Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 7 Change the program to use structs for temperature, wind, and weather m

ID: 3607071 • Letter: P

Question

Project 7

Change the program to use structs for temperature, wind, and weather measurement.

Refactor your program so that the code for

- temperature is in two files (.h – declarations) and (.cpp – implementations)

- wind is in two files (.h – declarations) and (.cpp – implementations)

-WeatherMeasurement is in two files (.h – declarations) and (.cpp – implementations)

- And your main is in one file

Make sure the program runs properly

I was told that this program would require at least 6 files so could you label each file and say which code goes in each file for the program. PLEASE MAKE SURE TO PROVIDE ALL THE FI LES. There should be at least 6. Please follow all steps carefully. Thank you. I really appreciate it.

C++ code:

#include "stdafx.h"

#include <iostream>

#include <string>

using namespace std;

void moveTemperaturesToRight(double temperatures[],

double windSpeed[],

string windDirection[])

{

for (int i = 3; i > 0; i--)

{

temperatures[i] = temperatures[i - 1];

windSpeed[i] = windSpeed[i - 1];

windDirection[i] = windDirection[i - 1];

}

}

int main()

{

string name;

int choice;

int numOfReadings = 0;

int size;

double temperatures[4], windSpeeds[4];

string windDirections[4];

bool initialized = false;

char str;

//Have the user provide a name for the weather station upon entry.

cout << "Enter the name of weather station: ";

getline(cin, name);

//Control loop to perform various actions.

while (true)

{

cout << "I. Input a complete weather reading." << " ";

cout << "P. Print the current weather." << " ";

cout << "H. Print the weather history (from most recent to oldest)." << " ";

cout << "E. Exit the program." << " ";

cout << "Enter your choice: ";

cin >> str;

if (str != 'I'&& str != 'P'&& str != 'H'&& str != 'E')

choice = 0;

else

choice = str;

//Switch based on choice.

switch (choice)

{

case 'I':

moveTemperaturesToRight(temperatures,

windSpeeds,

windDirections);

cout << "Enter the temperature:";

cin >> temperatures[0];

//get correct wind speed

do

{

cout << "Enter the wind speed (a value >=0):";

cin >> windSpeeds[0];

while (cin.fail() || (cin.peek() != ' ' && cin.peek() != ' '))

{

cout << "Invalid Input! Re Enter the wind speed" << endl;

cin.clear();

while (cin.get() != ' ');

cin >> windSpeeds[0];

}

} while (windSpeeds[0] < 0);

//get correct wind direction

do

{

cout << "Enter the wind direction (North,South,East or West):";

cin >> windDirections[0];

} while (windDirections[0] != "North" && windDirections[0] != "South" && windDirections[0] != "East" && windDirections[0] != "West");

initialized = true;

if (initialized)

numOfReadings++;

if (numOfReadings > 4)

numOfReadings = 4;

break;

case 'H': //Print the current weather, if valid weather is entered.

cout << "Enter size of the history wants:";

cin >> size;

if (numOfReadings<size)

{

cout << "History size is high";

break;

}

for (int i = 0; i < size; i++)

{

cout << "*****" << name << "*****" << " ";

cout << "Temperature: " << temperatures[i] << " ";

cout << "Wind speed: " << windSpeeds[i] << " ";

cout << "Wind direction: " << windDirections[i] << " " << " ";

}

if (numOfReadings == 0)

cout << "Please enter the details before asking to print." << " ";

break;

case 'P':

if (numOfReadings == 0)

{

cout << "Please enter the details before asking to print." << " ";

break;

}

cout << "*****" << name << "*****" << " ";

cout << "Temperature: " << temperatures[0] << " ";

cout << "Wind speed: " << windSpeeds[0] << " ";

cout << "Wind direction: " << windDirections[0] << " " << " ";

break;

case 'E':

return 0; //Stops execution.

default:

cout << "Invalid choice. Please follow the menu." << " ";

}

}

}

temperature.h

#pragma once

temperature.cpp

wind.h

#pragma once

wind.cpp

weatherMeasurement.h

#pragma once

weatherMeasurement.cpp

Explanation / Answer

#include <iostream>

#include <iomanip>

using namespace std;

// Constant for number of months

const int numMonths = 12;

//Function Prototypes

double getTotal(double []);

double getAverage(double []);

double getHighest(double [], int &);

double getLowest(double [], int &);

int main ()

{

// Array for holding the rainfall amounts

double rainFall[numMonths];

// Get rainfall for each month.

for (int month = 0; month < numMonths; month++)

{

// Get months rainfall

cout << "Enter the rainfall in inches for month #:";

cout << (month + 1) << ": ";

// Validate user input cannot accept negative numbers.

while (rainFall[month] < 0 )

{

cout << "Rainfall must be greater than 0. ";

cout << "Please enter correct total. ";

cin >> rainFall[month];

}

}

// Setting numeric output formatting

cout << fixed << showpoint << setprecision(2) << endl;

// Display total rainfall.

cout << "The total rainfall for the year is ";

cout << getTotal(rainFall)

<< " inches." << endl;

// Display the average rainfall from the year

cout << "The average rainfall for the year is ";

cout << getAverage(rainFall)

<< " inches." << endl;

// Display the largest amount of rainfall

int amount = 0;

cout << "The highest amount of rainfall was ";

cout << getHighest(rainFall, amount)

<< " inches in month ";

cout << (amount + 1) << "." << endl;

//Display the lowest amount of rainfall

cout << "The lowest amount of rainfall was ";

cout << getLowest(rainFall, amount)

<< " inches in month ";

cout << (amount +1) << "." << endl;

system ("pause");

return 0;

}

// getTotal array reads values from array to get total

double getTotal(double rainFall[])

{

double total = 0;

for (int count = 0; count < numMonths; count++)

total += rainFall[count];

return total;

}

// Get total to calculate the average

double getAverage(double rainFall[])

{

double average = 0.0;

average = getTotal(rainFall) / numMonths;

return average;

}

// Function to get the highest month rainfall

double getHighest(double rainFall[], int &amount)

{

double highest;

highest = rainFall[0];

or (int month = 0; month < numMonths; month++)

{

if (rainFall[month] > highest )

{

highest = rainFall[month];

amount = month;

}

}

return highest;

}

// Function to get the smallest month total

double getLowest(double rainFall[], int &amount)

{

double lowest;

lowest = rainFall[0];

for (int month = 0; month < numMonths; month++)

{

if (rainFall[month] < lowest )

{

lowest = rainFall[month];

amount = month;

}

}

return lowest;

}