Question: Use three linked-list-based queues, one for each player role and create a new C++ source file named lfgqueue.cpp that implements the LFGQueue class declared in

Use three linked-list-based queues, one for each player role and create a new C++ source file named lfgqueue.cpp that implements the LFGQueue class declared in lfgqueue.h such that provided files compile into a program that runs with no failed tests. Please use the files provided below and the final output after passing all the tests on main.cpp should output "Assignment complete."

Use three linked-list-based queues, one for each player role and create a

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// (lfgqueue.h)

 #ifndef LFGQUEUE_H #define LFGQUEUE_H #include "player.h" class LFGQueue { public: // All of the methods are the same // as in hwLFG1. LFGQueue(); int size(); void push_player(Player* p); Player* front_player(Player::Role r); void pop_player(Player::Role r); bool front_group(Player** group); void pop_group(); private: class Node { public: Player* p; Node* next; }; // You can index into these arrays using Player::Role values! // Check out player.h to see the int value of each Role. // // This lets you do things like: // "if (heads[p->role()] == nullptr)" and "++counts[p->role()]" Node* heads[3]; Node* tails[3]; int counts[3]; }; #endif 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

// (player.h)

 #ifndef PLAYER_H #define PLAYER_H #include  using namespace std; class Player { public: // This works like a custom type with just three values. // Outside of Player methods, reference them like: // "if (p->role == Player::Defender)", etc. enum Role {Defender=0, Hunter=1, Bard=2}; // Initializes a player with the given name and role Player(string name, Role role); // Returns the name of the player string name(); // Returns the role of the player Role role(); private: string _name; Role _role; }; #endif 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// (player.cpp)
 #include "player.h" Player :: Player(string name, Role role) { _name = name; _role = role; } string Player :: name() { return _name; } Player::Role Player :: role() { return _role; } 
//////////////////////////////////////////////////////////////////////////////////////////////////
// (main.cpp)
 #include  #include  #include  #include "lfgqueue.h" using namespace std; inline void _test(const char* expression, const char* file, int line) { cerr name() == oss.str()); oss.str(""); oss name() == oss.str()); oss.str(""); oss name() == oss.str()); q.pop_group(); test(q.size() == 999 - 3 * (i+1)); } test(q.size() == 0); test(!q.front_group(group)); for (int i = 0; i (choice); string name; switch (role) { case Player::Defender: name = "Defender #?"; break; case Player::Hunter: name = "Hunter #?"; break; case Player::Bard: name = "Bard #?"; break; } q.push_player(new Player(name, role)); ++added[choice]; } test(q.size() == 1000000); // Remove as many complete groups as possible int complete_groups = added[0]; if (added[1]  

"Daria" "Hector""Hugo'" DefenderHunter Hunter Player** heads Player** tails "Berta" "Bess" "Beto" Bard Figure 1: A queue of players

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!