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
#include
using namespace std;
int main()
{
string name;
int choice;
double temperature, windSpeed;
string windDirection;
bool initialized = false;
//Have teh 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 << "1. Input a complete weather reading." << " ";
cout << "2. Print the current weather." << " ";
cout << "3. Exit the program." << " ";
cout << "Enter your choice: ";
cin >> choice;
//switch based on choice
switch(choice)
{
case 1:
do
{
cout << "Enter the temperature (a value >= 0): ";
cin >> temperature;
}while(temperature < 0);
//get correct wind speed
do
{
cout << "Enter the wind speed (a value >= 0): ";
cin >> windSpeed;
}while(windSpeed < 0);
//get correct wind direction
do
{
cout << "Enter the wind direction (North, South, East or West): ";
cin >> windDirection;
}while(windDirection != "North" && windDirection != "South"
&& windDirection != "East" && windDirection != "West");
initialized = true;
if(initialized)
{
cout << "*****" << name << "******" << endl;
cout << "Temperature: " << temperature << endl;
cout << "Wind Speed: " << windSpeed << endl;
cout << "Wind Direction: " << windDirection << endl;
}
break;
case 2:
if(!initialized)
{
cout << "Please enter the details before asking to print." << endl;
}
else
{
cout << "*****" << name << "******" << endl;
cout << "Temperature: " << temperature << endl;
cout << "Wind Speed: " << windSpeed << endl;
cout << "Wind Direction: " << windDirection << endl;
}
break;
case 3:
return 0; //stop execution
default:
cout << "Invalid choice. Please follow the menu." << endl;
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
