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

Problem - http://www.cs.colorado.edu/~main/projects/Assn0201-Statistician.html U

ID: 3637874 • Letter: P

Question

Problem - http://www.cs.colorado.edu/~main/projects/Assn0201-Statistician.html

Use the header file provided below. Carefully read the preconditions and postconditions of each function to determine what the corresponding function should accomplish. You must write the implementation file and a driver program to test each function in the class.


// FILE: stats.h
// CLASS: stats -- A class to keep track of statistics on a sequence of real numbers

// CONSTRUCTOR for the class:
// Postcondition: The object has been initialized, and is ready to accept a sequence of numbers.

// PUBLIC MODIFICATION member functions for the statistician class:
// void next(double r)
// Postcondition: The number r has been given to the statistician as the next number in its sequence of
// numbers. All member variables will be updated.

// void reset( );
// Postcondition: The statistician has been cleared, as if no numbers had yet been given to it.

// void setcount(int init_count)
// Postcondition: count will be set to init_count

// void settotal(double init_total)
// Postcondition: total will be set to init_total

// void setminimum(double init_min)
// Postcondition: minimum will be set to init_min

// void setmaximum(double init_max)
// Postcondition: maximum will be set to init_max

// PUBLIC CONSTANT member functions for the statistician class:
// int getcount( ) const
// Postcondition: The return value is the count of the number of elements in the statistician

// double gettotal( ) const
// Postcondition: The return value is the total of all the numbers in the statistician's sequence.

// double mean( ) const
// Precondition: getcount( ) > 0
// Postcondition: The return value is the average of all the numbers in the statistician's sequence.

// double getminimum( ) const
// Precondition: getcount( ) > 0
// Postcondition: The return value is the minimum number in the statistician's sequence.

// double getmaximum( ) const
// Precondition: getcount( ) > 0
// Postcondition: The return value is the maximum number in the statistician's sequence.


// NON-MEMBER functions for the statistician class:
// stats operator+ (const stats & left, const stats & right)
// Postcondition: The statistician that is returned contains all the numbers of the sequences of left and right

// stats operator* (double scale, const stats & right) and stats operator* (const stats & left, double scale)
// Postcondition: The statistician that is returned contains the same
// numbers that left or right does, but each member has been multiplied by the scale number.

// bool operator ==(const stats& left, const stats& right)
// Postcondition: Return true if the left and right have the same count, mean, minimum, maximum, and total

// ostream& operator<< (ostream & cout, const stats & right)
// Postcondition: Displays the contents of the statistician (count, total, minimum, maximum, and mean)

#include <iostream>?using namespace std;
#ifndef STATS_H // Prevent duplicate definition
#define STATS_H
class stats
{
public:
// CONSTRUCTOR
stats( );
// MODIFICATION MEMBER FUNCTIONS
void next(double r);
void reset( );
void setcount(int);
void settotal(double);
void setminimum(double);
void setmaximum(double);
// CONSTANT MEMBER FUNCTIONS
int getcount( ) const;
double gettotal( ) const;
double mean( ) const;
double getminimum( ) const;
double getmaximum( ) const;
private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double minimum; // The smallest number in the sequence
double maximum; // The largest number in the sequence
};
// NON-MEMBER functions for the stats class
bool operator== (const stats& left, const stats& right);
stats operator+ (const stats& left, const stats& right);
stats operator* (double scale, const stats& right);
stats operator* (const stats & left, double scale);
ostream& operator<< (ostream & cout, const stats & right);
#endif

Explanation / Answer

//FILE: stats.cpp // CLASS IMPLEMENTED: stats //#include //#include //according to the text it provides assert // unnecessary #include "stats.h" // provides the stats class definition namespace main_savitch_2C { statistician::statistician() : count(0), total(0), tinyest(0), largest(0) {} //initializing everything to 0 /*-----------------------------------------------------------------------+ | next(double r) | | Give the statistician a new number | | Post: the count of the numbers statistician has seen has been | incremented | the sum of all the numbers statistician has seen has been | increment by r | the values of tinyest and largest have been adjusted if | necessary */ void statistician::next(double r) { if (count
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