Thread: Help Please :) Thank you

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    10

    Help Please :) Thank you

    Write a C program that detects and reports on areas of brightness in the night sky. You
    will input a portion of the night sky (from standard input) represented by an n × n grid of
    integers where n <= 1000. Each value in the grid will indicate the detected brightness of
    that portion of the night sky with a 0 value indicating no light. Unfortunately the detection
    hardware sometimes reports erroneous values; these values will show up as negative numbers
    and must be filtered out prior to finding the bright spots. After preprocessing your data
    to filter out all of the noise (more on this below), your program must report the brightest
    coordinate and the brightness value for that coordinate in every 5 × 5 patch of the sky that
    contains no zeros. Report “(none)” if no bright spots exist. Keep in mind that bright areas
    may overlap, and that any bright spot should only be reported once. You should also report
    bright spots of the 5 × 5 areas you encounter as you scan the data in a top to bottom, left
    to right order.
    You should preprocess your data to eliminate noise in following manner: for every negative
    value you encounter, average the (maximum of) 8 squares around it and replace the value
    with the average (rounded off to the nearest whole number; use nearbyint from math.h).
    If one of the surrounding squares also is negative, use the value of 0 in computing the average.
    Your input will consist of a single integer s representing the size of the grid followed by s×s
    data values. Your output should be presented exactly like the sample run.

    Data file:
    20
    0 0 0 0 0 0 0 13 18 18 15 5 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 6 16 19 16 6 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 12 16 18 17 5 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 12 14 12 14 9 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 8 10 4 6 10 0 0 0 0 0 0
    0 0 0 0 3 3 5 3 -2 10 12 11 11 6 0 0 0 0 0 0
    10 0 0 0 5 6 6 6 5 7 13 14 13 4 0 0 0 0 0 0
    0 0 0 0 2 7 8 6 4 8 12 13 11 9 0 0 0 0 0 0
    0 0 0 0 2 7 7 7 5 9 4 10 6 4 0 0 0 -2 0 0
    0 0 0 0 4 4 3 4 3 6 6 4 5 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 6 8 8 7 5 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 5 7 9 8 6 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 5 7 7 8 3 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 3 5 4 4 4 0 0 0 0 0 0 0
    0 0 0 0 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 -1 -1 -2 8 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 -1 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0



    sample run :
    Bright spot:
    [9,11] 14
    [10,6] 8
    [8,9] 10
    [9,10] 13
    [10,11] 13
    [11,11] 10
    [14,9] 9



    I just want you guys to tell me how to start this, I know i have to read them as arrays left to right top to bottom. But How would I change the negative numbers to the average of the array around it.?? Thank you

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Start by reading this.
    A development process

    Start by reading the data into an array, and then printing it out.
    Don't do anything else until your printout is the same as the input file.

    Then I guess the next thing is to search for negative numbers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    10
    what about the numbers in the output between brackets
    like [9,11]. is that the location of the brightest spot in the array ??

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by Feras Kakish View Post
    what about the numbers in the output between brackets
    like [9,11]. is that the location of the brightest spot in the array ??
    Sure, that sounds like a reasonable guess/assumption. It's your assignment, so presumably you, your tutor or your instructor know best what that output means. Of course, you could also verify that by hand if that is the location of a bright spot. Before you start programming, you must know how to solve this problem by hand. If you can't solve it, it will be impossible for you to program a computer to solve it.

    Have you done as Salem suggested yet? Can you successfully read in the file and print the data back out?

    Remember, plan your solution first, then implement it in small steps, compiling and testing often.

    EDIT: This program would really benefit from multiple functions. Make sure that a function does one thing and does it well, and has a descriptive name. Some examples:
    read_data
    remove_sensor_errors(sky_map, map_width, map_height
    patch_has_zeros(sky_map, start_row, start_col, patch_width, patch_height)
    find_brightest_spot(sky_map, start_row, start_col, patch_width, patch_height)
    Last edited by anduril462; 10-23-2014 at 04:30 PM.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Feras Kakish View Post
    what about the numbers in the output between brackets
    like [9,11]. is that the location of the brightest spot in the array ??
    We do NOT know your instructor; we have no info except what you posted.
    Does the two group of text go together? If yes, I have no idea what is in the [] brackets.
    If no, I would guess it is the center of the brightest spot.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Tags for this Thread