Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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."

image text in transcribed

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

// (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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Second International Conference Acids Hue City Vietnam March 2010 Proceedings Part 1 Lnai 5990

Authors: Manh Thanh Le ,Jerzy Swiatek ,Ngoc Thanh Nguyen

2010th Edition

3642121446, 978-3642121449

More Books

Students also viewed these Databases questions

Question

How is the ALU related to the CPU? What are its main functions?

Answered: 1 week ago

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago