CSCI 1310 Introduction to Computer Programming Assignment 6

$30.00

Category:

Description

5/5 - (3 votes)

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.
CSCI 1310 – Assignment 6 Due Saturday, Mar 10, by 08:00 am
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;
};
CSCI 1310 – Assignment 6 Due Saturday, Mar 10, by 08:00 am
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()
CSCI 1310 – Assignment 6 Due Saturday, Mar 10, by 08:00 am
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:
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 getFirstDayInData:
1-26-2016
Information displayed for getLastDayInData:
9-29-2016
CSCI 1310 – Assignment 6 Due Saturday, Mar 10, by 08:00 am
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 rainfall: inches
Information for printLastDayItRained:
Last day it rained:
Information for printLastDayAboveTemperature:
It was above on