Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implement a looking-for-group queue for a game where players can be one of three roles (Defender, Hunter, and Bard) and each group consists of one

implement a looking-for-group queue for a game where players can be one of three roles (Defender, Hunter, and Bard) and each group consists of one Defender, one Hunter, and one Bard.

image text in transcribed

Create a new C++ source file named lfgqueue.cpp that implements the LFGQueue class declared in lfgqueue.h such that lfqueue.cpp and the provided files compile into a program that runs with no failed tests.

please use the code given below

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

(lfgqueue.h)

#ifndef LFGQUEUE_H #define LFGQUEUE_H #include "player.h" class LFGQueue { public: // Constructs a new empty queue LFGQueue(); // Returns the number of players in the queue. int size(); // Pushes a pointer to a player onto the back of the queue. void push_player(Player* p); // Returns a pointer to the frontmost player // with the specified role. // If no such player exists, returns nullptr. Player* front_player(Player::Role r); // Removes the frontmost player with the specified role. // If no such player exists, does nothing. void pop_player(Player::Role r); // Returns whether the queue contains a complete group // (a Defender, a Hunter, and a Bard). // // If the queue contains a complete group, the method // sets the first three elements of the array parameter // equal to the addresses of the frontmost: // 1. Defender (index 0) // 2. Hunter (index 1) // 3. Bard (index 2) bool front_group(Player** group); // Removes the frontmost Defender, Hunter, and Bard // from the queue. If some role has no player with that role, // then does nothing. void pop_group(); private: Player** players; int count; int capacity; }; #endif

////////////////////////////////////////////// (player.h)

#ifndef PLAYER_H #define PLAYER_H #include using namespace std; class Player { public: // This works like a custom type with just four values. // Outside of Player methods, reference them like: // "if (p->role == Player::Defender)", etc. enum Role {Defender, Hunter, Bard}; // 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 capacity Player** A count Player* array "Berta"" Hunter Hector""Daria" Bard Defender Player objects 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

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions