Starting from:

$30

CSCI1310- Assignment 5​ Solved

For this assignment, the solution should be in the Code Runner. You must include comments in your code that explain what your code is doing.

 

Weather forecasting 
 

Objectives:

 

1.     Apply the concept of program decomposition.

2.     Populate an array of structs from a file. 

3.     Design functions that access the attributes of a struct.

 

In this assignment, you will process a file of weather forecasting data for Boulder and answer a few questions about the weather. There is a file on moodle called

​       boulderData that contains comma-delimited information about the weather forecast for each day 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
Forecast day
High temp
Low temp
Humidity
Avg. wind
Avg.

wind direct.
Max. wind
Max.

wind direct.
Precip
1-2

6-2

016
1-26-2 016
H:4

0
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
For this assignment, you need to read in the data stored in the file and store it in an array of structs of maximum 10 elements. Your struct should have the following minimum set of attributes:

 

struct Forecast{     string day;     int highTemp;     int lowTemp;     int humidity;     int avgWind;     string avgWindDir;     int maxWind;     string maxWindDir;     double precip;

};

 

Store only the most current forecast for each day, this would be the lines in the file where the Day and Forecast day are the same. Discard the other lines in the file by not reading them into your array. Your array will need to store 245 days worth of data.

NOTE: If you’re planning to do the additional functions suggested below, After submitting the assignment in moodle, modify your program to store all of the data and add an additional parameter to your struct for forecast day. 

 

Functions that need to be in your program
 

void populateArray(string filename,Forecast forecastData[]);

●      Populates the array reading data from file called filename.

 

string lastDayItRained(Forecast forecastData[]);

●      Returns the date of the last day it rained.

 

double totalRainfall(Forecast forecastData[]);

●      Returns the sum of the precipitation in the data set.

 

 

int maxWindspeed(Forecast forecastData[]);

●      Returns the index in the array where the maximum wind speed is found.

 

int maxRainfall(Forecast forecastData[]);

●      Returns the index in the array where the maximum precipitation is found.

 

int maxTempDifference(Forecast forecastData[]);

●      Returns the index in the array where with the maximum difference between the high and low temperature.

 

Forecast forecastForDay(Forecast forecastData[], string day); ● Returns the forecast for a particular day in the array.

 

Functionality in main()
In your main()​  function, declare Forecast struct array and call the populateArray function passing the filename and the struct array. Once you’re confident that the array data is correct, call the other functions 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

Maximum wind speed: <wind mph mph on <date

Maximum rainfall: <precipitation inches on <date

Maximum temperature difference: <high - low F on <date

 

Further your main function should prompt the user for a date and display the forecast for that date. If the date is not found in the file, your program should print “Date not found.”

 

cout<<”Enter a date:”; getline(cin, date)

Forecast dayForecast = forecastForDay(forecastData, date);

 

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 

 

 

Additional practice problems:

If you are interested in additional problems for practice, here are a few more functions you can work on. We won’t be grading them, but a little extra practice never hurt anyone. 

 

1.     Determine the day of the year when the three-day forecast and the day-of forecast showed the greatest difference for high temperature. If there are ties, print all days with the greatest difference.

2.     Determine how accurate the precipitation forecast is for one, two, and three days from the current day.

3.     Find the missing data point(s). There is at least one day of data missing from the file. Write a function to find it.

More products