#include #include "player.h" using namespace std ; // Add the plus minus rating for a game // to a player's record. // medianRating must be updated accordingly. // void Player::AddStat (stat& s) { record.push_back(s) ; dirty = true ; } // Print out a player's name and medianRating // This is a const function, so it should not // change the value of any data memebers. void Player::Print () const { cout << name << " " << GetRating() << endl ; } int Player::GetRating () const { if (dirty) { sort(record.begin(), record.end()) ; medianRating = (record[(record.size() / 2)]).pmRating ; dirty = false; } return medianRating ; } // Print out a player's name and medianRating // and all the stats. // This is a const function, so it should not // change the value of any data memebers. void Player::PrintAll () const { cout << name << " " << GetRating() << endl ; for (int i = 0 ; i < record.size() ; i++) { cout << "(" << record[i].game << "," << record[i].pmRating << ")" << " " ; } cout << endl ; } void Player::debug() { fprintf (stderr, "name (%p) = %s \n", name.c_str(), name.c_str()) ; fprintf (stderr, "record(%p) = { ", &record ) ; for(int i = 0 ; i < record.size() ; i++) { fprintf (stderr, "(%d, %d) ", record[i].game, record[i].pmRating) ; } fprintf (stderr, "}\n" ) ; fprintf (stderr, "medianRating = %d\n", medianRating) ; }