Project 5 Extend the functionality of project 4 to - incorporate a history of th
ID: 3589217 • Letter: P
Question
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 <iostream>
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.
Explanation / Answer
Program is done correctly ans tested with the giving inputs and working fine for all the inputs
Please check the below ouput:
Enter the name of weather station: anand 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 1 Enter the temperature: 25 Enter the wind speed: 63 Enter the wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 2 *****anand***** Temperature: 25 Wind speed: 63 Wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 1 Enter the temperature: 65 Enter the wind speed: 85 Enter the wind direction: north 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 2 *****anand***** Temperature: 65 Wind speed: 85 Wind direction: north 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 3 *****anand***** Temperature: 65 Wind speed: 85 Wind direction: north *****anand***** Temperature: 25 Wind speed: 63 Wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 1 Enter the temperature: 85 Enter the wind speed: 65 Enter the wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 1 Enter the temperature: 45 Enter the wind speed: 65 Enter the wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 2 *****anand***** Temperature: 45 Wind speed: 65 Wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 3 *****anand***** Temperature: 45 Wind speed: 65 Wind direction: east *****anand***** Temperature: 85 Wind speed: 65 Wind direction: east *****anand***** Temperature: 65 Wind speed: 85 Wind direction: north *****anand***** Temperature: 25 Wind speed: 63 Wind direction: east 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 1 Enter the temperature: 111 Enter the wind speed: 111 Enter the wind direction: north 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 2 *****anand***** Temperature: 111 Wind speed: 111 Wind direction: north 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 3 *****anand***** Temperature: 111 Wind speed: 111 Wind direction: north *****anand***** Temperature: 45 Wind speed: 65 Wind direction: east *****anand***** Temperature: 85 Wind speed: 65 Wind direction: east *****anand***** Temperature: 65 Wind speed: 85 Wind direction: north 1. Input a complete weather reading. 2. Print the current weather. 3. Print the weather history (from most recent to oldest). 4. Exit the program. Enter your choice: 4
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.