Write a C program to (i) calculate the mean level of E. Coli bacteria for a seri
ID: 642075 • Letter: W
Question
Write a C program to (i) calculate the mean level of E. Coli bacteria for a series of lake beaches in Ontario, (ii) make a decision to open or close the beach, and (iii) produce a report for all the lakes and beaches contained in the data file. * For each beach, there is a line of data in the file with the following fields separated by blanks - lake ID (integer), beach number (integer), number of samplings (integer) and one real number (double) per sampling representing the number of organisms in 100ml of water. * Your program should process as many data lines as there are present. * For each beach, calculate the mean level of bacteria (average). * If the mean level is above 50, close the beach. * If there are less than 3 samplings, there is insufficient data. * The report will present for each beach on separate lines the name of the lake, the name of the beach, and the recommendation ("open", closed" or "insufficient data"). Use the table below to convert IDs and numbers into names. * Look at the data files to make sure you understand the data format: (july08.data, july15.data, aug15.data). Try to determine by hand the output that should be correct for each one of those files. * Produce a report for a file of your choice. * To read data from the file, you must use the file input protocol (fopen/fscanf/fclose). * Your name(s) must appear at the bottom of the printout with the file name. Your reports should look like this (lakes and beaches names, not numbers with column properly aligned with columns headers):
Lake Beach Average E-Coli Level Recommendation ---- ----- -------------------- -------------- Ontario Kew Beach 47.12 OPEN Huron Goderich 51.13 CLOSED Simcoe Sibbald Point 0 INSUFFICIENT DATA . . . Report from july01.data generated by Harry Potter and Hermione Granger.
Lake table
1: Ontario
2: Erie
3: Huron
4: Muskoka
5: Simcoe
Beach table
100: Kew Beach
101: Sunnyside Beach
103: Sandbanks
201: Port Dover
202: Port Burwell
203: Crystal Beach
301: Goderich
302: Sauble Beach
303: Kincardine
401: Muskoka Beach
501: Sibbald Point
Explanation / Answer
#include
#include
struct beach
{
int lake_id, beach_no, no_of_samp;
char lname[20],bname[20];
double no_of_organism_ps[10];
}bch;
void input();
void output();
void input()
{int s,i;
printf("Lake Table 1. Ontorio 2. Erie 3. Huron 4. Muskoka 5. Simcoe Enter Lake
ID : ");
scanf("%d",&bch.lake_id);
printf("Beach Table 100. Kew Beach 101. Sunnyside Beach 103. Sandbanks 201.
Port Dover 202. Port Burwell Enter Beach No. : ");
scanf("%d",&bch.beach_no);
printf("Enter number of samplings taken");
scanf("%d",&bch.no_of_samp);
s=bch.no_of_samp;
for( i=1;i<=s;i++)
{
printf("Enter number of organisms in sample no.%d",i);
scanf("%lf",&bch.no_of_organism_ps[i]);
}
}
void output()
{int s,i,sum=0;
double mean;
printf("Lake Beach Average E-coli Level Recommendation ");
s=bch.no_of_samp;
for( i=1;i<=s;i++)
{
//printf("Number of organisms in sample no.%d : %lf ",i,bch.no_of_organism_ps[i]);
sum+=bch.no_of_organism_ps[i];
}
mean=sum/s;
if(bch.no_of_samp<3)
{printf("%s %s %lf INSUFFICIENT DATA ",bch.lname,bch.bname,mean);
break;}
else
{if(mean>50)
printf("%s %s %lf CLOSE ",bch.lname,bch.bname,mean);
else
printf("%s %s %lf OPEN ",bch.lname,bch.bname,mean);
}
}
void main()
{FILE *fw,*fr;
fw=fopen("beach.txt","a");
input();
fprintf(fw,"%d %s%d%s %d
%lf",bch.lake_id,bch.lname,bch.beach_no,bch.bname,bch.no_of_samp,bch.no_of_organism_ps);
fclose(fw);
fr=fopen("beach.txt","r");
do
{
fscanf(fr,"%d %s %d %s %d
%lf",bch.lake_id,bch.lname,bch.beach_no,bch.bname,bch.no_of_samp,bch.no_of_organism_ps);
output();
}while(!feof(fr));
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.