Write a C program that, given an input file that contains: a grid size (representing blocks in a neighborhood), coordinates of bakery-cafe locations, and customer survey responses; generates as output, a file with the maximum number of locations that can be accessed for each given survey response and the optimal coordinate from which a person can access them.
The Sunrise bakery-cafe chain has several locations in different parts of the far, far away city. City folks love coffee and donuts from Sunrise ❤☕���, so the local “kitties in booties” real estate company is interested in identifying landmarks that represent a good deal to build rental apartments that is based on proximity to Sunrise locations in the neighborhood.
To perform the valuation analysis, a map of the neighborhood marked with Sunrise locations is used. Assuming the average person is willing to walk a certain number of blocks to get their morning coffee, you need to find the coordinates from which a person can access the maximum number of Sunrise locations. A map has a grid layout (matrix), with blocks aligned on the northsouth and east-west axes. Since we need to walk through the streets to reach a location, the distance between the intersections (a,b) and (c,d) is given by the equation: |a − c| + |b − d|.
Instructions:
The source file for this assignment will be named p2_<username>_<labsection>.c
When you run your program, you will enter the input filename on the command line as follows:
p2_<username>_<labsection> <input_file>
Input:
Each input file could contain several test cases. The first line of each test case contains four integers dx, dy, n, r. These values represent: the dimensions of the grid dx×dy, (1<dx≤100) and (1<dy≤100), the number of locations n (0≤ n≤8000) and the number of responses for a survey r (1<r≤20). Each of the next n lines contains two integers xi and yi, (1≤ xi ≤ dx, 1 ≤ yi ≤ dy) these specify the coordinates of the ith Sunrise location. Each of the next r lines contains an integer max(0≤max≤100), which is the maximal distance that a person is willing to walk for a cup of coffee to a Sunrise location. The end of the test cases is a line containing four zeros.
Assumptions:
Output:
The program will print the results in an output file whose name will be the same as the input file but with the extension .out. If run is successful, the program prints the message “Output file: <output_file.out> created successfully”. Within the file, each instance is labeled as Instance #:, where # is the corresponding test case (the first case is 1, the second 2, and so on). Then, display a line for each survey response (r). Each line displays the maximum number of bakery-cafe locations that could be accessed for the maximal distance (max) that a person is willing to walk in that survey response followed by the optimal coordinate in the grid (x,y). Then, display the solution as a manner of a “map”, where each line grid is printed on a new line using ‘-‘ for an empty cell grid, ‘*’ for a Sunrise location, and ‘$’ to represent the optimal coordinate. Use ‘@’ when an optimal coordinate is the same as a Sunrise location.
Note:
Specific Requirements:
When coding a program, we try to avoid “Run Errors” using some techniques like checking user input, and some function returns, therefore your program must include the following functionality:
Restrictions:
Makefile:
Create a Makefile to compile your program. Use the template specified in Project 1
Submission: