Question: Hello, this is my weather station program in C++ C++ code: #include stdafx.h #include #include using namespace std; void moveTemperaturesToRight(double temperatures[], double windSpeed[], string windDirection[])

Hello, this is my weather station program in C++

C++ code:

#include "stdafx.h"

#include

#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;

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

{

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." << " ";

}

}

}

Here is a code outline of this program with functions. Please follow this outline and keep every functionality of this program the exact same. The users actions have to be encapsulated in functions. This is important. Thank you

Outline:

#include #include

#include

#include

using namespace std;

struct Weather_Station

{

string name;

double temperature;

double windspeed;

string windDirection;

};

string DisplayMenu(string station_name)

{

string str, temp;

do

{

cout << "*******************WEATHER STATION: " << station_name << " *******************"<< endl << endl;

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

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

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

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

cout << "Enter your choice: " << endl;

cin >> str;

temp = str;

for (std::string::size_type i = 0; i < str.length(); ++i)

temp[i] = toupper(str[i]);

str = temp;

} while (!(str == "I" || str == "P" || str == "H" || str == "E"));

return str;

}

double getTemperature()

{

double temp;

string temp_string;

stringstream converter;

cout << "Enter the temperature: ";

cin >> temp_string;

converter << temp_string;

converter >> temp;

return temp;

};

int main()

{

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

vector myStation;

Weather_Station myWeather_Details;

string station_name, input_choice;

cout << "Enter the name of Weather Station: ";

getline(cin, station_name);

myWeather_Details.name = station_name;

//Control loop to perform various actions

input_choice = DisplayMenu(station_name);

if (input_choice == "I")

{

// get the details

myWeather_Details.temperature= getTemperature(); // get temperature

// TODO implement windspeed and wind direction functions

}

//store the details

myStation.push_back(myWeather_Details);

return 0;

}

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!