Question: Create a header file for a class called Statistician Create a default constructor Statistician ( ) Create the next function void next ( double num

Create a header file for a class called Statistician
Create a default constructor Statistician()
Create the next function
void next(double num)
Include the + operator as a binary operator so that it combines two Statistician objects.
Statistician operator +(const Statistician& s1, const Statistician& s2);
Create getters for the variables:
average
total
num_items
maximum
minimum
Create the following double private variables:
average: represents the average of all of the numbers passed in through the next() function
total: represents the total of all the numbers passed in through the next() function
maximum: represents the largest of all of the numbers passed in through the next() function
minimum: represents the smallest of all of the numbers passed in through the next() function
Create an int private variable called num_items represents the total number of nums passed in through the next function. This is a counter.
Create the implementation file (.cpp file) for the Statistician
The default constructor Statistician() should assign zeros to total, average and num_items.
Code for the plus operator should:
add the totals together, add the num_items, recompute the average, compare the two maximums and assign the larger of the two to the resulting Statistician and similar process for minimum.
Code for the next function
Should add 1 to the num_items
initialize maximum and minimum to the num passed in if num_items is equal to 1. Otherwise, if num is bigger than maximum then maximum should be assigned num. If num is smaller than minimum, then minimum should be assigned the value of num.
Add num to the total
Update the average. Note average = total / num_items
Create a driver file (.cpp file with main()), that creates a default Statistician object, s1.
Call the next() function on the object with the following values: 2,8.5,3,0,10
Sample usage:
obj.next(2);
obj.next(8.5);
Repeat for each of numbers in the list. This function feeds the numbers to your Statistician object. Each call to the function updates all of the variables in the object.
Use the getters to display all of the variables in the object (there are 5 variables), in the following format:
:=
Example: Information for num_items would print as...
num_items :=5
How do I know it is correct?
Your output should look like:
Console showing 5 for num_items, 23.5 for total, 4.7 for average, 10 for maximum and 0 for minimum.
Expected output values for each variable
Variable Value
num_items 5
total 23.5
average 4.7
maximum 10
minimum 0
Now, create a second Statistician object s2 and call the next() function to insert 1,2, and 3
s2.next(1);
s2.next(2);
s2.next(3);
Then add the first Statistician object to s2 and save the result in the third Statistician object.
Statistician s3= s1+ s2;
Display all of the values for Statistician s3. These are the values you should see:
Total: 29.5
num_items: 8
maximum: 10
average: 3.6875
minimum: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!