Question: C++ Starter Code: main.cpp /* Update this file to demonstrate thorough testing of the LeaderBoard methods. */ #include int main() { std::cout Athlete.cpp //do not

 C++ Starter Code: main.cpp /* Update this file to demonstrate thorough

C++ Starter Code:

main.cpp /* Update this file to demonstrate thorough testing of the LeaderBoard methods. */ #include

int main() { std::cout

Athlete.cpp //do not update #include #include #include #include "Athlete.h" using namespace std;

Athlete::Athlete() : name_("unknown"), country_("unknown"), points_(0) {

}

Athlete::Athlete(const string& name, const string& country, unsigned points) : name_(name), country_(country), points_(points) { }

string Athlete::getName() const { return this->name_; }

string Athlete::getCountry() const { return this->country_; }

unsigned Athlete::getPoints() const { return this->points_; }

istream& operator>>(istream& input, Athlete& a) { getline(input, a.name_, ','); getline(input, a.country_, ','); input >> a.points_; input.ignore(); return input; }

ostream& operator

Athlete.h //do not update #ifndef ATHLETE_H #define ATHLETE_H #include using namespace std;

class Athlete { private: string name_; string country_; unsigned points_; public: Athlete(); Athlete(const string&, const string&, unsigned);

//Accessors string getName() const; string getCountry() const; unsigned getPoints() const;

friend istream& operator>>(istream&, Athlete&); friend ostream& operator

};

#endif

athletes.csv Matthew Fraser,USA,984 Noah Ohlsen,USA,949 Bjorgvin Karl Gudmudsson,Iceland,888 Scott Panchik,USA,795 James Newbury,Australia,728 Jacob Heppner,USA,694 Matt Mcleod,Australia,671 Adrian Mundwiler,Switzland,632

Leaderboard.cpp #include #include #include #include #include #include "Athlete.h" #include "LeaderBoard.h" using namespace std;

LeaderBoard::LeaderBoard() { ifstream file("athletes.csv"); Athlete who; while (!file.eof()) { file >> who; this->board_.push_back(who); } file.close(); } //end of constructor

ostream& operator::reverse_iterator itr; unsigned athlete_rank = b.board_.size(); for (itr = b.board_.rbegin(); itr != b.board_.rend(); itr++) { output

unsigned LeaderBoard::rank_of_athlete(const string& name) { vector::iterator itr = this->board_.begin(); unsigned athlete_rank = 1; while (itr != this->board_.end() && itr->getName() != name) { itr++; athlete_rank++; } if (itr != this->board_.end()) { return athlete_rank; } else { return 0; } } //end of rank_of_athlete

void LeaderBoard::add(const Athlete& a) { vector::iterator itr = this->board_.begin(); while (itr != this->board_.end() && itr->getPoints() >= a.getPoints()) { itr++; } this->board_.insert(itr, a); } //end of add

void LeaderBoard::remove(const string& name) { vector::iterator itr = this->board_.begin(); while (itr != this->board_.end() && itr->getName() != name) { itr++; } if (itr != this->board_.end()) { this->board_.erase(itr); } else { /o match is found, do nothing } } //end of rank_of_athlete

Leaderboard.h #ifndef LEADERBOARD_H #define LEADERBOARD_H #include #include #include "Athlete.h" using namespace std;

class LeaderBoard { private: vector board_; public: LeaderBoard();

//accessors //Can't add const at the end because we're not teaching constant iterators. unsigned rank_of_athlete(const string& name);

//mutators void add(const Athlete& a); void remove(const string& name);

friend ostream& operator

#endif

class LeaderBoard { private: vector board_; public: LeaderBoard(); //accessors unsigned rank_of_athlete(const string& name); //mutators void add(const Athlete& a); void remove(const string& name); friend ostream& operator board_; public: LeaderBoard(); //accessors unsigned rank_of_athlete(const string& name); //mutators void add(const Athlete& a); void remove(const string& name); friend ostream& operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!