Statistician Solution

Objectives
You will implement and test a small class called Statistician. The objectives of this programming project are as follows.
• Ensure that you can write a small class that meets precise specifications.
• Make sure you understand how to write a class that is separated into a header file and an implementation file.
• Give you experience in using a test program to track down bugs in a class' implementation.
Problem Description
In this programming project, you will implement a new class called Statistician, using a header file (most of which is written for you) and an implementation file (which you will write by yourself). You are to write the following files:
1. Statistician.h: The header file for the new Statistician class. Actually, you don't have to write much of this file. Just start with the given Statistician.h file (available on Blackboard) and add your name and other information at the top, and then fill in the necessary information. If some of your member functions are implemented as inline functions, then you may put those implementations in this file too.
2. Statistician.cpp: The implementation file for the new statistician class. You will write all of this file, which will have the implementations of all the Statistician's member functions.
The Statistician is a class that is designed to keep track of simple statistics about a sequence of integer numbers. There are two member functions that you should understand at an informal level before you proceed any further. The prototypes for these two functions are shown here as part of the statistician class declaration:
class Statistician
{
public:
...
void next(int r);
double mean( ) const;
...
};
The member function "next" is used to give a sequence of integer numbers to the Statistician one at a time. The member function "mean" is a constant member function that returns the arithmetic mean (i.e., the average) of all the integer numbers that have been given to the Statistician. Note that even though all the numbers given are integers, the arithmetic mean may be a floating point number. The following example illustrates the working of these two functions.
Example: Suppose that you want a Statistician to compute the mean of the sequence 1, 8, -3, 5, then you could write these statements:
// Declares a Statistician object called s
Statistician s;

// Give the three numbers 1, 8, -3, and 5 to the statistician
s.next(1);
s.next(8);
s.next(-3);
s.next(5);

// Call the mean function, and print the result followed by a return
cout << s.mean( ) << endl;
The output statement will print 2.75, since 2.75 is the mean of the three numbers 1, 8, -3, and 5.
Once you understand the workings of the next and mean member functions, you can look at the complete specification of the Statistician class, which is in the file Statistician.h. In this file you will find a precondition/postcondition contract for all the Statistician's member functions, including:
• A default constructor, which merely does any initialization needed for the statistician to start its work.
• The next and mean functions, described above.
• A constant member function called getLength, which returns the count of how many integer numbers have been given to the Statistician.
• Two constant member functions called getMin and getMax, which return the minimum and maximum numbers that have been given to the Statistician.
• A constant member function called getSum, which returns the sum of all the integer numbers that have been given to the Statistician. (By the way, the getMin, getMax, getSum, and mean functions all have a precondition that requires length 0. You cannot use these four member functions unless the Statistician has been given at least one number!)
• An overloaded operator == which tests to see whether two Statisticians are "equal". This is a member function of the Statistician class. The prototype is:
booloperator==(const Statistician& sRight) const;
In order for two Statisticians to be equal, they must have the same length (i.e., they have been given the same number of integer numbers). Also, if their length is greater than zero, they must also have the same sum (which implies that they have the same mean), the same minimum, and the same maximum. For example: Suppose that a Statistician s has been given four numbers 1, 2, 3, 4. A second
Powered by