示例#1
0
    statistician operator +(const statistician& s1, const statistician& s2){
        
     
      if (s1.length() ==0){
         return statistician(s2);
         }
      
      else if (s2.length() ==0){
        return statistician(s1); 
      }
        statistician s = statistician();

        s.count = s1.count + s2.count;
        s.total = s1.total + s2.total;
      
      // Killing to birds here by checking if one is smaller or equal
      if(s1.tinyest < s2.tinyest || s1.tinyest == s2.tinyest){
            s.tinyest = s1.tinyest;
        }
        else{
            s.tinyest = s2.tinyest;
        }

      // Same story, but doing it with the largest
        if(s1.largest < s2.largest || s1.largest == s2.largest){
            s.largest = s2.largest;
        }
        else{
            s.largest = s1.largest;
        }


        return s;
    }
示例#2
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;
}
示例#3
0
 statistician operator+(const statistician& s1, const statistician& s2) {
     statistician stat;
     stat.length = s1.length + s2.length;
     stat.sum = s1.sum + s2.sum;
     stat.last = s2.lastNumber();
     if (s1.largest > s2.largest) stat.largest = s1.largest;
     else stat.largest = s2.largest;
     if (s1.smallest < s2.smallest) stat.smallest = s1.smallest;
     else stat.smallest = s2.smallest;
     return stat;
 }
示例#4
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;
}
示例#5
0
 statistician operator *(double scale, const statistician& s1){
     
     if (s1.length() == 0) return statistician();
     
     statistician s = statistician();
     s.count = s1.count;
     s.total = s1.total * scale;
     
     // If the scale is positive, everything is fine. If it's negative, the largest and the smallest must switch!
     if (scale > 0){
         s.largest = s1.largest * scale;
         s.tinyest = s1.tinyest * scale;
     }
     else{
         s.largest = s1.tinyest * scale;
         s.tinyest = s1.largest * scale;
     }
     
     return s;
 }
示例#6
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;
}
示例#7
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;
}
示例#8
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;
    }