Beispiel #1
0
//Overrides the + opperator
 cs304_statistician::statistician cs304_statistician::operator +(const statistician& s1, const statistician& s2){
	//Creates a new statistician object to save values to and return
	statistician statistician_return;	
	//Adds the length of the two statistician
	statistician_return.save_length = s1.length() +s2.length();
	//Adds the sum of the statistician	
	statistician_return.save_sum = s1.sum() +s2.sum();
	//Selects which max to take	
	if(s1.maximum() > s2.maximum() ){
		statistician_return.save_max = s1.maximum();
	}
	else{
		statistician_return.save_max = s2.maximum();
	}
	//Selects which min to take
	if(s1.minimum() < s2.minimum() ){
		statistician_return.save_min = s1.minimum();
	}
	else{
		statistician_return.save_min = s2.minimum();
	}
	//Recalculates the mean
	statistician_return.save_mean = (((s1.mean()*s1.length()) +(s2.mean()*s2.length()))/statistician_return.save_length);	
	return statistician_return;
}
Beispiel #2
0
//Checks to see if two statisticians lengths are equal
bool cs304_statistician::operator ==(const statistician& s1, const statistician& s2){
	//If they are equal lengths return true
	if(s1.length() == s2.length() && s1.minimum() == s2.minimum() && s1.mean() == s2.mean() && s1.sum() == s2.sum() && s1.maximum() == s2.maximum())
		return true;
	//If they are not equal lengths return false
	else
		return false;
}
Beispiel #3
0
    bool operator == (const statistician& s1, const statistician& s2){
        
        // If they's both empty, just ship them out like that
        if( ( s1.length() == 0) && (s2.length() == 0) ) return true;

        // Go through anything that could be different. If they are, it's all false!
        if( !(s1.length() == s2.length() ) ) return false;
        else if( !(s1.sum() == s2.sum() ) ) return false;
        else if( !(s1.minimum() == s2.minimum() ) ) return false;
        else if( !(s1.maximum() == s2.maximum() ) ) return false;
        else if( !(s1.mean() == s2.mean() ) ) return false;
 
        return true;
    }
Beispiel #4
0
//Overrides the * operator
cs304_statistician::statistician cs304_statistician::operator *(double scale, const statistician& s){
	//Creates new statistician object to be returned
	statistician statistician_return;	
	//Scales all the values of the statistician
	statistician_return.save_max = s.maximum() * scale;
	statistician_return.save_mean = s.mean() * scale;
	statistician_return.save_min = s.minimum() * scale;
	statistician_return.save_sum = s.sum() * scale;
	//Retains the origin length
	statistician_return.save_length = s.length();	
	return statistician_return;
}
Beispiel #5
0
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;
}