Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 // Provided by: (your name here) Go Back Email Address: (your email address here) 3 // FILE: stats.h 4 // CLASS PROVIDED: statistician 5

image text in transcribedimage text in transcribed

1 // Provided by: (your name here) Go Back Email Address: (your email address here) 3 // FILE: stats.h 4 // CLASS PROVIDED: statistician 5 (a class to keep track of statistics on a sequence of real numbers) 6 This class is part of the namespace main_savitch_2c. 7 // 8 // CONSTRUCTOR for the statistician class: statistician(); 10 // Postcondition: The object has been initialized, and is ready to accept 11 // a sequence of numbers. Various statistics will be calculated about the 12 // sequence. 13 // 14 // PUBLIC MODIFICATION member functions for the statistician class: 15 // void next(double r) 16 // The number r has been given to the statistician as the next number in 17 its sequence of numbers. 18 // void reset(); 19 Postcondition: The statistician has been cleared, as if no numbers had 20 // yet been given to it. 21 // 22 // PUBLIC CONSTANT member functions for the statistician class: 23 // int length() const 24 // Postcondition: The return value is the length of the sequence that has 25 // been given to the statistician (i.e., the number of times that the 26 // next(r) function has been activated). 27 // double sum( ) const 28 // Postcondition: The return value is the sum of all the numbers in the 29 // statistician's sequence. 30 double mean() const 31 Precondition: length() > 32 Postcondition: The return value is the arithmetic mean (i.e., the 33 // average of all the numbers in the statistician's sequence). 34 // double minimum( ) const 35 // Precondition: length() > 0 36 // Postcondition: The return value is the tinyest number in the 37 // statistician's sequence. 38 // double maximum( ) const 39 // Precondition: length() > 0 40 // Postcondition: The return value is the largest number in the 41 // statistician's sequence. 42 // 43 // NON-MEMBER functions for the statistician class: 44 statistician operator +(const statistician& si, const statistician& s2) 45 // Postcondition: The statistician that is returned contains all the 46 // numbers of the sequences of s1 and s2. 47 statistician operator *(double scale, const statistician& s) 48 // Postcondition: The statistician that is returned contains the same 49 // numbers that s does, but each number has been multiplied by the 50 // scale number. 51 bool operator ==(const statistician& si, const statistician& s2) 52 // Postcondition: The return value is true if s1 and s2 have the zero 53 // length. Also, if the length is greater than zero, then si and s2 must 54 // have the same length, the same mean, the same minimum, 55 // the same maximum, and the same sum. 56 // 57 // VALUE SEMANTICS for the statistician class: 58 // Assignments and the copy constructor may be used with statistician objects. 59 69 70 75 76 60 #ifndef STATS_H // Prevent duplicate definition 61 #define STATS_H 62 #include 63 -64 namespace main_savitch_2C 65 { class statistician 67 { 68 public: // CONSTRUCTOR statistician(); 71 // MODIFICATION MEMBER FUNCTIONS 72 void next(double r); 73 void reset(); 74 // CONSTANT MEMBER FUNCTIONS int length() const; double sum() const; 77 double mean() const; 78 double minimum const; double maximum( ) const; // FRIEND FUNCTIONS friend statistician operator + 82 (const statistician& si, const statistician& s2); friend statistician operator * (double scale, const statistician& s); private: int count; // How many numbers in the sequence 87 double total; // The sum of all the numbers in the sequence 88 double tinyest; // The smallest number in the sequence double largest; // The largest number in the sequence }; 91 92 // NON-MEMBER functions for the statistician class 93 bool operator ==(const statistician& si, const statistician& s2); 94 } 95 96 #endif 89 90 97

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago

Question

=+and reduction in force, and intellectual property.

Answered: 1 week ago