Question: Project 5 Extend the functionality of project 4 to - incorporate a history of the past 4 weather measurements - update the user menu to

Project 5

Extend the functionality of project 4 to

- incorporate a history of the past 4 weather measurements

- update the user menu to include

- printing the current weather

- printing the weather history (from most recent to oldest)

Use a text-driven menu to present the choices for actions to the user

c++ code:

#include 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; double temperatures[4], windSpeeds[4]; string windDirections[4]; //Have the user provide a name for the weather station upon entry. cout << "Enter the name of weather station: "; cin >> name; //Control loop to perform various actions. while(true) { cout << "1. Input a complete weather reading." << endl; cout << "2. Print the current weather." << endl; cout << "3. Print the weather history (from most recent to oldest)." << endl; cout << "4. Exit the program." << endl; cout << "Enter your choice: "; cin >> choice; //Switch based on choice. switch(choice) { case 1: moveTemperaturesToRight(temperatures, windSpeeds, windDirections); cout << "Enter the temperature: "; cin >> temperatures[0]; cout << "Enter the wind speed: "; cin >> windSpeeds[0]; cout << "Enter the wind direction: "; cin >> windDirections[0]; numOfReadings++; if(numOfReadings > 4) numOfReadings = 4; break; case 3: //Print the current weather, if valid weather is entered. for(int i = 0; i < numOfReadings; i++) { cout << "*****" << name << "*****" << endl; cout << "Temperature: " << temperatures[i] << endl; cout << "Wind speed: " << windSpeeds[i] << endl; cout << "Wind direction: " << windDirections[i] << endl << endl; } if(numOfReadings == 0) cout << "Please enter the details before asking to print." << endl; break; case 2: if(numOfReadings == 0) { cout << "Please enter the details before asking to print." << endl; break; } cout << "*****" << name << "*****" << endl; cout << "Temperature: " << temperatures[0] << endl; cout << "Wind speed: " << windSpeeds[0] << endl; cout << "Wind direction: " << windDirections[0] << endl << endl; break; case 4: return 0; //Stops execution. default: cout << "Invalid choice. Please follow the menu." << endl; } } }

Please tell me if this program is done correctly and if not make the appropriate corrections. Also, make sure that there are no bugs and that it still runs correctly when hard tested.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!