write a program that loads data from a data file into arrays

write a program that loads data from a data file into arrays of structs. The program will do some calculations using the data, print out information, and exit. The program must take the name of the data file using argv and argc.

Details

The data file will contain fictional weather data for two cities: Saskatoon and Guelph. Each row of data contains the city name, the date, the high temperature, the amount of precipitation. For this assignment dates are represented as the number of days since Jan 1 (i.e. Jan 31 is day 31, Feb 5 is day 36, etc). A function to parse one line of this data and copy the data into a struct supplied as a parameter to the function has been provided at the bottom of this assignment description.

Your program must do the following:

Take the name of the data file using argv/argc. Do not prompt the user for a data file unless there is an error opening the file.

Open the data file for reading. There will be no more than 200 lines of data in the data file. There will be a newline at the end of the data file.

Create two arrays of struct Weather (struct definition given below). One array is for data from Saskatoon, one array is for data from Guelph.

Read the data line by line. Decide whether the line goes into the Guelph array or the Saskatoon array.

use the parser provided to decode the line into a struct in the array

once all of the data file has been read, calculate the average temperature for each city

given the data.

calculate the total precipitation for each city

print the results in the required format

Required Output

The output for this program must be exactly as shown. If you change the location of anything, even a space or a blank line, you will lose marks.
Start the output with one blank line:

******
Guelph
******
AVG TEMP: 12.00 TOTAL PRECIP: 8.00

Leave a single blank line then print each element of the Guelph array, one per line, as specified in the description of the print function. Leave a single blank line then begin the section for Saskatoon.

********* Saskatoon *********
AVG TEMP: 3.00 TOTAL PRECIP: 2.00

Leave a single blank line then print each element of the Saskatoon array, one per line, as specified in the description of the print function. Do not print a blank line after the Saskatoon list.

Required Functions

1. A function to print a single struct. It must output the data of the struct exactly as specified: DAY: daynum (TEMP: temp)[precip MM]

a.

b. c.

daynum, temp and precip are the values. All other text should be reproduced exactly as shown, including the spaces. Numbers should be printed to two decimal points.
The function should not print a \ after the text.

For example, suppose the data were: City:Guelph, Day:133, Temp:25.01, Precipitation:0.0, the print function would print a single line of text that looked like this: DAY: 133 (TEMP: 25.00)[0.00 MM]

A function that returns a file pointer after open the file and checking for null file pointer and prompting the user to re-enter the filename if necessary.

A function that returns a double to calculate the average temperature given an array as a parameter.

A function that returns a double to calculate the total precipitation given an array as a parameter.

Solution

#inlcude<stdio.h>
#include<conio.h>


struct Weather
{
   String cname;
   int date;
   double high_temp;
   double precipitation;
};

   const int NUM_MONTHS = 12; //Number of Months
   Weather months[NUM_MONTHS]; //Array of 12 months
   int index;


for (int index = 0; index < NUM_MONTHS; index++)
   {
       cout << \"Enter the rainfall in inches for month #:\";
       cout << (index + 1) << \": \";
       cin >> months[index].rainfall;
   }


void main()

{

struct weather s[100];

void load()
{
FILE *fileName;
fileName = fopen(\"filename.txt\", \"r\");
if (fileName != NULL){
fread (s,1,1,fileName);
}
else {
printf(\"ERROR\");
}   

}

void avg()
{
int i;

printf(\"\ Collections: \ \");

for(i = 0; i < tail; i++)
{

avg=totaltemp/12;

}

write a program that loads data from a data file into arrays of structs. The program will do some calculations using the data, print out information, and exit.
write a program that loads data from a data file into arrays of structs. The program will do some calculations using the data, print out information, and exit.
write a program that loads data from a data file into arrays of structs. The program will do some calculations using the data, print out information, and exit.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site