CSCI 201 Fall 2000

Assignment 5

Description:

In this assignment, you are asked to write just one program. In this program, you are asked to define and implement a class and then write a program that uses that class.

Program 1:

(worth 25 points)

Write a class that records the highest and lowest temperatures that it has received as input.

  1. The class should be called MinMaxTemp.
  2. The class should have a single constructor which takes a single float as its argument. This argument represents the first temperature observation.
  3. The class should have a single mutator function AddNewTemp which also takes a single float, representing a new temperature observation, as its argument. A mutator function is a function that can change the values of the private member variables.
  4. The class has two inspector functions, MinTemp and MaxTemp, which return respectively the minimum and maximum observed temperatures. Inspector functions can't change the values of the private member variables, they simply display or return the values of these variables.

Write a driver program which tests your class. The driver program should open the file temp.txt which contains one floating point number on each line; these numbers are temperatures. After opening the file, the driver program should read the temperatures and use the MinMaxTemp class to discover both the smallest and largest temperture in the file. Before terminating, your driver program should print the smallest and largest temperatures to the monitor. A sample input file is provided; the smallest value in this file is -40 and the largest is 212.

In your solution you should create three files

  1. MinMaxTemp.h, which gives the interface to the MinMaxTemp class (also called the definition of the class),
  2. MinMaxTemp.cpp, which gives the implementation of the class, and
  3. Driver.cpp, which contains your driver program and consequently the main routine.

What to turn in:

The programs written for this assignment must be turned in by transferring the C++ source code files to your ftp directory for this class. Only the files MinMaxTemp.h, MinMaxTemp.cpp and Driver.cpp should be turned in. You were shown how to transfer files to your class ftp directory in lab01, here is a quick repeat.