Question: Need help with this problem. the problem asks for an implementation file called ( stats.cpp ) for the file stats.h which is already given. I

Need help with this problem. the problem asks for an implementation file called (stats.cpp) for the file stats.h which is already given. I am posting the question along with the precode file stats.h. Just help me with the implementation file (stats.cpp) for the file stats.h. The implementation description is given in the problem. thanks in advance

Need help with this problem. the problem asks for an implementation filecalled (stats.cpp) for the file stats.h which is already given. I amposting the question along with the precode file stats.h. Just help me

with the implementation file (stats.cpp) for the file stats.h. The implementation descriptionis given in the problem. thanks in advance #ifndef STATS_H // Prevent

#ifndef STATS_H // Prevent duplicate definition

#define STATS_H

#include

namespace CISP430_A1

{

class statistician

{

public:

// CONSTRUCTOR

statistician( );

// MODIFICATION MEMBER FUNCTIONS

void next(double r);

void reset( );

// CONSTANT MEMBER FUNCTIONS

int length( ) const { return count; }

double sum( ) const { return total; }

double mean( ) const;

double minimum( ) const;

double maximum( ) const;

// FRIEND FUNCTIONS

friend statistician operator +

(const statistician& s1, const statistician& s2);

friend statistician operator *

(double scale, const statistician& s);

private:

int count; // How many numbers in the sequence

double total; // The sum of all the numbers in the sequence

double tiniest; // The smallest number in the sequence

double largest; // The largest number in the sequence

};

// NON-MEMBER functions for the statistician class

bool operator ==(const statistician& s1, const statistician& s2);

}

You will create, implement and test a small class called statistician, which is similar to some of the small classes in Chapter 2 of the text. The new class is called statistician, using a header file, stats.h (attached).(most of which is written for you) and an implementation file, stats.cpp (which you need to create and implement.). The statistician is a class that is designed to keep track of simple statistics about a sequence of real 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 (double r); double mean const; }; The member function "next" is used to give a sequence of 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 numbers that have been given to the statistician. Example: Suppose that you want a statistician to compute the mean of the sequence 1.1, 2.8,-0.9. Then you could write these statements: // Declares a statistician object called s statistician si // Give the three numbers 1.1, 2.8 and -0.9 to the statistician S.next(1.1); S.next.(2.8); s.next(-0.9); // Call the mean function, and print the result followed by a carriage return cout 0. You cannot use these three member functions unless the statistician has been given at least one number!) A constant member function called sum, which returns the sum of all the numbers that have been given to the statistician. This function does NOT have a precondition. It may be called even if the statistician has NO numbers (in which case it should return 0). An overloaded operator == which tests to see whether two statisticians are "equal". The prototype is: bool operator ==(const statistician& s, const statistician& t); In order for two statisticians to be equal, they must have the same length (i.e., they have been given the same number of numbers). Also, if their length is greater than zero, they must also have the same mean, the same minimum, the same maximum, and the same sum. For example: Suppose that a statistician s has been given four numbers 1, 2, 3, 4. A second statistician t has been given four numbers 1, 1.5, 3.5, 4. Then the test (s==t) must return true since both s and t have equal values for all the member functions, as shown here: s.length() and t.length() are both 4 s.mean() and t.mean(are both 2.5 s.sum() and t.sum() are both 10.0 s.minimum and t.minimum are both 1 s.maximum and t.maximum are both 4 An overloaded + operator which has two statisticians as arguments, and returns a third statistician, as shown in this prototype: statistician operator +(const statisticiana s, const statistician& t); An overloaded * operator which allows you to "multiply" a double number times a statistician. Here is the prototype: 1. 2. 3. 4. 5. . the statistician t has been given the numbers 4, 5. Then the assignment statement u=s+t will result in u behaving as if it had been given the five numbers 1, 2, 3, 4, 5. n stats.h) No Selection 66 68 69 73 74 76 58 #ifndef STATS_H // Prevent duplicate definition 59 #define STATS_H 60 #include 61 62 namespace CISP430_A1 63 { 64 class statistician 65 { public: 67 // CONSTRUCTOR statistician(); // MODIFICATION MEMBER FUNCTIONS 70 void next(double r); 71 void reset(); 72 // CONSTANT MEMBER FUNCTIONS int length() const { return count; } double sum() const { return total; } 75 double mean() const; double minimum( ) const; 77 double maximum() const; 78 // FRIEND FUNCTIONS 79 friend statistician operator + (const statistician& si, const statistician& s2); 81 friend statistician operator * (double scale, const statistician& s); private: int count; // How many numbers in the sequence 85 double total; // The sum of all the numbers in the sequence double tiniest; // The smallest number in the sequence double largest; // The largest number in the sequence 88 }; 89 // NON-MEMBER functions for the statistician class bool operator ==(const statistician& si, const statistician& s2); 92 } 93 94 #endif 95 8mmagww 80 82 83 84 86 90 91

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 Databases Questions!