1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//Date class
class Weather
{
private:
string name;
int temperature;
int dewPoint;
string winds;
float pressure;
string weather;
public:
void setWeather(string, int, int, string, float, string);
void weatherFormat();
Weather(string, int, int, string, float, string);
};
//Default constructor
Weather::Weather(string n, int t, int dP, string wi, float p, string we)
{
name = n;
dewPoint = dP;
winds = wi;
pressure = p;
weather = we;
}
//Function to set the weather variables
void Weather::setWeather(string n, int t, int dP, string wi, float p, string we)
{
name = n;
dewPoint = dP;
winds = wi;
pressure = p;
weather = we;
}
//Function to print weather data
void Weather::weatherFormat()
{
string name;
int temperature;
int dewPoint;
string winds;
float pressure;
string weather;
cout << "At ";
cout << name << ", the temperature is ";
cout << temperature << " degrees Fahrenheit, the dew point is ";
cout << dewPoint << "degrees Fahrenheit, winds are from the";
cout << winds << " , pressure is ";
cout << pressure << " inches of mercury, and it is ";
cout << weather;
cout << endl << endl;
}
//Main program
main()
{
const int size = 25;
string name;
int temperature;
int dewPoint;
string winds;
float pressure;
string weather;
int i = 0;
Weather inputWeather();
fstream inputFile;
inputFile.open("c:\\weatherObs.txt");
for (i = 0; i < size; i++)
{
inputFile >> setWeather[i].name;
inputFile >> setWeather[i].temperature;
inputFile >> setWeather[i].dewPoint;
inputFile >> setWeather[i].winds;
inputFile >> setWeather[i].pressure;
inputFile >> setWeather[i].weather;
}
inputWeather.setWeather(name, temperature, dewPoint, winds, pressure, weather);
inputWeather.weatherFormat();
cout << endl;
cout << "\nNormal job termination\n" << endl;
system("pause");
return 0;
}
|