#include "stdstuff.h" #include "SwimStats.h" // constructs a new swimmer with 0 golds, 0 2-3rds, 0 4-8ths, 0 9th+ SwimStats::SwimStats() { golds = medals = finals = heats = 0; } // constructs a new swimmer with "golds" golds, "medals" medals, // "finals" finals, and "heats" heats SwimStats::SwimStats(int golds, int medals, int finals, int heats) { this->golds = golds; SwimStats::medals = medals; this->finals = finals; SwimStats::heats = heats; // this-> or SwimStats:: only required if argument names match field names } // the swimmer adds a win to his record! void SwimStats::win() { golds++; } // the swimmer adds a 2nd or 3rd to his record void SwimStats::medal() { medals++; } // the swimmer adds a 4th-8th to his record void SwimStats::final() { finals++; } // the swimmer adds a 9th or worse to his record void SwimStats::noFinal() { heats++; } // prints the stats: "golds-medals-finals-heats" void SwimStats::printStats() const { cout << golds << "-" << medals << "-" << finals << "-" << heats; } // returns the number of golds this swimmer has to date int SwimStats::numGolds() const { return golds; } // returns true if the swimmer has more medals (1st-3rd) than other placings bool SwimStats::moreMedals() const { return (golds+medals > finals+heats); } // returns true if the swimmer has more gold medals than the other swimmer, // and false otherwise bool SwimStats::moreGoldsThan(const SwimStats &otherSwimmer) const { return (golds > otherSwimmer.golds); } // returns the number of points the swimmer has (10 for a win; 5 for 2nd-3rd; // 1 for 4th-8th) int SwimStats::score() const { return (10*golds + 5*medals + finals); }