For this assignment, you are to use a class to describe a the weather in a city. Use the definition given below:
class city_weather
{
public:
city_weather
( ); // Constructor
void read_city_weather
(ifstream &); // Read data for a single city from the file.
void display_city_weather
( ); // Display all the data about a single city on the screen.
int get_high_temp
( ); // Return the high temperature for the city.
string get_city_name
(); // Return the name of the city.
private:
int high,
low;
string name;
};
This class contains the data and functions to describe
the weather for a single city. Create a file such as the following:
New York, 45 36
Use this file to test out the following class. Fill in the code for the functions that have not been defined.
city_weather :: city_weather ( )
{
high = 0;
low = 0;
name = "";
} // city_weather :: city_weather ( )
void city_weather :: read_city_weather (ifstream &
weather)
{
char ch;
getline (weather, name, ',');
weather >> high >> low;
weather.get (ch);
} // void city_weather :: read_city_weather (ifstream
& weather)
void city_weather :: display_city_weather ( )
{
// Display all the data for the weather
of the city.
} // void city_weather :: display_city_weather ( )
int city_weather :: get_high_temp ()
{
// Return the high temperature for
the city.
} // int city_weather :: get_high_temp ()
string city_weather :: get_city_name ()
{
// Return the name of the city.
} // string city_weather :: get_city_name ()
int main ( )
{
city_weather one_city;
string name;
int high;
ifstream weather;
city_weather_file.open ("weather.txt");
if (weather.fail ( ))
{
cerr <<
"File not found" << endl;
return 1;
}
one_city.read_city_weather (weather);
weather.close ( );
one_city.display_city_weather ();
name = one_city.get_city_name ();
high = one_city.get_high_temp ();
cout << "The high temperature
for " << name << " is " << high << endl;
return 0;
}