Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anyone help me fix this trainwreck of an attempt at writing c code? INPUT FILE: 13 LAKE-POWELL-RESERVOIR March 3 3677.23 3663.35 3648.63 3608.95 3584.49

Can anyone help me fix this trainwreck of an attempt at writing c code?

image text in transcribed

image text in transcribed

INPUT FILE:

13

LAKE-POWELL-RESERVOIR

March 3 3677.23 3663.35 3648.63 3608.95 3584.49 3557.42 3589.22 3597.85 0000.00

November 11 3674.93 3661.25 3623.98 3601.24 3569.69 3602.65 3607.46 3599.71 0000.00

September 9 3678.70 3665.45 3627.10 3604.11 3571.07 3602.20 3602.08 3602.27 0000.00

December 12 3671.59 3658.07 3621.65 3598.82 3565.73 3600.14 3604.96 3596.79 0000.00

August 8 3681.12 3667.81 3630.83 3607.32 3575.85 3604.96 3604.93 3605.56 0000.00

February 2 3678.48 3665.02 3651.01 3613.00 3589.11 3560.35 3591.94 3598.63 0000.00

May 5 3676.76 3665.27 3644.88 3606.11 3584.70 3571.60 3598.27 3604.68 0000.00

October 10 3676.96 3663.47 3625.59 3602.92 3570.70 3602.31 3606.12 3601.27 0000.00

April 4 3676.44 3662.56 3646.79 3605.92 3583.02 3557.52 3589.94 3599.75 0000.00

June 6 3682.19 3672.19 3642.98 3615.39 3587.01 3598.06 3609.36 3610.94 0000.00

January 1 3680.12 3668.05 3654.25 3617.61 3594.38 3563.41 3596.26 3601.41 0000.00

July 7 3682.86 3671.37 3637.35 3613.64 3583.07 3607.73 3608.79 3609.47 0000.00

Averages 0 0000.00 0000.00 0000.00 0000.00 0000.00 0000.00 0000.00 0000.00 0000.00

/* Preprocessor directives */

#include

#include

#define inputfile "u:\\engr 200\\lake_powell.txt"

#define outputfile "u:\\engr 200\\lake_powell_report.txt"

/* Define the structure to represent hurricane data */

struct powell

{

char month[10];

int number;

double height1, height2, height3, height4, height5, height6, height7, height8;

};

/* Main function */

int main(void)

{

/* Declare variables */

struct powell pow[13],temporary;

int nrows, ncols, i, j, lakename,minrow,mincol,maxrow,maxcol;

double sumheight1=0.0,sumheight2=0.0,sumheight3=0.0,sumheight4=0.0,

sumheight5=0.0,sumheight6=0.0,sumheight7=0.0,sumheight8=0.0,avg1,avg2,avg3,

avg4,avg5,avg6,avg7,avg8, totavg,min,max;

FILE *lake, *report;

/* Open input file */

lake = fopen(inputfile,"r");

report = fopen(outputfile,"w");

/* Verify input file */

if(lake == NULL)

{

printf(" ERROR OPENING INPUT FILE.");

printf(" PROGRAM TERMINATED. ");

return 0;

}

/* Read control number */

fscanf(lake,"%i",&nrows);

fscanf(lake,"%s",&lakename);

/* Read lake data into array */

for(i=0; i

{

for(j=0; j

{

{

fscanf(lake,"%s %i %lf %lf %lf %lf %lf %lf %lf %lf",

&pow[i].month,&pow[i].number,&pow[i].height1,&pow[i].height2,

&pow[i].height3,&pow[i].height4,&pow[i].height5,&pow[i].height6,

&pow[i].height7,&pow[i].height8);

}

}

}

/* Sort Months */

for(i=0; i

{

for(j=0; j

{

if(pow[j].number

{

temporary = pow[j];

pow[j] = pow[j+1];

[j+1] = temporary;

}

}

}

/* Sum water height categories */

for(i=0; i

{

sumheight1 += pow[i].height1;

sumheight2 += pow[i].height2;

sumheight3 += pow[i].height3;

sumheight4 += pow[i].height4;

sumheight5 += pow[i].height5;

sumheight6 += pow[i].height6;

sumheight7 += pow[i].height7;

sumheight8 += pow[i].height8;

}

/* Compute average water height */

avg1 = sumheight1rows;

avg2 = sumheight2rows;

avg3 = sumheight3rows;

avg4 = sumheight4rows;

avg5 = sumheight5rows;

avg6 = sumheight6rows;

avg7 = sumheight7rows;

avg8 = sumheight8rows;

/* Compute 8 year average */

totavg = (sumheight1+sumheight2+sumheight3+sumheight4+sumheight5+sumheight6+

sumheight7+sumheight8)cols;

/* Compute max and min water heights */

min = lake[0][3];

max = lake[0][3];

for(i=0; i

{

{

if(lake[i][j]

{

min = lake[i][j];

minrow = i+1;

mincol = j;

}

if(lake[i][j] > max)

{

max = lake[i][j];

maxrow = i+1;

maxcol = j;

}

}

}

/* Print headings */

printf("********************************************************************"

"********************************"

" %21s",lakename);

printf(" Year");

printf(" 2000 2001 2002 2003 2004 "

"2005 2006 2007 Monthly"

"Month "

" Average");

/* Print array */

for(i=0; i

{

printf(" %10s %3i %7lf %7lf %7lf %7lf %7lf %7lf %7lf"

" %7lf %7lf",pow[i].month,pow[i].height1,pow[i].height2,

pow[i].height3,pow[i].height4,pow[i].height5,pow[i].height6,

pow[i].height7,pow[i].height8,totavg);

}

/* Print average category */

printf(" RESERVOIR STATISTICS:");

/* Print min, max, overall avg */

printf(" Minimum water height above sea level was %7lf feet in %s, %lf",

min,pow[i].month);

printf(" Maximum water height above sea level was %7lf feet in %s, %lf",

max,pow[i].month);

printf(" Overall average water height above sea level was %7lf feet.",

totavg);

printf(" Overall average height above sea level was exceeded %2i times.",

totavg);

/* Print headings */

printf(" ***************************************************************"

"************************************* ");

/* Close input file */

fclose(powell);

fcose(report)

/* Exit program */

return 0;

}

/******************************************************************************/

INTRODUCTION: Lake Powell is the second largest reservoir in the United States following Lake Mead. It was formed after the completion of the Glen Canyon Dam on the Colorado River. Over an eight-year period (2000 2007) data was collected dealing with the height of the water in the reservoir measured in feet above sea level. A file called lake_powell contains the collected data. EXAM: Using only the techniques provided in demo programs and assignment programs, and using a defined structure, write a C program that reads from the input file the size of the array of structures, and then reads the reservoir name into a one-dimensional character arra The program will read from the input file into the array of structures the first column as a string of characters, the second column as an integer for the month number, and the remaining columns as the heights in feet abov sea level The program will sort the data by month chronologically. The program will compute the average water height for each year and place the computed values in the last row of the array of structures. The program will compute the average water height for each month and place the computed values in the last column of the array of structures. The program will compute the overall eight-year average (do not include the monthly or yearly averages). The program will determine the minimum and maximum water heights for the eight-year period, and the month and year that the minimum and maximum occurred. The program will determine how many times for the eight-year period the water level exceeded the overall eight-year average (do not include the monthly or yearly averages). The program will incorporate input and output files, if structures, an array of structures, and for loops. The defined structure will contain a character array, and integer variable, and double variables. The main function will contain the character array for the name of the reservoir. No other arrays are allowed in the program. Also no C code copied from the internet will be allowed. Do not use while loops for any part of the program. Do not use any C++ code in the program Your program will print to the computer screen and print to an output file called lake_powell_report. The output format is given on page 2 NOTE: When printing the array of structures, do not print a number in the last row/last column position. Review the output format provided on page 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

e. What age client does the person see?

Answered: 1 week ago