Question: Create a C++ PROGRAM In many multiplayer online games, theres a looking for group feature for being automatically matched with other players. Such a feature

Create a C++ PROGRAM

In many multiplayer online games, theres a looking for group feature for being automatically matched with other players. Such a feature behaves like a queue: players join the queue and removed in complete groups, and players who join the queue first are the first to be grouped. Here youll 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.

YOU CAN ONLY CHANGE lfgqueue.cpp file. Do not change anything else

Create a C++ PROGRAM In many multiplayer online games, theres a looking

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.

The following files have been given and are not to be changed:

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  

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; } 

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(); // Adds a (pointer to a) player to 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 0. 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 // no players are removed. void pop_group(); private: Player** players; int count; int capacity; };
Player objects

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!