Computer Science 121
Assignment 9
Due: April 28, 1999

For this assignment, you are to fill in the code for three functions that are called by the main function. They are given below. They use some of the definitions and functions that you typed in for assignment 8. Store the following data in your file.

New York, 45 36
Washington DC, 55 41
Albany, 42 34
Boston, 35 28
Jersey City, 49 41

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

class city_weather
{
    public:
        city_weather ( ); // Constructor
        void read_city_weather (ifstream &); // Read data from the file into the three arrays.
        void display_city_weather ( ); // Display all the data about the cities on the screen.
        int get_highest_temp ( ); // Return the highest high temperature in the array, high [].
        string get_city_name (); // Return the name of the city with the highest high temperature..
    private:
        int high [5] ;
        int low [5] ;
        string name [5] ;
        int no_cities;
};  // class city_weather

city_weather :: city_weather ( )
{
    no_cities = 0;
} // city_weather :: city_weather ( )

void city_weather :: read_city_weather (ifstream & weather)
{
    char ch;
    int count = 0;
    string city_name;
    getline (weather, city_name, ',');
    while (!weather.eof ())
    {
        name [count] = city_name;
        weather >> high [count] >> low [count];
        weather.get (ch);
        count ++;
        getline (weather, city_name, ',');
    }
    no_citites = count;
} // void city_weather :: read_city_weather (ifstream & weather)

void city_weather :: display_city_weather ( )
{
    // Display all the data in the arrays.
} // void city_weather :: display_city_weather ( )

int city_weather :: get_highest_temp ()
{
    // Find and return the highest of the high temperatures.
} // int city_weather :: get_highest_temp ()

string city_weather :: get_city_name ()
{
    // Return the name of the city with the highest high temperature.
} // string city_weather :: get_city_name ()

int main ( )
{
    city_weather cities;
    string name;
    int high;
    ifstream weather;
    weather.open ("weather.txt");
    if (weather.fail ( ))
    {
        cerr << "File not found" << endl;
        return 1;
    }
    cities.read_city_weather (weather);
    weather.close ( );
    cities.display_city_weather ();
    name = cities.get_city_name ();
    high = cities.get_highest_temp ();
    cout << "The highest high temperature was " << high << endl;
    cout << "The highest high temperature was in " << name << endl;
    return 0;
} // int main ()