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

You are developing a database of measured meteorological data for use in weather

ID: 3716612 • Letter: Y

Question

You are developing a database of measured meteorological data for use in weather and climate research. Define a structure type MeasureData with components siteIdNumber (a four-digits integer), windSpeed, day OfMonth, and temperature. Each site measures its data daily, at noon local time. Write a program that inputs a file of MeasuredData records and determines the site with the greatest variation in temperature ( defined here as the biggest difference between extrema) and the site with the highest average wind speed for all the days in the file. You may assume that there will be at most ten sites. Test the program on the following July daily data collected over one week at three sites:

ID DAY Wind Speed(Knots) Temperature (deg C)

2001 10 11 30
2001 11 5 22
2001 12 18 25
2001 13 16 26
2001 14 14 26
2001 15 2 25
2001 16 14 22
3345 10 8 29
3345 11 5 23
3345 12 12 23
3345 13 14 24
3345 14 10 24
3345 15 9 22
3345 16 9 20
3819 10 17 27
3819 11 20 21
3819 12 22 21
3819 13 18 22
3819 14 15 22
3819 15 9 19
3819 16 12 18

Explanation / Answer

#include<stdio.h>

#include<limits.h>

int main()

{

FILE *f; //file pointer

f=fopen("MeasuredDataFile.txt", "r"); //open file

int id,day,temp,windspeed,min_temp,max_temp,max_temp_var,site,sum,avg,datacount,max_var,avg_t,max_var_t,max_avg_site,

max_var_temp_site,temp_var_min,temp_var_max,temp_var_t;

//read first record from datafile

fscanf(f,"%d%d%d%d",&id,&day,&windspeed,&temp);  

site=id;

sum=windspeed;

min_temp=max_temp=temp_var_min=temp_var_max=temp;

max_temp_var=(max_temp-min_temp);

datacount=1;

avg_t=avg=INT_MIN;

max_avg_site=id;

max_var_temp_site=id;

printf("Site avg Wind Speed Temperature Variation ");

while(!feof(f))

{

fscanf(f,"%d%d%d%d ",&id,&day,&windspeed,&temp);

if(site==id)

{

sum+=windspeed;

datacount++;

if(temp<min_temp)

min_temp=temp;

if(temp>max_temp)

max_temp=temp;

}

/*

for perticular site add all windspeed data for all days and record min and max temperature

*/

else

{

// find average and max temperature variation

avg_t=(sum/datacount);

temp_var_t=max_temp-min_temp;

// compare average windspeed and temperature variation and find maximum

if(avg<avg_t)

{

avg=avg_t;

max_avg_site=site;

}

if(temp_var_t>max_temp_var)

{

max_temp_var=temp_var_t;

max_var_temp_site=site;

  

temp_var_min=min_temp;

  

temp_var_max=max_temp;

}

printf("%d %d %d ",site,avg_t,max_temp_var);

//print site id and average wind speed and temperature variation for all site

site=id;

min_temp=max_temp=temp;

datacount=1;

sum=windspeed;

avg_t=INT_MIN;

}

}

avg_t=(sum/datacount);

temp_var_t=max_temp-min_temp;

if(avg<avg_t)

{

avg=avg_t;

max_avg_site=site;

}

if(temp_var_t>max_temp_var)

{

max_temp_var=temp_var_t;

max_var_temp_site=site;

  

temp_var_min=min_temp;

  

temp_var_max=max_temp;

}

printf("%d %d %d ",site,avg_t,max_temp_var);

//print final result maximum average wind speed site and maximum temperature variation

printf(" Site with the highest average wind speed : %d Highest average wind speed : %d",max_avg_site,avg);

printf(" Site with greatest variation in Temperature : %d Maximum temperature Variation : %d Maximum temperature : %d Minimum Temperature : %d "

,max_var_temp_site,max_temp_var,temp_var_max,temp_var_min);

return 0;

}

/*

Measured Data File

2001 10 11 30

2001 11 5 22

2001 12 18 25

2001 13 16 26

2001 14 14 26

2001 15 2 25

2001 16 14 22

3345 10 8 29

3345 11 5 23

3345 12 12 23

3345 13 14 24

3345 14 10 24

3345 15 9 22

3345 16 9 20

3819 10 17 27

3819 11 20 21

3819 12 22 21

3819 13 18 22

3819 14 15 22

3819 15 9 19

3819 16 12 18

OUTPUT

Site avg Wind Speed Temperature Variation

2001 11 8

3345 9 9

3819 16 9

Site with the highest average wind speed : 3819 Highest average wind speed : 16

Site with greatest variation in Temperature : 3345

Maximum temperature Variation : 9

Maximum temperature : 29

Minimum Temperature : 20

--------------------------------

Process exited after 0.04137 seconds with return value 0

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote