Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a top-down design and write a program to produce a bar chart of gourmet-

ID: 3673200 • Letter: D

Question

Develop a top-down design and write a program to produce a bar chart of gourmet-popcorn production for a cooperative farm group on a farm-by-farm basis. The input to the program is a series of data sets, one per line, with each set representing the production for one farm.

Each data set consists of the name of a farm followed by a comma and one or more spaces; a decimal number representing acres planted, one or more spaces; and an integer representing the number of pint jars of popcorn produced for that farm. The output is a bar chart that identifies each farm and displays its production in pints of corn per acre. The output is a single line for each farm, with the name of the farm starting in the first column on a line and the bar chart starting in column 30. Each mark in the bar chart represents 25-pint jars of popcorn per acre. The production goal for the year is 400 jars per acre. A vertical bar should appear in the chart for farms with production that does not meet this goal, and a special mark (#) is used for farms with production greater than or equal to 400 jars per acre.

For example, given the input file

Orville’s Acres, 114.8 43801

Hoffman’s Hills, 77.2 36229

Jiffy Quick Farm, 89.4 24812

Jolly Good Plantation, 183.2 104570

Organically Grown Inc., 45.5 14683

the output would be:

Popcorn Co-op Production in Hundreds of Pint Jars per Acre

Farm Name 1 2 3 4 5 6 ---|---|---|---|---|---|

Orville's Acres ***************|

Hoffman's Hills ***************#***

Jiffy Quick Farm *********** |

Jolly Good Plantation ***************#******

Organically Grown Inc. ************ |

The program should prompt the user for a text file name.

it needs to be able to compile and run in the latest version of drjava

Explanation / Answer

try this code for reading 4 farms companies and acre from txt file ....

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

//int main

int main() {

    FILE * ifp;

    ifp = fopen("input.txt", "r");

    FILE * ofp;

    ofp = fopen("output.txt", "w");

    int farms= 0, i, j;

    int sum = 0;

    int perc;

    int acre;

    char name [10];

    //read the first line for # of farm

    fscanf(ifp, "%d", & farms);

    //Loop for all farms

    for (i=0; i< farms; i++)

{

                fscanf(ifp, "%s", &name);

                fprintf(ofp, "%s:", name);

                fscanf(ifp, "%d ", &acre);

                perc = acre;

                fprintf(ofp, " +:");

                for(j=0; j<perc; j++)

{

                    fprintf(ofp, "*");

                }

                fscanf(ifp, "%d ", &acre);

                perc = acre;

                fprintf(ofp, " -:");

                for(j=0; j<perc; j++)

{

                    fprintf(ofp, "*");

                }

                fscanf(ifp, "%d ", &acre);

                perc = acre;

                fprintf(ofp, " *:");

                for(j=0; j<perc; j++){

                    fprintf(ofp, "*");

                }

                fscanf(ifp, "%d %d", &score1, &score2);

                perc = acre;

                fprintf(ofp, " /:");

                for(j=0; j<perc; j++){

                    fprintf(ofp, "*");

                }

                    fprintf(ofp, " ");

    }

    fclose(ifp);

    fclose(ofp);

return 0;

}