Starting from:

$25

CSCI1310- Assignment 6 Solved

For this assignment, you need to submit three files: WeatherForecaster.hpp, WeatherForecaster.cpp, and main.cpp. The files should be zipped to create on .zip file called Assignment6_LastName, where LastName is your last name. Please include comments in your code that explain what your code is doing. The comments should also include your name, recitation TA, and the assignment number. 

 

Weather forecasting  

Objectives:

 

1.     Apply the concept of program decomposition.

2.     Define a class managing multiple files for the header, methods and driver. 

3.     Apply the concept of private vs public variables and functions.

 

This assignment builds on the previous assignment by incorporating classes into your program. The data file you will use is the same, it’s the boulderData file on Moodle. If you downloaded that file and changed its format for Assignment 5, you are welcome to use your same file for this assignment.

 

​     The boulderData​ file contains comma-delimited information about the weather forecast for the current and the next three days. 

 

The first day in the file is January 26, 2016 and the last day in the file is September 29, 2016. The format for each line in the file is as follows:

 

Day
Forecas t day
High temp
Low temp
Humidit

y
Avg. wind
Avg. wind

direct

.
Max. wind
Max. wind

direct

.
Preci p
1-26

-201

6
1-26-20 16
H:40
L:26
43
6
WNW
10
WNW
0.0
 

       Day: The current day​

 

Forecast day: The day that the forecast is for. In this example, the day and forecast​      day are the same, which means it’s the forecast for 1-26-2016 on 1-26-2016. There are other lines in the file that show the forecast for a future day. For example, if the day were 1-26-2016 and forecast day were 1-27-2016, it would be the forecast for 1-27-2016 issued on 1-26-2016.

 

High temp:​ The forecasted high temp for the forecast day.

 

Low temp:​ The forecasted low temp for the forecast day.

 

Humidity:​ The forecasted humidity for the forecast day.

 

Avg. wind:​ The forecasted average wind speed for the forecasted day.

 

Avg. wind direction:​ The forecasted average wind direction for the forecasted day.

 

Max. wind:​ The forecasted maximum wind speed for the forecasted day. Max. wind direct.:​ The forecasted direction for the maximum wind speed for the forecasted day.

 

Precip.:​ The forecasted precipitation.

 

Assignment Details
There is a .hpp 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;

 };  

 

 


​6

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 printForecastForDay(string);

●      Take a date as an argument and shows the forecast for that day.

(when day == forecastDay)
    

void printFourDayForecast(string);

●      Takes a date as an argument and shows the forecast issued on that date and for the next three days (see expected output below). 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. The accumulator is modified only when forecastDay is the current day (day == forecastDay)​     .      

 

void printLastDayItRained();  

●      Shows the date of the last measureable precipitation.

(when day == forecastDay)
    

void printLastDayAboveTemperature(int);

● Takes an integer (temperature) 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.”

(when day == forecastDay)
 

      void printTemperatureForecastDifference(string);        

●      Takes a date as an argument and shows the temperature forecast for that date using the three days leading up to the date and the day-of forecast.

 

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

 

 

 

 

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.

 

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: <date of last rain event

Total rainfall: <sum of precipitation

First date in data: <date

Last date in data: <date

 

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 <date:  

H: <high temp

L: <low temp

Humidity: <humidity

Avg. wind: <avg wind speed

Avg. wind direction: <avg wind direction

Max wind: <max wind speed

Max wind direction: <max wind direction

Precipitation: <precip  

 

For printFourDayForecast​ , repeat information for all four days.

 

Information displayed for getFirstDayInData​ :

 

1-26-2016

 

Information displayed for getLastDayInData​ :

 

9-29-2016

 

Information displayed for printTemperatureForecastDifference​ :

 

Forecast for <date 1 issued on <date 2

H:<high temp

L:<low temp

Forecast for <date 1 issued on <date 3

H:<high temp

L:<low temp

Forecast for <date 1 issued on <date 4

H:<high temp

L:<low temp

Actual forecast for <date 1

H:<high temp

L:<low temp

 

Information for calculateTotalPrecipitation​ :

Total rainfall: <double inches

 

Information for printLastDayItRained​ :

Last day it rained: <date  

  

Information for printLastDayAboveTemperature​ :

It was above <temperature on <date

 

More products