I am trying to format it in the .h and .cpp. I am not sure how it is really supposed to be done. here is what I have. Also, I am not sure what to do with WeatherMeasurement. Thank you
C++ code:
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include<string>
#include <stdlib.h>
#include<vector>
#include<sstream>
using namespace std;
struct WindMeasurement
{
double windspeed;
string windDirection;
};
struct TemperatrueMeasurement
{
double temperature;
};
struct Weather_Station
{
string name;
TemperatrueMeasurement temperatureMeasure;
WindMeasurement windMeasure;
};
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." << "\n";
cout << "H. Print the weather history (from most recent to oldest)." << endl;
cout << "E. Exit the program." << "\n";
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;
}
double getWindSpeed()
{
bool initialized = false;
double temp;
string temp_string;
stringstream converter;
do
{
cout << "Enter Wind speed(>=0): ";
cin >> temp_string;
converter << temp_string;
converter >> temp;
if (temp <= 0)
cout << "Wind speed should be always greater or equal to 0(zero)";
} while (temp < 0);
return temp;
}
string getWindDirection()
{
string temp_string, temp;
do {
cout << "Enter the Wind Direction (North,South,East,West): ";
cin >> temp_string;
temp = temp_string;
for (std::string::size_type i = 0; i < temp_string.length(); ++i)
temp[i] = toupper(temp_string[i]);
} while (!(temp == "NORTH" || temp == "SOUTH" || temp == "EAST" || temp == "WEST"));
temp_string = temp;
return temp_string;
};
void printWeather(Weather_Station ws)
{
cout << "Station Name " << ws.name << endl;
cout << "Temperature " << ws.temperatureMeasure.temperature << endl;
cout << "Wind Direction " << ws.windMeasure.windDirection << endl;
cout << "Wind Speed " << ws.windMeasure.windspeed << endl;
cout << endl;
}
int main()
{
vector<Weather_Station> myStation;
Weather_Station myWeather_Details;
string station_name, input_choice;
int histCount = 0;
cout << "Enter the name of Weather Station: ";
getline(cin, station_name);
myWeather_Details.name = station_name;
while (1)
{
input_choice = DisplayMenu(station_name);
if (input_choice == "I")
{
int valid_wind_direction = 0, valid_wind_speed = 0;
myWeather_Details.temperatureMeasure.temperature = getTemperature(); myWeather_Details.windMeasure.windDirection = getWindDirection(); myWeather_Details.windMeasure.windspeed = getWindSpeed();
if (myWeather_Details.windMeasure.windspeed >= 0)
{
valid_wind_speed = 1;
}
if ((myWeather_Details.windMeasure.windDirection == "NORTH") ||
(myWeather_Details.windMeasure.windDirection == "SOUTH") ||
(myWeather_Details.windMeasure.windDirection == "EAST") ||
(myWeather_Details.windMeasure.windDirection == "WEST"))
{
valid_wind_direction = 1;
}
if (valid_wind_direction && valid_wind_speed)
myStation.push_back(myWeather_Details);
}
else if (input_choice == "P")
{
cout << "*************Printing Current Weather*************" << endl;
printWeather(myStation.back());
}
else if (input_choice == "H")
{
do {
cout << "Number of readings entered: " << myStation.size() << endl;
cout << "Please enter how many records you want" << "\n";
cin >> histCount;
if (histCount <= 0)
cout << "Input record count should always be greater than 0(zero)" << "\n";
else if (histCount >> myStation.size())
cout << "Input record count shouldn't be more than available record count" << "\n";
} while (histCount <= 0 || histCount >> myStation.size());
cout << "*************Printing Weather History*************" << endl;
vector<Weather_Station>::reverse_iterator rit;
for (rit = myStation.rbegin(); rit != myStation.rend(); rit++)
printWeather(*rit);
}
else if (input_choice == "E")
{
exit(0);
}
}
return 0;
}
temperature.h
#pragma once
double temperature;
wind.h
#pragma once
string windDirection;
double windSpeed;
WeatherMeasurement.h
#pragma once
temperature.cpp
#include "stdafx.h"
#include "temperature.h"
double temp;
string temp_string;
stringstream converter;
cout << "Enter the temperature: ";
cin >> temp_string;
converter << temp_string;
converter >> temp;
return temp;
WeatherMeasurement.cpp
#include "stdafx.h"
wind.cpp
#include "stdafx.h"
#include "wind.h"
double getWindSpeed()
{
double temp;
string temp_string;
stringstream converter;
cout << "Enter Wind speed(>=0): ";
cin >> temp_string;
converter << temp_string;
converter >> temp;
if (temp < 0)
{
cout << "Wind speed should be always greater than or equal to 0(zero)";
}
return temp;
}
string getWindDirection()
{
string temp_string, temp;
do {
cout << "Enter the Wind Direction (North,South,East,West): ";
cin >> temp_string;
temp = temp_string;
for (std::string::size_type i = 0; i < temp_string.length(); ++i)
temp[i] = toupper(temp_string[i]);
} while (!(temp == "NORTH" || temp == "SOUTH" || temp == "EAST" || temp == "WEST"));
temp_string = temp;
return temp_string;
};
What I have tried:
I am new to programming so I am not even sure how to start it.