Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello Programmers ! Can anyone help me with this project please? I attached all the details for requirements and also attached a header file created

Hello Programmers ! Can anyone help me with this project please? I attached all the details for requirements and also attached a header file created ny me... u can add more variables if needed. A class with a header file "stats.h", implementation file "stats.cxx" and executable file "stattest.cxx". Need it by next Wednesday. I put more details now, if you still need additional information, please don't hesitate to inform me. TIA.

1. Class name will be STATISTICIAN.

2. Three files name will be stats.h, stats.cxx for implementation and stattest.cxx will be executable file name.

3. use the namespace "namespace main_savitch_2C.

4. a Default constructor, which merely does any initialization needed for the statistician to start its work.

5. a void next (double r) member function to give sequence of numbers to the statistician one at a time.

6. a void reset () member function. post condition- the statistician has been cleared, as if no numbers had been given to it.

7. a int length() const, member function to return the value of the length of the sequence that has been given to the statistician. (I.e, number of the times that next(r) function has been activated.

8. a double sum() const member function which will return the sum of the all numbers in the statistician's sequence.

9. a double mean()const member function which will return the average of all numbers in the statistician's sequence. pre-condition, length()>0.

10. a double minimum() const member function which will return the smallest number in statistician's sequence. pre-condition, length()>0.

11. a double maximum() const member function which will return the largest number in the statistician's sequence. pre-condition, length()>0.

12. a int abs_minimum() const, member function which will return smallest absolute value in the statistician's sequence. pre-condition, length()>0.

13. a int abs_maximum() const, member function which will return largest absolute value in the statistician's sequence. pre-condition, length()>0.

14. a "friend statistician operator+ (const statistician & s1, const statistician & s2)" function which will return contains all the numbers of the sequences of s1 and s2.

15. a " friend statistician operator * ( double scale, const statistician & s)" function which will return containing the same numbers that S does, but each number has been multiplied by the scale number.

16. a " bool operator == ( const statistician & s1 , const statistician & s2) non-member function which will return true if s1 and s2 have the zero length. also if the length is greater than zero , then s1 and s2 must have the same length , the same mean, the same minimum, the same maximum, and the same sum.

// assignments and the copy constructor may be used with statistician objects.

image text in transcribed

image text in transcribed

image text in transcribed

Two more constant member functions called abs minimum and abs maximum, which return the numbers with the smallest and largest absolute values. (By the way, these two functions, the minimum maximum functions, the recent function and the mean function all have and a precondition that requires ength()>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 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 has two statistidians as arguments, and returns a third statistician, as shown in this prototype: . statistician operator +(const statisticians s, const statisticiant t) a An overloaded *operator which allows you to "multiply a double number times a statistician. Here is the prototype: . statistician operator (double scale, const statistician&s) This is not a member function. The result of a multiplication such as 2*s is a new statistidan that looks as if it had been glven all the numbers of s, multiplied by the constant 2. Examples: Suppose that s is a statistidian that has been given 1,2, 3, and u is another statistician. Then the assignment statement u2ts will result in u behaving as if it had been given the numbers 2,4,6. As another example, the assignment statement un3*s will result in u behaving as if it had been given the numbers-3, 6, -9. Notice that neither + nor are member functions. (See Section 2.5 in the textbook). The result of s+t is a new statistician that looks as if it had been given all the numbers of the sequence for s, followed by all the numbers of the sequence for t. For example: Suppose that we have three statisticians s, t, and u. The statistician s has been given the numbers 1, 2, 3; the statistician t has been given the numbers 4, 5. Then the assignment statement uss t will result in u behaving as if it had been given the five numbers 1, 2,3,4,5 Hints and Frequently Asked Questions The Private Member Variables Carefully read the class definition in stats.h. Notice how the private member variables are being used to keep track of information about the statistician's sequence of numbers. The statistician does NOT keep track of all the numbers in the sequence. There is no need to do so, and trying to do so can get you into trouble. Instead, it keeps track of only the information that is relevant to its member functions: How many numbers have been seen? What is the most recent number you have seen? What is the sum of those numbers? If you have seen at least one number, then what are the smallest and largest numbers that you've seen so far? What are the largest and smallest absolute values you have seen so far? These items should be your only private member variables. Be careful about how you set the private member variable that keeps track of the smallest number. My suggestion is that you do NOT have the constructor initialize this member variables (because when the constructor does its work, there have not yet been amy numbers, so there is no smallest number). But part of the work of the "next function is to correctly maintain the private member variables. This means that the first time that the next function is called, it should set the private member variable that keeps track of smallest values, Later, if next is called again with a smaller number, then the next function will change the member variable that is keeping track of the smallest value. (You'll have a similar process for the member variable that's keeping track of the largest value) Check Boundary Values ifndef STATS-"- 9 adefine STATS H includeciostrean 11e nanespace main_savitch 2c 3 class statistician statistician); void next (double r) void reset() int length )const return count; double sum)const return total; double recent )const double mean()const double minimu )const double maximum )const; int abs minimum)const; int abs maximum()const friend statistician operator (const statisticians si, const statistician& $2) friend statistician operator (double scale, const statisticians s) Sprivate: int counts 1/ how many numbers in the sequence double total; the sun of all umbers in the sequence double tinsest; the smellest number in the sequence. I double largest; / the largest number in the sequence. Non menber function for statistician class bool operator.(const statisticians si, const statistician8 s2) 49 nendifSTATSH Writable Smart Insert38:65 ne FILE: stats.h CLASS PROVIDED: statistician // (a class to keep track of statistic on a sequence of real numbers) / This elass is part of the nanespace main savitch 2c. CONSTRUCTOR for the statistician class statisticlant Post.conditions The object has been initialized, and is ready to accept a sequence of nunbers. Various statiatics will be calculated about the sequence // PUBLIC-001 FCATOI-nter tunctions for the atatiatici an class: void nexttdouble t The number E has been given to the statiatician as the next number in ita sequence of numbers / vold resett Poatconditiont The statistician has been cleared, as if no numbers had yet been given to it. PUBLIC CONSTANT menber functions tor the atatistician elaas: 1 int length) const Postoonditions The return value is the length of the sequence that has been given t the statisti elan (1,e., the hunt er of times that the nexttal funetlon has been activated). double sum! 1 conat Poatcondition: The return value ls the sum of all the nunbers in the tatiatician's sequence. /1 double meant conat Preconditions lengtht 1 >o Postcondition: The ceturn value is the arithmetic nean .e, the average of all the numbers in the statiatielan'a sequence). double minimunl 1 eonst Precondition! length ] > O Post oondition: The return value ia the tiniest number in the statiatician's sequence Precondition: lengtht Y0 Postcondition: The return value is the largest number in the statistician's sequence NON-MEMBER Eunctiona tor the atatiatiel an class 1 statiatician operator foonst atatiatielans a1. conat a tson: The statistieian that is retuened containa all the nubers of the sequences of al and a2. a cale, oonst statistielans that a does, but each nunber has been multiplied by the ator -tLoonst statiaticians a1.const statiatleians s2 operator Idouble a Post oonditions The atatiatiian that is returned contains the sae acale /1 bool operstor-Ioonst tions The ceturn value is trve it al and 2 have the zero i-ngth. Also, if the length 1" greater than zero, then s1 and s2 suat have the sase length, the oane nean, the same minimum. the sane maximun, and the sane aun VALUE SEMANTICs t 1 Aasigomenta and the copy eonstruetor ay be used with atatiatician objeeta for the statistician elass Two more constant member functions called abs minimum and abs maximum, which return the numbers with the smallest and largest absolute values. (By the way, these two functions, the minimum maximum functions, the recent function and the mean function all have and a precondition that requires ength()>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 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 has two statistidians as arguments, and returns a third statistician, as shown in this prototype: . statistician operator +(const statisticians s, const statisticiant t) a An overloaded *operator which allows you to "multiply a double number times a statistician. Here is the prototype: . statistician operator (double scale, const statistician&s) This is not a member function. The result of a multiplication such as 2*s is a new statistidan that looks as if it had been glven all the numbers of s, multiplied by the constant 2. Examples: Suppose that s is a statistidian that has been given 1,2, 3, and u is another statistician. Then the assignment statement u2ts will result in u behaving as if it had been given the numbers 2,4,6. As another example, the assignment statement un3*s will result in u behaving as if it had been given the numbers-3, 6, -9. Notice that neither + nor are member functions. (See Section 2.5 in the textbook). The result of s+t is a new statistician that looks as if it had been given all the numbers of the sequence for s, followed by all the numbers of the sequence for t. For example: Suppose that we have three statisticians s, t, and u. The statistician s has been given the numbers 1, 2, 3; the statistician t has been given the numbers 4, 5. Then the assignment statement uss t will result in u behaving as if it had been given the five numbers 1, 2,3,4,5 Hints and Frequently Asked Questions The Private Member Variables Carefully read the class definition in stats.h. Notice how the private member variables are being used to keep track of information about the statistician's sequence of numbers. The statistician does NOT keep track of all the numbers in the sequence. There is no need to do so, and trying to do so can get you into trouble. Instead, it keeps track of only the information that is relevant to its member functions: How many numbers have been seen? What is the most recent number you have seen? What is the sum of those numbers? If you have seen at least one number, then what are the smallest and largest numbers that you've seen so far? What are the largest and smallest absolute values you have seen so far? These items should be your only private member variables. Be careful about how you set the private member variable that keeps track of the smallest number. My suggestion is that you do NOT have the constructor initialize this member variables (because when the constructor does its work, there have not yet been amy numbers, so there is no smallest number). But part of the work of the "next function is to correctly maintain the private member variables. This means that the first time that the next function is called, it should set the private member variable that keeps track of smallest values, Later, if next is called again with a smaller number, then the next function will change the member variable that is keeping track of the smallest value. (You'll have a similar process for the member variable that's keeping track of the largest value) Check Boundary Values ifndef STATS-"- 9 adefine STATS H includeciostrean 11e nanespace main_savitch 2c 3 class statistician statistician); void next (double r) void reset() int length )const return count; double sum)const return total; double recent )const double mean()const double minimu )const double maximum )const; int abs minimum)const; int abs maximum()const friend statistician operator (const statisticians si, const statistician& $2) friend statistician operator (double scale, const statisticians s) Sprivate: int counts 1/ how many numbers in the sequence double total; the sun of all umbers in the sequence double tinsest; the smellest number in the sequence. I double largest; / the largest number in the sequence. Non menber function for statistician class bool operator.(const statisticians si, const statistician8 s2) 49 nendifSTATSH Writable Smart Insert38:65 ne FILE: stats.h CLASS PROVIDED: statistician // (a class to keep track of statistic on a sequence of real numbers) / This elass is part of the nanespace main savitch 2c. CONSTRUCTOR for the statistician class statisticlant Post.conditions The object has been initialized, and is ready to accept a sequence of nunbers. Various statiatics will be calculated about the sequence // PUBLIC-001 FCATOI-nter tunctions for the atatiatici an class: void nexttdouble t The number E has been given to the statiatician as the next number in ita sequence of numbers / vold resett Poatconditiont The statistician has been cleared, as if no numbers had yet been given to it. PUBLIC CONSTANT menber functions tor the atatistician elaas: 1 int length) const Postoonditions The return value is the length of the sequence that has been given t the statisti elan (1,e., the hunt er of times that the nexttal funetlon has been activated). double sum! 1 conat Poatcondition: The return value ls the sum of all the nunbers in the tatiatician's sequence. /1 double meant conat Preconditions lengtht 1 >o Postcondition: The ceturn value is the arithmetic nean .e, the average of all the numbers in the statiatielan'a sequence). double minimunl 1 eonst Precondition! length ] > O Post oondition: The return value ia the tiniest number in the statiatician's sequence Precondition: lengtht Y0 Postcondition: The return value is the largest number in the statistician's sequence NON-MEMBER Eunctiona tor the atatiatiel an class 1 statiatician operator foonst atatiatielans a1. conat a tson: The statistieian that is retuened containa all the nubers of the sequences of al and a2. a cale, oonst statistielans that a does, but each nunber has been multiplied by the ator -tLoonst statiaticians a1.const statiatleians s2 operator Idouble a Post oonditions The atatiatiian that is returned contains the sae acale /1 bool operstor-Ioonst tions The ceturn value is trve it al and 2 have the zero i-ngth. Also, if the length 1" greater than zero, then s1 and s2 suat have the sase length, the oane nean, the same minimum. the sane maximun, and the sane aun VALUE SEMANTICs t 1 Aasigomenta and the copy eonstruetor ay be used with atatiatician objeeta for the statistician elass

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_2

Step: 3

blur-text-image_3

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions