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

Most of the program is already written. For file stats.cpp Add the logic for the

ID: 3628065 • Letter: M

Question

Most of the program is already written.


For file stats.cpp
Add the logic for the following methods:.

// implement reset

// implement mean

// implement minimum

// implement maximum

// implement operator +

// implement operator ==



// FILE: stats.h
// Written by: Michael Main (main@colorado.edu) - Nov 13, 1996
// Edited by: Briana Morrison (bmorriso@spsu.edu) - Jan 23, 2008
// CLASS PROVIDED: Statistician
// (a class to keep track of statistics on a sequence of real numbers)
//
// CONSTRUCTOR for the Statistician class:
// Statistician( );
// Postcondition: The object has been initialized, and is ready to accept
// a sequence of numbers. Various statistics will be calculated about the
// sequence.
//
// PUBLIC MODIFICATION member functions for the Statistician class:
// void next(double r)
// The number r has been given to the statistician as the next number it
// its sequence of numbers.
// void reset( );
// Postcondition: The statistician has been cleared, as if no numbers had
// yet been given to it.
//
// PUBLIC CONSTANT member functions for the Statistician class:
// int length( ) const
// Postcondition: The return value is the length of the sequence that has
// been given to the statistician (i.e., the number of times that the
// next(r) function has been activated).
// double sum( ) const
// Postcondition: The return value is the sum of all the numbers in the
// statistician's sequence.
// double mean( ) const
// Precondition: length( ) > 0
// Postcondition: The return value is the arithmetic mean (i.e., the
// average of all the numbers in the statistician's sequence).
// double minimum( ) const
// Precondition: lenght( ) > 0
// Postcondition: The return value is the tinyest number in the
// statistician's sequence.
// double maximum( ) const
// Precondition: length( ) > 0
// Postcondition: The return value is the largest number in the
// statistician's sequence.
//
// NON-MEMBER functions for the Statistician class:
// Statistician operator +(const Statistician& s1, const Statistician& s2)
// Postcondition: The statistician that is returned contains all the
// numbers of the sequences of s1 and s2.
// bool operator ==(const Statistician& s1, const Statistician& s2)
// Postcondition: The return value is true if s1 and s2 have the same
// length. Also, if the length is greater than zero, then s1 and s2 must
// have the same mean, the same minimum, and the same maximum, and the
// same sum.
//
// VALUE SEMANTICS for the Statistician class:
// Assignments and the copy constructor may be used with Statistician objects.

#ifndef STATS_H // Prevent duplicate definition
#define STATS_H
#include

using namespace std;

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 istream& operator >>
(istream&, Statistician& s1);
friend ostream& operator <<
(ostream&, Statistician& s1);
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
};

// NON-MEMBER functions for the Statistician class
bool operator ==(const Statistician& s1, const Statistician& s2);

#endif

// FILE: stats.cpp
// Written by: Michael Main (main@colorado.edu) - Nov 13, 1996
// Edited by: Briana Morrison (bmorriso@spsu.edu) - Jan 23, 2008
// CLASS IMPLEMENTED: Statistician (see stats.h for documentation)



#include // Provides istream classes
#include "stats.h"

using namespace std;

Statistician::Statistician( )
{
reset( );
}

void Statistician::next(double r)
{
total += r;
count++;
if ((count == 1) || (r < tinyest))
tinyest = r;
if ((count == 1) || (r > largest))
largest = r;
}


// implement reset

// implement mean

// implement minimum

// implement maximum

// implement operator +

// implement operator ==



istream& operator >>(istream& ins, Statistician& target)
{
double user_input;

while (ins && (ins.peek( ) != ';'))
{
if (ins.peek( ) == ' ')
ins.ignore( );
else
{
ins >> user_input;
target.next(user_input);
}
}
ins.ignore( );

return ins;
}

ostream& operator <<(ostream& outs, Statistician& target)
{
outs << "Values for statistician object: " << endl;
outs << " total: " << target.total << endl;
outs << " count: " << target.count << endl;
outs << " smallest: " << target.tinyest << endl;
outs << " largest: " << target.largest << endl << endl;

return outs;

}

// File teststate.cpp
// Written by Briana Morrison (bmorriso@spsu.edu)
// usage of stats file

#include
#include "stats.h"

using namespace std;

void menu (void)
{ cout<cout<<"1. Add a number"<cout<<"2. Reset the statistician"<cout<<"3. Length"<cout<<"4. Sum"<cout<<"5. Mean"<cout<<"6. Minimum"<cout<<"7. Maximum"<cout<<"8. Add"<cout<<"9. Equality"<cout<<"10. Print" << endl;
cout<<"11. Quit"<cout<<"Enter selection>";
}

void add(Statistician& S)
{Statistician s2, s3;
s2.reset();
s3.reset();

//enter values for second stat
cout<<"Enter values for second stat, enter ; to stop"<cin>>s2;

s3 = S + s2;
cout<<"Values for added statistician are:"<cout<<"Length: "<cout<<"Sum: "<}


void equal(const Statistician &S)
{ Statistician s2;
s2.reset();

//enter values for second stat
cout<<"Enter values for second stat, enter ; to stop"<cin>>s2;

if (s2==S) cout<<"equal"<else cout<<"unequal"<}


//Beginning of main program
int main (void)
{
int choice;
double num;

//declare a Statistician
Statistician s;
s.reset();

do {
//print menu
menu();
cin>>choice;

switch (choice) {
case 1 : cout< ";
cin>>num;
s.next(num);
cout<break;

case 2 : s.reset();
cout<break;

case 3: cout<break;

case 6: if (s.length() >0)
cout<break;

case 7: if (s.length() >0)
cout<break;

case 8: add(s);
break;

case 9: equal(s);
break;

case 10: cout << s;
break;

case 11: cout<break;

default : cout<}

} while (choice != 11);
}

Explanation / Answer

I am working on this program.
But could you please explain to me what each option in the menu will do?

Your file seems to be collapse it and it's taking me so much time to rewrite. If you give me more info it would be great.

 

-- here are the codes. Not have chance to compile the codes because you haven't answer my question above.

// implement reset
void Statistician::reset()
{
    count = 0;
    total = 0;
    tinyest = 0;
    largest = 0;
}

// implement mean
double Statistician::mean()
{
    if (count > 0)
        return (total/count);
    else
    {
        cout << "no number in Statistian, mean() returning 0 ";
        return 0;
    }
}

// implement minimum
double Statistician::minimum()
{
    if (cout > 0)
        return tinyest;
    else
    {
        cout << "no number in Statistian. minimum() returning 0 ";
        return 0;
    }
}

// implement maximum
double Statistician::maximum()
{
    if (count > 0)
        return largest;
    else
    {
        cout << "no number in Statistian. maximum() returning 0 ";
        return 0;
    }
}


// implement operator +
Statistician operator +(const Statistician& s1, const Statistician& s2)
{
    Statistician result;
    result.count = s1.length() + s2.length();
    result.total = s1.sum() + s2.sum();
    if (s1.minimum() < s2.mimimum())
        result.tinyest = s1.minimum();
    else
        result.tinyest = s2.minimum();

    if (s1.maximum() < s2.maximum())
        result.largest = s2.maximum();
    else
        result.largest = s1.maximum();
    return result;
}


// implement operator ==
bool operator ==(const Statistician& s1, const Statistician& s2)
{
    if (s1.length() == 0 && s2.length() == 0)
        return true;
    // if it reaches here, it means one of their lengths, or both of their lengths is not 0
    if (s1.length() == s2.length())
    {
        if ((s1.mean() == s2.mean()) && (s1.minimum() == s2.minimum())
            && (s1.maximum() == s2.maximum()) && (s1.sum() == s2.sum())
            return true;
        else
            return false;
    }
}

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