CAN SOMEBODY PLEASE HELP ME WITH THIS ASSIGNMENTS . i WILL RATE RIGHT AWAY INTRO
ID: 3588243 • Letter: C
Question
CAN SOMEBODY PLEASE HELP ME WITH THIS ASSIGNMENTS . i WILL RATE RIGHT AWAY
INTRODUCTION:
You are an engineer working as an urban planner for the city of Metropolis. Data has been collected dealing with rainfall amounts for the city and you are required to develop a computer program that will perform rainfall averaging, and minimum/maximum analysis for storm sewer pipe sizing. The input data file is called rain_fall, and it is a space delimited file. As you examine the input file, you notice that the first record line contains the control number. The remaining record lines are the rainfall amounts; 12 rows (January – December) and 5 years (2013 – 2017).
ASSIGNMENT:
Write a C program that will read the control number, and the program will read the rainfall amounts into 5 one-dimensional arrays (years 2013-2017). Manipulate the one-dimensional arrays to calculate the total rainfall for each year, the average rainfall for each year, and determine the minimum and maximum rainfall values for the year 2015.
Print the output to the computer screen and to an output file called rain_fall_report. Illustrated below is the output style for the computer screen and the output file.
OUTPUT FORMAT:
******************************************************
METROPOLIS RAINFALL DATA
2013 2014 2015 2016 2017
Month 1 x.xx x.xx x.xx x.xx x.xx
Month 2 . . . . .
Month 3 . . . . .
Month 4 . . . . .
Month 5
Month 6
Month 7
Month 8
Month 9
Month 10
Month 11
Month 12 x.xx x.xx x.xx x.xx x.xx
Averages: x.xx x.xx x.xx x.xx x.xx
REPORT SUMMARY:
Minimum rainfall for 2015 is x.xx inches.
Maximum rainfall for 2015 is x.xx inches.
******************************************************
Explanation / Answer
#include<stdio.h>
#include<string.h>
void find_min(float a[14],int n)
{
float min=a[0];
int i;
float total_rain_fall=a[0];
for(i=1;i<n;i++)
{
if(min>a[i])
min=a[i];
total_rain_fall+=a[i];
}
a[i]=total_rain_fall;
a[i+1]= total_rain_fall / n;
a[i+2]=min;
}
void find_max(float a[14],int n)
{
float max=a[0];
int i;
for(i=1;i<n;i++)
if(max<a[i])
max=a[i];
a[i+3]=max;
}
int main()
{
float year2013[16],year2014[16],year2015[16],year2016[16],year2017[16];
int control_records,i;
char line[200];
FILE *ifp,*ofp; //ifp - input file pointer, ofp - output file pointer
ifp=fopen("rain_fall","r");
if(ifp==NULL)
{
printf("Unable to open rain_fall... ");
return -1;
}
fscanf(ifp,"%d ",&control_records);
for(i=0;i<control_records;i++)
fscanf(ifp,"%f %f %f %f %f ",&year2013[i] , &year2014[i],&year2015[i],&year2016[i],&year2017[i]);
find_min(year2013,control_records);
find_min(year2014,control_records);
find_min(year2015,control_records);
find_min(year2016,control_records);
find_min(year2017,control_records);
find_max(year2013,control_records);
find_max(year2014,control_records);
find_max(year2015,control_records);
find_max(year2016,control_records);
find_max(year2017,control_records);
ofp=fopen("rainfall_report.txt","w");
if(ofp==NULL)
{
printf("Error opening output file rainfall_report.txt");
return -2;
}
printf("**************************************************************** ");
strcpy(line, "**************************************************************** ");
fprintf(ofp,"%s",line);
printf(" METROPOLIS RAINFALL DATA ");
strcpy(line," METROPOLIS RAINFALL DATA ");
fprintf(ofp,"%s",line);
printf(" 2013 2014 2015 2016 2017 ");
strcpy(line," 2013 2014 2015 2016 2017 ");
fprintf(ofp,"%s",line);
for(i=0;i<control_records+2;i++)
if (i+1<10)
{
printf("Month %d %14.2f %9.2f %9.2f %9.2f %9.2f ", i+1, year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
fprintf(ofp,"Month %d %14.2f %9.2f %9.2f %9.2f %9.2f ", i+1, year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
}
else
{
if(i==12)
{
printf(" Total Rain Fall : %.2f %9.2f %9.2f %9.2f %9.2f ", year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
fprintf(ofp," Total Rain Fall : %.2f %9.2f %9.2f %9.2f %9.2f ", year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
}
else if(i==13)
{
printf(" Averages : %.2f %9.2f %9.2f %9.2f %9.2f ", year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
fprintf(ofp," Averages : %.2f %9.2f %9.2f %9.2f %9.2f ", year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
}
else
{
printf("Month %d %13.2f %9.2f %9.2f %9.2f %9.2f ", i+1, year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
fprintf(ofp,"Month %d %13.2f %9.2f %9.2f %9.2f %9.2f ", i+1, year2013[i] , year2014[i],year2015[i],year2016[i],year2017[i]);
}
}
printf(" REPORT SUMMARY ");
strcpy(line," REPORT SUMMARY ");
fprintf(ofp,"%s",line);
printf("Minimum rainfall for 2013 is %.2f inches. ", year2013[14]);
fprintf(ofp,"Minimum rainfall for 2013 is %.2f inches. ", year2013[14]);
printf("Maximum rainfall for 2015 is %.2f inches. ", year2013[15]);
fprintf(ofp, "Maximum rainfall for 2015 is %.2f inches. ", year2013[15]);
printf("Minimum rainfall for 2013 is %.2f inches. ", year2014[14]);
fprintf(ofp,"Minimum rainfall for 2013 is %.2f inches. ", year2014[14]);
printf("Maximum rainfall for 2015 is %.2f inches. ", year2014[15]);
fprintf(ofp,"Maximum rainfall for 2015 is %.2f inches. ", year2014[15]);
printf("Minimum rainfall for 2013 is %.2f inches. ", year2015[14]);
fprintf(ofp,"Minimum rainfall for 2013 is %.2f inches. ", year2015[14]);
printf("Maximum rainfall for 2015 is %.2f inches. ", year2015[15]);
fprintf(ofp,"Maximum rainfall for 2015 is %.2f inches. ", year2015[15]);
printf("Minimum rainfall for 2013 is %.2f inches. ", year2016[14]);
fprintf(ofp,"Minimum rainfall for 2013 is %.2f inches. ", year2016[14]);
printf("Maximum rainfall for 2015 is %.2f inches. ", year2016[15]);
fprintf(ofp,"Maximum rainfall for 2015 is %.2f inches. ", year2016[15]);
printf("Minimum rainfall for 2013 is %.2f inches. ", year2017[14]);
fprintf(ofp,"Minimum rainfall for 2013 is %.2f inches. ", year2017[14]);
printf("Maximum rainfall for 2015 is %.2f inches. ", year2017[15]);
fprintf(ofp,"Maximum rainfall for 2015 is %.2f inches. ", year2017[15]);
printf("**************************************************************** ");
strcpy(line, "**************************************************************** ");
fprintf(ofp,"%s",line);
fclose(ifp);
fclose(ofp);
return 0;
}
/*
lenovo@lenovo-Vbox:~/chegg$ cat rain_fall
12
0.32 1.02 0.45 0.35 0.95
0.26 0.55 0.11 0.25 0.35
0.93 1.00 1.25 0.95 0.90
2.63 2.50 2.25 2.75 2.01
2.57 2.75 2.15 2.25 2.36
6.61 5.69 6.62 5.75 6.25
3.70 3.71 3.24 3.75 3.69
3.20 2.92 2.85 3.25 3.15
1.28 1.40 1.12 1.25 1.29
0.37 0.29 0.57 0.38 0.92
0.31 0.27 0.32 0.35 0.29
0.22 0.02 0.12 0.25 0.27
lenovo@lenovo-Vbox:~/chegg$ cc rainfall.c
lenovo@lenovo-Vbox:~/chegg$ ./a.out
****************************************************************
METROPOLIS RAINFALL DATA
2013 2014 2015 2016 2017
Month 1 0.32 1.02 0.45 0.35 0.95
Month 2 0.26 0.55 0.11 0.25 0.35
Month 3 0.93 1.00 1.25 0.95 0.90
Month 4 2.63 2.50 2.25 2.75 2.01
Month 5 2.57 2.75 2.15 2.25 2.36
Month 6 6.61 5.69 6.62 5.75 6.25
Month 7 3.70 3.71 3.24 3.75 3.69
Month 8 3.20 2.92 2.85 3.25 3.15
Month 9 1.28 1.40 1.12 1.25 1.29
Month 10 0.37 0.29 0.57 0.38 0.92
Month 11 0.31 0.27 0.32 0.35 0.29
Month 12 0.22 0.02 0.12 0.25 0.27
Total Rain Fall : 22.40 22.12 21.05 21.53 22.43
Averages : 1.87 1.84 1.75 1.79 1.87
REPORT SUMMARY
Minimum rainfall for 2013 is 0.22 inches.
Maximum rainfall for 2015 is 6.61 inches.
Minimum rainfall for 2013 is 0.02 inches.
Maximum rainfall for 2015 is 5.69 inches.
Minimum rainfall for 2013 is 0.11 inches.
Maximum rainfall for 2015 is 6.62 inches.
Minimum rainfall for 2013 is 0.25 inches.
Maximum rainfall for 2015 is 5.75 inches.
Minimum rainfall for 2013 is 0.27 inches.
Maximum rainfall for 2015 is 6.25 inches.
****************************************************************
lenovo@lenovo-Vbox:~/chegg$ ls
0*abc body.c ccmplx dtob.c float lab5.c minor3B.sh rail_fAll.c~ show tcps tmpcnv.cpp
0xyz calc.sh cmplx dtob.s fruits lab6.c minor3B.sh~ rain_fall show.c tcps.c tst
1to100.c call_data.txt cmplx.cpp err.txt h2.awk main.c names rainfall.c simu.c temp tstcpp.cpp
a.out call_stats3 count.sh expsin.c helloc makrs numbers.txt rainfall_report.txt tcpc test weekly_call_info.txt
body call_stats3.cpp count.sh~ fib.c hello.c menu.c railfall.c~ readseq.cpp tcpc.c tmp
lenovo@lenovo-Vbox:~/chegg$ cat rainfall_report.txt
****************************************************************
METROPOLIS RAINFALL DATA
2013 2014 2015 2016 2017
Month 1 0.32 1.02 0.45 0.35 0.95
Month 2 0.26 0.55 0.11 0.25 0.35
Month 3 0.93 1.00 1.25 0.95 0.90
Month 4 2.63 2.50 2.25 2.75 2.01
Month 5 2.57 2.75 2.15 2.25 2.36
Month 6 6.61 5.69 6.62 5.75 6.25
Month 7 3.70 3.71 3.24 3.75 3.69
Month 8 3.20 2.92 2.85 3.25 3.15
Month 9 1.28 1.40 1.12 1.25 1.29
Month 10 0.37 0.29 0.57 0.38 0.92
Month 11 0.31 0.27 0.32 0.35 0.29
Month 12 0.22 0.02 0.12 0.25 0.27
Total Rain Fall : 22.40 22.12 21.05 21.53 22.43
Averages : 1.87 1.84 1.75 1.79 1.87
REPORT SUMMARY
Minimum rainfall for 2013 is 0.22 inches.
Maximum rainfall for 2015 is 6.61 inches.
Minimum rainfall for 2013 is 0.02 inches.
Maximum rainfall for 2015 is 5.69 inches.
Minimum rainfall for 2013 is 0.11 inches.
Maximum rainfall for 2015 is 6.62 inches.
Minimum rainfall for 2013 is 0.25 inches.
Maximum rainfall for 2015 is 5.75 inches.
Minimum rainfall for 2013 is 0.27 inches.
Maximum rainfall for 2015 is 6.25 inches.
****************************************************************
lenovo@lenovo-Vbox
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.