Assignment Details There is a .h file on Moodle that provides a definition for a
WeatherForecaster class. The functionality for that class is similar to the functionality you
implemented in Assignment 5, with a few additional functions. Instead of using an array of
structs and functions to process the array, you will create one WeatherForecaster object that
includes the array of structs as a private variable and public methods to process the data. The
struct for this assignment has an additional member called forecastDay, you will need to store all
of the data this time. struct ForecastDay{ string day; string forecastDay; int highTemp; int
lowTemp; int humidity; int avgWind; string avgWindDir; int maxWind; string maxWindDir;
double precip; }; Methods in the WeatherForecaster class void addDayToData(ForecastDay); •
Takes a ForecastDay as an argument and adds it to the private array stored in the
WeatherForecaster object. • Use the private index variable to control where ForecastDay is
added to the array. void printDaysInData(); • Show the dates in the data set where the day and
the forecast day are the same. void printForecastForDay(string); • Take a date as an argument
and shows the forecast for that date. CSCI 1310 - Assignment 6 Due Saturday, Oct 15, by 12:30
pm void printFourDayForecast(string); • Takes a date as an argument and shows the forecast
issued on that date and for the next three days. For example, for a date of 1- 26-2016, you would
show the forecast for 1-26-2016 issued on 1- 26-2016 as well as the forecast for 1-27, 1-28, and
1-29 issued on 1-26. double calculateTotalPrecipitation(); • Returns the sum of the precipitation
in the data set. void printLastDayItRained(); • Shows the date of the last measureable
precipitation. void printLastDayAboveTemperature(int); • Takes an integer as an argument and
shows the date for the last day above that temperature. If no days are above the temperature,
prints “No days above that temperature.” void printTemperatureForecastDifference(string); •
Takes a date as an argument and shows the temperature forecast for that date for the three days
leading up to the date and the day-of forecast. void printPredictedVsActualRainfall(int); • Shows
the difference between the predicted and actual rainfall total in the entire data set. • The
argument to the function is the number of forecast days away. For example, the forecast for 1-27-
2016 is one day away from 1- 26-2016. string getFirstDayInData(); • Returns the first date in the
data with a day-of forecast, i.e. day = forecastDay string getLastDayInData(); • Returns the last
date in the data with a day-of forecast, i.e. day = forecastDay Challenge functions 1. There is
another header file on Moodle called WeatherForecastChallenge.h that uses a vector to store the
future forecast days. Instead of including all data in the yearData array, you can include only
days where the day = forecast day in the array. The other forecast days are stored in the vecto.
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
Assignment Details There is a .h file on Moodle that provides a defi.pdf
1. Assignment Details There is a .h file on Moodle that provides a definition for a
WeatherForecaster class. The functionality for that class is similar to the functionality you
implemented in Assignment 5, with a few additional functions. Instead of using an array of
structs and functions to process the array, you will create one WeatherForecaster object that
includes the array of structs as a private variable and public methods to process the data. The
struct for this assignment has an additional member called forecastDay, you will need to store all
of the data this time. struct ForecastDay{ string day; string forecastDay; int highTemp; int
lowTemp; int humidity; int avgWind; string avgWindDir; int maxWind; string maxWindDir;
double precip; }; Methods in the WeatherForecaster class void addDayToData(ForecastDay); •
Takes a ForecastDay as an argument and adds it to the private array stored in the
WeatherForecaster object. • Use the private index variable to control where ForecastDay is
added to the array. void printDaysInData(); • Show the dates in the data set where the day and
the forecast day are the same. void printForecastForDay(string); • Take a date as an argument
and shows the forecast for that date. CSCI 1310 - Assignment 6 Due Saturday, Oct 15, by 12:30
pm void printFourDayForecast(string); • Takes a date as an argument and shows the forecast
issued on that date and for the next three days. For example, for a date of 1- 26-2016, you would
show the forecast for 1-26-2016 issued on 1- 26-2016 as well as the forecast for 1-27, 1-28, and
1-29 issued on 1-26. double calculateTotalPrecipitation(); • Returns the sum of the precipitation
in the data set. void printLastDayItRained(); • Shows the date of the last measureable
precipitation. void printLastDayAboveTemperature(int); • Takes an integer as an argument and
shows the date for the last day above that temperature. If no days are above the temperature,
prints “No days above that temperature.” void printTemperatureForecastDifference(string); •
Takes a date as an argument and shows the temperature forecast for that date for the three days
leading up to the date and the day-of forecast. void printPredictedVsActualRainfall(int); • Shows
the difference between the predicted and actual rainfall total in the entire data set. • The
argument to the function is the number of forecast days away. For example, the forecast for 1-27-
2016 is one day away from 1- 26-2016. string getFirstDayInData(); • Returns the first date in the
data with a day-of forecast, i.e. day = forecastDay string getLastDayInData(); • Returns the last
date in the data with a day-of forecast, i.e. day = forecastDay Challenge functions 1. There is
another header file on Moodle called WeatherForecastChallenge.h that uses a vector to store the
future forecast days. Instead of including all data in the yearData array, you can include only
days where the day = forecast day in the array. The other forecast days are stored in the vector.
For example, the forecast for 1-26 issued on 1-26 is stored in the array. That element in the array
then has a vector that stores the forecasts for 1-27, 1-28, and 1-29. Functionality in main() In
your main() function, you will need to open the file, read in the data, and create an instance of
2. WeatherForecaster. Once you’ve populated a ForecastDay instance, you add it to your
WeatherForecaster instance using the addDayToData method. CSCI 1310 - Assignment 6 Due
Saturday, Oct 15, by 12:30 pm Once you’re confident that the array data is correct, call the
methods to analyze the data and print the results. Your output should look like this: Forecast
statistics: Last day it rained: Total rainfall: First date in data: Last date in data: Your main
function should prompt the user for a date and pass that date as an argument to the
printForecastForDay and printFourDayForecast methods to display the information. If the date is
not found in the file, your program should print “Date not found.” WeatherForecaster wf;
cout<<”Enter a date:”; getline(cin, date); wf.printForecastForDay(date); Information displayed
in printForecastForDay: Forecast for : H: L: Humidity: Avg. wind: Avg. wind direction: Max
wind: Max wind direction: Precipitation: For printFourDayForecast, repeat information for all
four days. Information displayed for printDaysInForecast: 1-26-2016 1-27-2016 1-28-2016 . . .
9-29-2016 Information displayed for getFirstDayInData: 1-26-2016 Information displayed for
getLastDayInData: CSCI 1310 - Assignment 6 Due Saturday, Oct 15, by 12:30 pm 9-29-2016
Information displayed for printPredictedVsActualRainfall: Predicted rainfall in -day forecast
inches Actual rainfall in day-of forecast inches Information displayed for
printTemperatureForecastDifference: Forecast for issued on H: L: Forecast for issued on H: L:
Forecast for issued on H: L: Actual forecast for H: L: Information for
calculateTotalPrecipitation: Total precipitation: inches Information for printLastDayItRained: It
last rained on: Information for printLastDayAboveTemperature: It was above on
Solution
#include
#include "WEATHERFORECASTER.h"
using namespace std;
int main()
{
WeatherForecaster yD;
yD.printDaysInData();
//yD.addDayToData();
// yD.printForecastForDay("9-16-2016");
yD.getFirstDayInData();
yD.getLastDayInData();
}
Here is the header file:
3. #ifndef WEATHERFORECASTER_H
#define WEATHERFORECASTER_H
#include
struct ForecastDay{
std::string day;
std::string forecastDay;
int highTemp;
int lowTemp;
int humidity;
int avgWind;
std::string avgWindDir;
int maxWind;
std::string maxWindDir;
double precip;
};
class WeatherForecaster
{
public:
WeatherForecaster();
~WeatherForecaster();
void addDayToData(ForecastDay);
void printDaysInData(); //prints the unique dates in the data
void printForecastForDay(std::string);
void printFourDayForecast(std::string);
double calculateTotalPrecipitation();
void printLastDayItRained();
void printLastDayAboveTemperature(int); //argument is the temperature
void printTemperatureForecastDifference(std::string);
void printPredictedVsActualRainfall(int); //argument is days out, such as 1 = 1 day out, 2 = 2
days out, 3 = 3 days out
std::string getFirstDayInData();
std::string getLastDayInData();
protected:
private:
int arrayLength = 984;
4. int index;
ForecastDay yearData[984]; //data for each day
};
#endif // WEATHERFORECASTER_H
Here is the source file:
#include "WEATHERFORECASTER.h"
#include
#include
#include
#include
#include
using namespace std;
WeatherForecaster::WeatherForecaster()
{
//ctor
ifstream Fore; //Open up the file DATABOULDER.csv for weather data
Fore.open("DATABOULDER.csv");
if (Fore.fail()) //If it fails nothing will happen
{
}
else
{ //Otherwise open the file and begin sorting the data
string weather; //Create a string called weather
int lineIndex = 0; //Create a counter for the lines
while (getline(Fore, weather, ' ')) //Move through each line of the data by stopping at a
character return
{ //Set the weather variable to that whole line of data
stringstream ss; //Create a stream using the weather string
ss << weather;
int weatherIndex = 0; //Create a new Index counter for each piece of data within the line
while (getline(ss, weather, ',')) //Go through the line and every comma store that as a
weatherIndex
{
if (weatherIndex == 0) //Begin setting the pieces of the array beginning with the first index
{
string day = yearData[lineIndex].day; //If the index is 0 then set it as the .day extension
5. yearData[lineIndex].day = weather; //Set this equal to the weather variable in order to get the
actual piece of data
}
else if (weatherIndex == 1) //If Index is 1 then this is the forecast day so use that extension
{
string forecastDay = yearData[lineIndex].forecastDay;
yearData[lineIndex].forecastDay = weather; //Set that equal to the weather variable to get actual
data
}
else if (weatherIndex == 2) //If the Index is 2 then this is the high temp
{
istringstream convert(weather); //First convert weather so it can take ints
int highTemp = 0; //Create a highTemp int variable
string strHighTemp = ""; //Create a string to use with the string for converting the highTemp
strHighTemp = weather.substr(2, 2); //This allows for the H: to be removed and only a number
or int
if (!(istringstream(strHighTemp) >> highTemp)) highTemp = 0;//Converting string highTemp to
int highTemp and if it fails set highTemp to 0
yearData[lineIndex].highTemp = highTemp;
}
else if (weatherIndex == 3)
{
istringstream convert(weather); //Perform the exact same steps as previous for low temperatures
int lowTemp = 0;
string strLowTemp = "";
strLowTemp = weather.substr(2, 2);
if (!(istringstream(strLowTemp) >> lowTemp)) lowTemp = 0;
yearData[lineIndex].lowTemp = lowTemp;
}
else if (weatherIndex == 4) //If Index is 4 then that is humidity and we need to convert
{
istringstream convert(weather); //Convert weather to take ints
int humidity = 0; //Initialize a variable for humidity
if (!(istringstream(weather) >> humidity)) humidity = 0;//Convert string humidity to int
humidity and if it fails set humidity to 0
yearData[lineIndex].humidity = humidity; //Set this index of the array to humidity variable type
6. int
}
else if (weatherIndex == 5) //If Index is 5 then that is avgWind and we must convert
{
istringstream convert(weather); //Convert weather to take ints
int avgWind = 0; //Initialize variable for avgWind
if (!(istringstream(weather) >> avgWind)) avgWind = 0; //Convert string avgWind to int
avgWind and if it fails set avgWind to 0
yearData[lineIndex].avgWind = avgWind; //Set this index of the array to the avgWind variable
type int
}
else if (weatherIndex == 6) //If Index is 6 then it is the avg Wind Direction
{
yearData[lineIndex].avgWindDir = weather; //Set this index of the array to weather since it is a
string
}
else if (weatherIndex == 7) //If Index is 7 then it is max Wind
{
istringstream convert(weather); //Convert weather to take ints
int maxWind = 0; //Initialize variable for maxWind
if (!(istringstream(weather) >> maxWind)) maxWind = 0;//Convert string maxWind to int
maxWind and if it fails set maxWind to 0
yearData[lineIndex].maxWind = maxWind; //Set this index of the array to the maxWind
variable type int
}
else if (weatherIndex == 8) //If Index is 8 then it is max Wind Direction
{
yearData[lineIndex].maxWindDir = weather; //Set equal to weather since it is a string
}
else if (weatherIndex == 9) //If Index is 9 then it is precipitation
{
istringstream convert(weather); //Convert weather to take doubles
double precip = 0; //Initialize variable for precipitation type double
if (!(istringstream(weather) >> precip)) precip = 0;//Convert string precip to int precip and if it
fails set it to 0
yearData[lineIndex].precip = precip; //Set this index of the array to the precip variable of type
7. double
}
weatherIndex++; //Increment each weatherIndex to get all lines
}
lineIndex++; //Increment each lineIndex to get all pieces from the lines
}
}
}
WeatherForecaster::~WeatherForecaster()
{
//dtor
}
/*void WeatherForecaster::addDayToData(ForecastDay day)
{
if(index < arrayLength)
{
yearData[index].forecastDay = ForecastDay;
index++;
}
else
{
cout<<"array full"<