Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is what the exercise says: create an implement a class called statistician.

ID: 3620103 • Letter: T

Question

This is what the exercise says:

create an implement a class called statistician. Initialized, it can be given a sequence of double numbers. (Note: do not use an array to hold the sequence of input data. You need only the data members - length, sum, mean (may not need as actual data member but you can calculate it easily), smallest number, largest number) You must be able to handle an empty statistician. (i.e. you cannot find the mean of no numbers)

you are to add the following to your statistician program.

Two constructor methods that initialize your statistician objects: one is the default and one to initialize a statistician with the value of another statistician. The second constructor is call a copy constructor. Ex "Statstician stat1;" declares an object as you normally do. The secont one "Statistician stat2(stat1);" declares stat2 and initializes stat2 to the values (data member values) in stat1. So if you print stat2 and stat1, both would have the same values.
The copy constructor would look like

statistician( statistician s ) //where 's' is the argument 'stat1' above.
{several assignments of the data members } An overloaded (<<) output mehtod using the "friend" attribute. The output should look something like the following where you print out of the data members with some labeling: sum = xxx len=xxx mean=xxx ... An overloaded(+) method as a function outside the class. An overloaded(==) and (!=) method. Add an 'erase' function member that resets a statistician object. Use the following input to test your program. Data for statistican1: 5.5, 6.6, 8.8, -3.4, -0.5, 4.7, 9.1 Print out: the sume, length, and average only for statician1(you'll need getter funcitons for these) add to statistician1: 5.2, -3.3, -8.5, 3.2, 5.5 Printout: statistician1 using the << operator. Data for statistican2: initialize statistican2 with the value of statistian1 on declaration of statistician2. Print out; statistician2 using the << operator. add to statistician2: 103, 821, 871, 487, 312, 245, 224, 623, 424, 432 Print out: the sum, length and average onlyh for statistician2 Print out: statistician1 & statistician2 using the << operator. Add: to add two statisticians together. The results shoud add the sums, the lengths, and determine which of the two are the largest and the smalles of the new statisticians from the two inputs. ex. statistician3 largest is the statistician 3 = statistician1 + statistian2; Print out: statistician1 & statistician2 & statistician 3 using the << operator. Erase statistician2 to its initial declareation by calling the function member 'erase'. Print out statistician1 & statistician2 & statistician3 using the << operator.
This is what the exercise says:

create an implement a class called statistician. Initialized, it can be given a sequence of double numbers. (Note: do not use an array to hold the sequence of input data. You need only the data members - length, sum, mean (may not need as actual data member but you can calculate it easily), smallest number, largest number) You must be able to handle an empty statistician. (i.e. you cannot find the mean of no numbers)

you are to add the following to your statistician program.

Two constructor methods that initialize your statistician objects: one is the default and one to initialize a statistician with the value of another statistician. The second constructor is call a copy constructor. Ex "Statstician stat1;" declares an object as you normally do. The secont one "Statistician stat2(stat1);" declares stat2 and initializes stat2 to the values (data member values) in stat1. So if you print stat2 and stat1, both would have the same values.
The copy constructor would look like

statistician( statistician s ) //where 's' is the argument 'stat1' above.
{several assignments of the data members } An overloaded (<<) output mehtod using the "friend" attribute. The output should look something like the following where you print out of the data members with some labeling: sum = xxx len=xxx mean=xxx ... An overloaded(+) method as a function outside the class. An overloaded(==) and (!=) method. Add an 'erase' function member that resets a statistician object. Use the following input to test your program. Data for statistican1: 5.5, 6.6, 8.8, -3.4, -0.5, 4.7, 9.1 Print out: the sume, length, and average only for statician1(you'll need getter funcitons for these) add to statistician1: 5.2, -3.3, -8.5, 3.2, 5.5 Printout: statistician1 using the << operator. Data for statistican2: initialize statistican2 with the value of statistian1 on declaration of statistician2. Print out; statistician2 using the << operator. add to statistician2: 103, 821, 871, 487, 312, 245, 224, 623, 424, 432 Print out: the sum, length and average onlyh for statistician2 Print out: statistician1 & statistician2 using the << operator. Add: to add two statisticians together. The results shoud add the sums, the lengths, and determine which of the two are the largest and the smalles of the new statisticians from the two inputs. ex. statistician3 largest is the statistician 3 = statistician1 + statistian2; Print out: statistician1 & statistician2 & statistician 3 using the << operator. Erase statistician2 to its initial declareation by calling the function member 'erase'. Print out statistician1 & statistician2 & statistician3 using the << operator.

Explanation / Answer

// statistian.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#ifndef STATS_H // Prevent duplicate definition

#define STATS_H

#include<iostream>

#include<iomanip>

using namespace std;

class statistician

{

public:

     // CONSTRUCTOR

     statistician( );

     // MODIFICATION MEMBER FUNCTIONS

     void next(double r);

    void reset( );

                    // CONSTANT MEMBER FUNCTIONS

     int length( ) const;

     double sum( ) const; 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);

    bool operator ==(const statistician& s1,

                          const statistician& s2);

    

private: int count;

// How many numbers in the sequence double total;

          // The sum of all the numbers in the sequence

          double tinyest;

          // The smallest number in the sequence

          double largest; // The largest number in the sequence

};

   bool operator ==

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

   #endif

double get_number();

char get_user_command();

void print_menu( );

/

double get_number( );

/

void print_values(const statistician& s);

int main( )

{

     statistician s1, s2, s3;

     // Three statisticians for us to play with

   // A command character entered by the user

     double x;

     char choice;

     // Value for multiplication x*s1

     cout << "Three statisticians s1, s2, and s3 are

            ready to test." << endl;

     do {

          cout << endl; print_menu( );

          choice = toupper(get_user_command( ));

          switch (choice)

          {

          case 'R':

              cout << "Which one should I reset

                                 (1, 2, 3) " << endl;

              choice = get_user_command( );

              switch (choice)

              {

              case '1':

                   s1.reset( );

                   break;

              case '2':

                   s2.reset( );

                   break;

              case '3':

                   s3.reset( );

                   break;

              }

              cout << "Reset activated for s"

                         << choice << "." << endl;

              break;

          case '1': s1.next(get_number( ));

              break;

          case '2': s2.next(get_number( ));

              break;

          case '3': s3.next(get_number( ));

              break;

          case 'T':

              cout << "The values are given

                          in this table:" << endl;

              cout << " LENGTH SUM" << " MINIMUM MEAN

                                    MAXIMUM" << endl;

              cout << " s1"; print_values(s1);

              cout << " s2"; print_values(s2);

              cout << " s3"; print_values(s3);

              break;

          case 'E': if (s1==s2)

              cout << "s1 and s2 are equal." << endl;

              else

               cout << "s1 and s2 are not equal." << endl;

                   break;

          case '+':

               s3 = s1 + s2;

              cout << "s3 has been set to s1 + s2" << endl;

              break;

          case '*':

              cout << "Please type a value for x: ";

              cin >> x; s3 = x * s1;

              cout << "s3 has been set to " << x <<

                                 " * s1" << endl;

              break;

          case 'Q':

              cout << "Ridicule is the best test

                       of truth." << endl;

              break;

          default: cout << choice << " is invalid. Sorry."

                              << endl;

          }

     } while ((choice != 'Q'));

     return EXIT_SUCCESS;

}

void print_menu()

{

cout << endl;

cout << "The following choices are available: " << endl;

     cout << " R Activate one of the reset( )

                  functions" << endl;

     cout << " 1 Add a new number to the

           1st statistician s1" << endl;

     cout << " 2 Add a new number to the

           2nd statistician s2" << endl;

     cout << " 3 Add a new number to the 3rd

                statistician s3" << endl;

     cout << " T Print a table of values from the

                   statisticians" << endl;

     cout << " E Test whether s1 == s2" << endl;

     cout << " + Set the third statistician s3 equal

                           to s1 + s2" << endl;

     cout << " * Set the third statistician s3

                         equal to x*s1" << endl;

     cout << " Q Quit this test program" << endl;

}

char get_user_command( )

{

     char command;

     cout << "Enter choice: ";

     cin >> command;

     return command;

}

double get_number( )

{

     double result;

     cout << "Please enter the next real number for the sequence: ";

     cin >> result; cout << result << " has been read." << endl;

     return result;

}

void print_values(const statistician& s) // Library facilties used: iostream.h

{

     cout << setw(10) << s.length( );

     cout << setw(10) << s.sum( );

     if (s.length( ) != 0)

     {

          cout << setw(10) << s.minimum( );

          cout << setw(10) << s.mean( );

          cout << setw(10) << s.maximum( );

     }

     else

          cout << " none none none"; cout << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote