SlideShare a Scribd company logo
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
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:
#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;
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
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
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
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"<

More Related Content

PDF
The Weather Service Bureau department has data representing .pdf
DOC
Cmis 102 hands on/tutorialoutlet
DOCX
1 CMIS 102 Hands-On Lab Week 8 Overview Th.docx
DOCX
#include Status.hnamespace sdds{StatusStatus(c
DOCX
#include Status.hnamespace sdds{StatusStatus(c
PDF
@author Haolin Jin To generate weather for locatio.pdf
PDF
DO NOT use System.exit().DO NOT add the project or package stateme.pdf
PDF
AnswerNote Entire skeleton of the code is provided. The below co.pdf
The Weather Service Bureau department has data representing .pdf
Cmis 102 hands on/tutorialoutlet
1 CMIS 102 Hands-On Lab Week 8 Overview Th.docx
#include Status.hnamespace sdds{StatusStatus(c
#include Status.hnamespace sdds{StatusStatus(c
@author Haolin Jin To generate weather for locatio.pdf
DO NOT use System.exit().DO NOT add the project or package stateme.pdf
AnswerNote Entire skeleton of the code is provided. The below co.pdf

Similar to Assignment Details There is a .h file on Moodle that provides a defi.pdf (20)

DOCX
(1) Learn to create class structure in C++(2) Create an array of.docx
DOCX
Opp compile
PDF
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
PDF
URGENTJavaPlease updated the already existing Java program and m.pdf
PDF
Functional C++
PDF
8 arrays and pointers
PDF
P2
PPTX
User defined datatype in C++ with examples
PPSX
SRAVANByCPP
PDF
PDF
Lo17
PDF
PDF
Problem DefinitionBuild a Date class and a main function to test i.pdf
PPTX
Chp 3 C++ for newbies, learn fast and earn fast
DOCX
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
PPTX
Chapter -6.pptx ethics and emergng thechnology
PDF
Please make a comment for all the codesOr explain this pro.pdf
PDF
Please I am posting the fifth time and hoping to get this r.pdf
PPT
Lec2&3 data structure
(1) Learn to create class structure in C++(2) Create an array of.docx
Opp compile
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
URGENTJavaPlease updated the already existing Java program and m.pdf
Functional C++
8 arrays and pointers
P2
User defined datatype in C++ with examples
SRAVANByCPP
Lo17
Problem DefinitionBuild a Date class and a main function to test i.pdf
Chp 3 C++ for newbies, learn fast and earn fast
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
Chapter -6.pptx ethics and emergng thechnology
Please make a comment for all the codesOr explain this pro.pdf
Please I am posting the fifth time and hoping to get this r.pdf
Lec2&3 data structure
Ad

More from jyothimuppasani1 (20)

PDF
How does an open source operating system like Linux® affect Internet.pdf
PDF
Help please!!(Include your modified DList.java source code file in.pdf
PDF
how can I replace the Newsfeed text with a custom on in SharePoi.pdf
PDF
Hello!This is Java assignment applet.Can someone help me writing.pdf
PDF
For each of the following reseach questions identify the observation.pdf
PDF
Find an Eulerian trail in the following graph. Be sure to indicate th.pdf
PDF
File encryption. [32] Write a program which accepts a filename as a .pdf
PDF
Explain the relevance that medical standards of practice have to one.pdf
PDF
Find the mission and values statements for four different hospita.pdf
PDF
Did colonial rule freeze colonized societies by preserving old s.pdf
PDF
Do you think that nonhuman animals have interests Does this mean th.pdf
PDF
Discuss the importance of recognizing and implementing different ent.pdf
PDF
Considering the challenges she is facing, what Anitas plan before .pdf
PDF
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
PDF
Conceptual skills are most important at theSolutionConceptual .pdf
PDF
A variable whose scope is restricted to the method where it was decl.pdf
PDF
•Design (create) 3 questions for a quiz show game and design regular.pdf
PDF
You are to write a GUI program that will allow a user to buy, sell a.pdf
PDF
write the To Dos to get the exact outputNOte A valid Fraction .pdf
PDF
What are the factors that contribute to H+ gain or loss How do lung.pdf
How does an open source operating system like Linux® affect Internet.pdf
Help please!!(Include your modified DList.java source code file in.pdf
how can I replace the Newsfeed text with a custom on in SharePoi.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdf
For each of the following reseach questions identify the observation.pdf
Find an Eulerian trail in the following graph. Be sure to indicate th.pdf
File encryption. [32] Write a program which accepts a filename as a .pdf
Explain the relevance that medical standards of practice have to one.pdf
Find the mission and values statements for four different hospita.pdf
Did colonial rule freeze colonized societies by preserving old s.pdf
Do you think that nonhuman animals have interests Does this mean th.pdf
Discuss the importance of recognizing and implementing different ent.pdf
Considering the challenges she is facing, what Anitas plan before .pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Conceptual skills are most important at theSolutionConceptual .pdf
A variable whose scope is restricted to the method where it was decl.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf
You are to write a GUI program that will allow a user to buy, sell a.pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
What are the factors that contribute to H+ gain or loss How do lung.pdf
Ad

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Types and Its function , kingdom of life
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Pharma ospi slides which help in ospi learning
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Basic Mud Logging Guide for educational purpose
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial disease of the cardiovascular and lymphatic systems
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
FourierSeries-QuestionsWithAnswers(Part-A).pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Types and Its function , kingdom of life
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Computing-Curriculum for Schools in Ghana
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Pharma ospi slides which help in ospi learning
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
Anesthesia in Laparoscopic Surgery in India
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPH.pptx obstetrics and gynecology in nursing

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"<