Question

In: Computer Science

C ++ Data File Preparation 1. Using the original AL Weather Station Data file find all...

C ++ Data File Preparation

1. Using the original AL Weather Station Data file find all records that have a bad data flag (-9999) for either the PRCP, TMAX or TMIN fields. Produce a new data file (call it Filtered_AL_Weather_Station.txt ) that omits those records with bad data flags. This new file will be used in problem 2. NOTE: The temperatures are given in tenths of a degree Celsius. e.g 83 is 8.3 degrees C.   

2. Using the filtered data file from problem 1, create another file (weather_station_five_column.txt) with only the following five columns of information:

            STATION NAME           DATE PRCP TMAX              TMIN

Separate the date fields by inserting spaces and convert the temperatures from Celsius to Fahrenheit.

IMPORTANT: You will need to use the string conversion functions to convert the string type numbers to float or double. The functions are stof and stod. To convert a string to float do this:

string s_tmax; // string type for TMAX
float tmax; // float type for TMAX

// Convert string to float
tmax = stof(s_tmax);

Here is a sample of the output. (You may left justify station name if you like.)

Preliminary program to test the new data file.

3. Using the weather_station_five_column.txt file produced by problem two above:

  • Determine the highest and lowest temperatures in the state for the entire month of March 2018.
  • Print out (to the screen) the station names with highest and lowest temperatures along with the high and low values. (Multiple stations may record the same values for high and low.)

INTERACTIVE DATA PROCESSING

4. Using the five-column data file produced by problem 2 above write a program that gives the user five options as described by a-e below.

The program should provide a menu showing each of the five options. The user then selects one of the five options. Depending on the option the user will be prompted to enter the corresponding parameters. Then those parameters will be passed to a function to do the work.

A: Total Precipitation from all stations for a single day

User enters one day in mm dd yyyy format. Program returns total precipitation from all stations in inches for that date.

TEST CASES: March 10, March 20.

B: Total Precipitation over a range of dates.

User specifies start date and end date in mm dd yyyy format. Program returns total precipitation from all stations over the date range.

TEST CASE: 03 07 2018 through 03 12 2018

C: Total Precipitation by Station for March.

User enters station name. The program adds up the precipitation for the entire month from that station - or group of stations. (NOTE: Entering DECATUR will select all stations with DECATUR as all or part of the station name.)

TEST CASES: HUNTSVILLE, ATHENS

D: Temperature Extremes and Average by Station

User enters station name. e.g. BANKHEAD. The program finds and returns the maximum temp, minimum temp, average high temperature, and average low temperature for station during March. (Station names must match exactly.)

TEST CASES: MOBILE DOWNTOWN AIRPORT, DECATUR PRYOR FIELD

E. Temperature Extremes and Average by Station over a range of dates

User enters station name, start date and end date in mm dd yyyy format. The program computes and returns the maximum temp, minimum temp, average high temperature, and average low temperature for the specified station over the date range. (Station names must match exactly.)

TEST CASES: BIRMINGHAM AIRPORT 03 05 2018 03 15 2018
SCOTTSBORO 03 20 2018 03 31 2018

http://uahcs.org/CS121/data/AL_Weather_Station.txt

Solutions

Expert Solution

Working code implemented in C++ and appropriate comments provided for better understanding.

Source Code:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main(void) {
   ifstream weatherin;
   ofstream weatherout;
   string s_tmax, s_tmin, s_prcp, dataline;
   int pos_tmax, pos_tmin, pos_prcp;
   float f_tmax, f_tmin, f_prcp;
   unsigned int i = 0, records = 0;

   cout << "PROBLEM 1" << endl << endl;

   cout << "Attempting to open AL_Weather_Station.txt..." << endl << endl;
   weatherin.open("C:/Temp/AL_Weather_Station.txt");

   if (!weatherin) {
       cout << "ERROR: AL_Weather_Station file not found." << endl << endl;
       system("pause");
       return 1;
   }
   else {
       cout << "AL_Weather_Station file opened." << endl << endl;
   }

   cout << "Creating new file: Filtered_AL_Weather_Station.txt..." << endl << endl;
   weatherout.open("C:/Temp/Filtered_AL_Weather_Station.txt");
   if (!weatherout) {
       cout << "ERROR: Filtered_AL_Weather_Station file not found." << endl << endl;
       system("pause");
       return 1;
   }
   else {
       cout << "Filtered_AL_Weather_Station file opened." << endl << endl;
   }

   cout << "Attempting to find position of TMAX, TMIN, and PRCP columns..." << endl << endl;
   getline(weatherin, dataline);
   weatherout << dataline << endl;

   pos_tmax = dataline.find("TMAX");
   if (pos_tmax != string::npos) {
       cout << "The index of the TMAX column is " << pos_tmax << endl;
   }
   else
   {
       cout << "Unable to find TMAX" << endl << endl;
       system("pause");
       return 2;
   }

   pos_tmin = dataline.find("TMIN");
   if (pos_tmin != string::npos) {
       cout << "The index of the TMIN column is " << pos_tmin << endl;
   }
   else
   {
       cout << "Unable to find TMIN" << endl << endl;
       system("pause");
       return 2;
   }
  
   pos_prcp = dataline.find("PRCP");
   if (pos_prcp != string::npos)
       cout << "The index of the PRCP column is " << pos_prcp << endl << endl;
   else
   {
       cout << "Unable to find PRCP" << endl << endl;
       system("pause");
       return 2;
   }

   // Skipping formatting line
   getline(weatherin, dataline);

   cout << "Parsing data..." << endl << endl;

   while (!weatherin.eof()) {
       // Continuously scroll through each line of data
       getline(weatherin, dataline);

       // Find the value for each header
       s_tmax = dataline.substr(pos_tmax, 5);
       s_tmin = dataline.substr(pos_tmin, 5);
       s_prcp = dataline.substr(pos_prcp, 5);

       // Converting string values to floats
       f_tmax = stof(s_tmax);
       f_tmin = stof(s_tmin);
       f_prcp = stof(s_prcp);

       if (f_tmax != -9999 && f_tmin != -9999 && f_prcp != -9999) {
           weatherout << dataline << endl;
           records++;
       }
   }

   cout << "Total number of valid weather data entries: " << records << endl << endl;
  
   cout << "Closing files..." << endl << endl;
   weatherin.close();
   weatherout.close();

   system("pause");
   return 0;
}


Related Solutions

C++ 1. Modify this program to open the file "Customers.dat" so that all data is written...
C++ 1. Modify this program to open the file "Customers.dat" so that all data is written to the end of the file AND to allow the file to be read. 2. Create a method called "getLargestCustomerNumber" and call it after the "Customers.dat" file has been opened. Read all the existing customerNumbers and determine the largest customerNumber - do not assume the last record in the file is the largest number. Use this number as the base when adding new customer...
What contribution might the weather data file make to the performance gap?
What contribution might the weather data file make to the performance gap?
1. Create one XML data file and one DTD file for the entire data set (using...
1. Create one XML data file and one DTD file for the entire data set (using a subset of SQL assignment – see below). [Use of ID and IDREF are not required.] 2. Write and execute XML statements for the following two queries: Q1. Find the name of an employee who lives in Lincoln and works in Omaha. Q2. Find salaries of employees who live in the same cities as the companies for which they work. [You can replace one...
Using the data provided in the excel file, show all of your work for the following...
Using the data provided in the excel file, show all of your work for the following calculations: a.) mean temperature of unmixed reagents (oC) b.) δελταT from graph (oC) c.) q absorbed by reaction mixture (J) d.) q absorbed by calorimeter, stirrer, and thermometer (J) e.) q total absorbed (J) f.) q total released (J) g.) calculation to show limiting reagent h.) deltaH neutralization for the reaction (kJ/mole of acid) A student reacted 100.0 mL of 0.9800 M HCl with...
C++ (data structure using c++). please send me copyable file. Write a program and test a...
C++ (data structure using c++). please send me copyable file. Write a program and test a program that translates the following Bubble Sort algorithm to a bubblesort function. The function's prototype is, void bubblesort(int a[], int size); Bubble Sort The inner loop moves the largest element in the unsorted part of the array to the last position of the unsorted part of the array; the outer loop moves the last position of the unsorted part of the array. The Bubble...
Using C Programming. Put all of these 4 things in one source file and attach to...
Using C Programming. Put all of these 4 things in one source file and attach to this question. Put #1 in main. Put all the others into separate function functions but in the same file.   1)   Put this code in main. You are writing a program for Bowl Me Over, a local bowling alley. The program will allow staff to enter any number of bowling scores. Scores in a standard game range between 0 to 300, with being a perfect...
Using C programming I have a file that contains earthquake data that I will copy and...
Using C programming I have a file that contains earthquake data that I will copy and paste below. I want to use either bubble or insertion sort to sort the file by latitude in ascending order, then create a new file containing the sorted data. example file to sort: time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net 2020-10-17T17:22:03.840Z,32.877,-116.2991667,0.31,1.16,ml,21,119,0.07747,0.26,ci 2020-10-17T17:17:29.980Z,34.1611667,-116.452,2.75,0.87,ml,17,66,0.05224,0.22,ci 2020-10-17T17:03:54.460Z,33.5396667,-116.4613333,8.66,0.63,ml,18,126,0.06084,0.16,ci 2020-10-17T16:55:01.080Z,63.254,-151.5232,8,1.4,ml,,,,0.9,ak
Using OOP, write a C++ program that will read in a file of names. The file...
Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...
. Using your data file Ice Cream, find:             Temperature = Independent Variable; Sales = Dependent...
. Using your data file Ice Cream, find:             Temperature = Independent Variable; Sales = Dependent variable Temperature Sales 63 1.52 70 1.68 73 1.80 75 2.05 80 2.36 82 2.25 85 2.68 88 2.90 90 3.14 91 3.06 92 3.24 75 1.92 98 3.40 100 3.28 92 3.17 87 2.83 84 2.58 88 2.86 80 2.26 82 2.14 76 1.98            a. What is an appropriate null hypothesis for Regression Analysis?            b. What is the test statistic (F)...
Since all of the data used in the preparation of the Statement of Cash Flows are...
Since all of the data used in the preparation of the Statement of Cash Flows are available on the other financial statements or in mandatory footnote disclosures, why prepare it? What insights does it provide that make it valuable to the financial statement reader?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT