Question: the output needs to look like this and pulled from a csv file Number of data records: 941 Beginning date: 2015-01-13 Ending date: 2021-10-23 Maximum

the output needs to look like this and pulled from a csv file

Number of data records: 941 Beginning date: 2015-01-13 Ending date: 2021-10-23 Maximum temperature: 106 degrees on 2018-06-14 Minimum temperature: 13 degrees on 2020-01-24 Number of days 100 and over: 32 Number of days below freezing: 49

//DailyReading.cpp

/** * Implementation (Definition) of DailyReading class **/ #include "DailyReading.h"

/** * Constructor * @param max is the max temperature for this record **/ DailyReading::DailyReading(int max) { maxTemperature = max; }

/** * Report if the day's max temperature is greater than the * given reference temperature. * @param refTemp is the reference temperature to compare against * @return true if this day's max is greater than the reference temp **/ bool DailyReading::maxGreaterThan(int refTemp) { return maxTemperature > refTemp; }

/** * Return a string for reporting the maximum temperature. * @return a string containing the report **/ std::string DailyReading::maxOnDateString() { return std::to_string(maxTemperature) + std::string(" degrees on "); }

//DailyReading.h

// // Declaration of DailyReading class // #ifndef DAILYREADING_H #define DAILYREADING_H #include

#include

class DailyReading { public: DailyReading(int max); bool maxGreaterThan(int refTemp); std::string maxOnDateString(); private: int maxTemperature; };

#endif // DAILYREADING_H

// main.cpp

/****************************************************************** * Weather data processing app, starting version ******************************************************************/ #include #include #include #include #include "DailyReading.h"

// Helper function declarations; definitions are below main() void readDataFile(std::ifstream& inFile, std::vector& dataset); void printDataset(std::vector& dataset);

/** * Program start **/ int main(int argc, char* argv[]) { // check to make sure we have one command line argument if (argc != 2) { std::cerr << "Error: a filename argument must be given "; return -1; } // The collection of all of our daily readings that we read in // from the data file; we store the collection in a vector, // which acts as a list or kind-of like a variable-sized array std::vector dataset; // Create an input stream object for the filename given as an argument; // this also opens the file for reading std::ifstream inFile(argv[1]); if (!inFile) { std::cerr << "Error: file " << argv[1] << " cannot be opened "; return -1; } // now we have an open file, so read it in and get our data std::cout << "Readinge the data file...."; readDataFile(inFile, dataset); inFile.close(); std::cout << "done. "; // now use the dataset in a function printDataset(dataset); return 0; }

/** * Read in a weather data file and save the relevant data fields * in a collection (vector) of DailyReading objects * @param inFile is an open ifstream object to read the file from * @param dataset is collection to put the temperature readings into **/ void readDataFile(std::ifstream& inFile, std::vector& dataset) { std::string line; int max=0; // read first line of file (data column titles) and throw it away std::getline(inFile, line); // read the rest of the file line by line; this is safer // than trying to parse the lines as you read the data in while (std::getline(inFile, line)) { // uncomment the next line if you are debugging and need to // see what each line looks like //std::cout << "line is [" << line << "] "; if (line.length() < 2) continue; // probably at end of file // now treat the line itself as an input stream (from a string!) std::istringstream lineStream(line); std::string piece; int column = 0; // loop below separates pieces of the line by commas while (std::getline(lineStream, piece, ',')) { // remove quotation marks on data, if they exist if (piece.front() == '"' && piece.back() == '"') piece = piece.substr(1,piece.size()-2); // uncomment the next line if you are debugging and need to // see what each piece looks like //std::cout << " piece [" << piece << "] "; column++; if (column == 15) { // max temp column max = std::stoi(piece); } } // make a new DailyReading object DailyReading* today = new DailyReading(max); // add this object to our collection dataset.push_back(today); } }

/** * An example of iterating over the dataset collection * and using each object (just to print out one message) * @param dataset is collection of temperature readings to use **/ void printDataset(std::vector& dataset) { std::cout << "Data printout for " << dataset.size() << " readings "; for (DailyReading* day: dataset) { std::cout << "day: (" << day->maxOnDateString() << ") "; } }

//weather-small.csv

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!