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

Here is the code i have so far, i need data to get read into the array. Here are

ID: 3779148 • Letter: H

Question

Here is the code i have so far, i need data to get read into the array.

Here are the complete direction

//Given the original AL Weather Station Data file design a structure for one record
//of data where one record consists of all eleven data items on one line of the data file (starting after the headers and line of dashes).
//Next, create an array of records with enough elements to hold the entire data file. Initialize the array of records by reading in all the data from the file.
//
//Write the following functions that will process the data from the array of records:
//Compute average high temperatures for any one of the three days. Date will be a parameter to the function. The user will select the day from the three available.
//Find and print weather stations that reported precipitation PRCP above a given amount on a specific day. (NOTE: the data is shown in hundredths of an inch. 13 is 0.13 inches)
//
//From your main program call the functions to:
//Compute the average TMAX for June 1
//Find and print all weather stations reporting more than 0.50 inches of precipitation on June 2

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;


struct date
{
   unsigned int year;
   unsigned int month;
   unsigned int day;
};

struct station_data
{
   string station;
   string name;
   date date;
   int MDPR;
   int DAPR;
   unsigned int PRCP;
   int SNWD;
   int SNOW;
   int TMAX;
   int TMIN;
   int TOBS;
};

struct node
{
   station_data body;
   node *link;
};

void precipitation(station_data);
float hightemp(station_data);

int main(void)
{
   //This filters the data
   string top, dash, dataline;
   string tmax_test, tmin_test;
   string station;

   int pos_tmax, pos_tmin, count = 0, count2 = 0;
   ifstream data_orig;
   ofstream data_filt;

   //Open data files
   data_orig.open("C:/Temp/AL_Weather_Station.txt");
   data_filt.open("C:/Temp/Filtered_AL_Weather_Station.txt");

   if (!data_orig)
   {
       cout << "Unable to open innput the file." << endl;
       system("pause");
       return 1;
   }
   if (!data_filt)
   {
       cout << "Unable to open innput the file." << endl;
       system("pause");
       return 1;
   }
   //Get the header and dash lines
   getline(data_orig, top);
   getline(data_orig, dash);
   //Get position of TMAX and TMIN to sort through bad data
   pos_tmax = top.find("TMAX");
   pos_tmin = top.find("TMIN");
   cout << pos_tmax << endl;
   cout << pos_tmin << endl;
   //Print the top two lines     
   data_filt << top << endl;
   data_filt << dash << endl;
   //Write filtered data to new file
   while (!data_orig.eof())
   {
       getline(data_orig, dataline);
       tmax_test = dataline.substr(123, 5);
       tmin_test = dataline.substr(132, 5);
       if (tmax_test == "-9999" || tmin_test == "-9999")
       {
           count++;
       }
       else
       {
           data_filt << dataline << endl;
           count2++;
       }
   }
   cout << "There were " << count << " INVALID data entries. These have been deleted." << endl;
   data_orig.close();
   data_filt.close();
   cout << "There are " << count2 << " VALID data entries." << endl;
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   //Start structures here.
   //Initilaize array
   station_data data1; // Declare a variable for one set of data
   station_data station_A[307];

   data1.station = "GHCND:US1ALLS0003";
   data1.name = "ATHENS 4.3 W AL US";
   data1.date.month = 06;
   data1.date.day = 02;
   data1.date.year = 2014;
   data1.MDPR = -9999;
   data1.DAPR = -9999;
   data1.PRCP = 51;
   data1.SNWD = -9999;
   data1.SNOW = -9999;
   data1.TMAX = -9999;
   data1.TMIN = -9999;
   data1.TOBS = -9999;

   // Declare an array for up to number of data records. 307 vaid entries.
   cout << " The average max temp for " << data1.date.month << data1.date.day << " is: " << hightemp(data1) << endl;// Call the functions
   precipitation(data1);

   cout << endl << endl;
   system("pause");
   return 0;
}

float hightemp(station_data data)
{
   float average_temp;
   average_temp = data.TMAX;
   return average_temp;
}

//Find and print weather stations that reported precipitation PRCP above a given amount on a specific day. (NOTE: the data is shown in hundredths of an inch. 13 is 0.13 inches)
void precipitation(station_data data)
{
   int precip = 0;
   if (data.PRCP > 49)
   {
       cout << "It rained more than 0.5 inches on this day." << endl;
   }

   return;
}

Explanation / Answer

The data1 array should be filled with the data file you have read from desktop, not with the random data. You can apply loop to get it store to the final array you have created station_A[307]. Also I am not getting why are you specifically creating the array of 307 records. You should decide the length of the array with the number of records in the file.

Hope this will be useful to you. I am attaching the part of the code to help you more.