Question
The program uses both files and two dimensional arrays. The Problem Statement Business is going well for your friend, who is selling discounts to area
The program uses both files and two dimensional arrays.
The Problem Statement
Business is going well for your friend, who is selling discounts to area clubs and restaurants, which means that business is going well for you!
Both of you have decided that you'll advertise on memory mall, which is roughly arranged as a rectangle. There's not enough time before a football game to hand flyers to everyone arranged on the mall. Therefore, you will only be able to walk through one "row" or "column" of the huge grid for advertising purposes.
Naturally, you'd like to give flyers to as many people as possible as you make your single walk through.
Program Setup
A scaffold of the solution has been created for you:
#include
#define ROWS 20 #define COLS 5
int main() { // Open the input file and read in the number of cases to process. FILE* ifp = fopen("marketing.txt", "r"); int loop, numCases, best, cur; int grid[ROWS][COLS], i, j; fscanf(ifp, "%d", &numCases);
// Go through each input case. for (loop=0; loop // Get this input grid. for (i=0; i // Will store best value for row or column. best = 0; /*** FILL IN CODE HERE, TO UPDATE BEST, AS NEEDED. ***/ // Output result. printf("%d ", best); } fclose(ifp); return 0; } Place your solution in the designated area of the scaffold. Memory mall is arranged like a 20 x 5 grid of tailgating locations. A representation of memory mall has been created using a two dimensional array. You will need to read from a file the number of people in each section or "cell" of memory mall. Then, you should determine which row or column of the grid has the most number of people in it. Since these numbers represent the number of people in an area, it is guaranteed that all numbers for all input cases are non-negative. Example This example is on a smaller grid to illustrate the idea. Suppose the following is our input grid. Each number represents the number of people tailgating in that cell. If we select the third column shaded blue, we would advertise to 1500 people. This is more than if we chose any of the other columns or rows. Input File Format The first line of the input file contains a single positive integer, n (n 1000), representing the number of grids to process. This is followed by n 5x20 grids of integers. Sample Run After you add your code to designated location in the scaffold, run your program using the input file marketing.txt. Your output should match the output in marketing.out. 11 4 3 2 110 4 5 4 29 10 10 10 108 4 3 2 16 1 1 1 17 4 3 2 15 0 300 2 24 2 2 0 03 5 5 3 32 2 3 4 51 1 2 1 2228 13 214 15 16100 100 100 100 10018 17 18 19 2017 100 100 100 18216 13 3 4 415 1 2 3 414 4 3 200 113 4 3 2 112 1 2 3 411 4 3 2 110 4 5 400 29 10 10 10 108 4 3 2 16 1 1 1 17 4 3 2 15 0 0 2 24 2 2 0 03 5 5 3 32 2 3 4 51 1 2 100 2228 13 14 15 16100 100 100 100 10018 17 18 19 2017 100 100 100 18216 13 3 4 415 1 2 3 414 4 3 2 113 4 3 2 112 1 2 3 40011 4 3 2 110 4 5 4 29 10 10 10 108 4 3 2 16 1 1 1 17 4 3 2 15 0 0 2 2004 2 2 0 03 5 5 3 3002 2 3 4 51 1 2 1 2228 13 14 15 16100 100 100 100 100 .out and .txt are unformatted files that can be opened with most text editors. Code::Blocks can also create and read files of these types. Specification Homework assignments are either correct or incorrect. Do not modify any of the printf statements in the scaffold. Do not add any printf statements to the program.
200 20 500 19 25 44 5 16 50 30 400 15 80 93 2 14 19 40 600 0 30 18 92 19
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started