Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete file CandidateQueue.cpp CandidateQueue.cpp #include CandidateQueue.h #include using namespace std; CandidateQueue::CandidateQueue() { count = 0; capacity = 2; candidates = new Candidate*[capacity]; } void CandidateQueue::push_player(Candidate*

Complete file CandidateQueue.cpp

CandidateQueue.cpp

 #include "CandidateQueue.h" #include  using namespace std; CandidateQueue::CandidateQueue() { count = 0; capacity = 2; candidates = new Candidate*[capacity]; } void CandidateQueue::push_player(Candidate* p) { // TO DO } Candidate* CandidateQueue::front_player(string r) { // TO DO } void CandidateQueue::pop_player(string r) { // TO DO } Candidate** CandidateQueue::form_group() { Candidate** group = new Candidate*[2]; // TO DO return group; }

CandidateQueue.h

#pragma once #include "Candidate.h" class CandidateQueue { private: Candidate **candidates; // This field keeps the players that are in the line (It is an array which keeps pointers to Players) int count; // This field keeps track of number of people in the line int capacity; // This field is the capacity of the line public: // Constructs a new empty queue CandidateQueue(); // Pushes a pointer to a player onto the back of the line (remember it is a queue implemented in array, so back of the line is index 0). // If the line is full , double the capacity and move everybody in the line to the new line (create a new array of pointers with new capacity, copy everything from the current line and assign it to the current line) //Hint: don't forget to release the memory for current line void push_player(Candidate *p); // Returns a pointer to the frontmost player in the line with the specified role. // If no such player exists, returns nullptr. Candidate* front_player(string role); // Removes the frontmost player with the specified role. // Don't forget to move everybody after removing that player // If no such player exists, does nothing. void pop_player(string role); // Returns whether the queue contains a complete group // // Create a group of two (an array), if the queue contains a complete group (one developer and one designer), //this method put them in the created array and return the group (an array of pointer to players) //Hint: Use the other methods you already developed above Candidate** form_group(); };

Source.cpp

/* In this program, we have a line of candidates, some are developer and some are designer. When we want to create a team, we need one deisgner and one developer. The candidates are all standing in the line. */ #include  #include "CandidateQueue.h" using namespace std; int main() { // Variables used for testing Candidate daniela("Daniela", "Developer"); Candidate hector("Hector", "Developer"); Candidate berta("Berta", "Designer"); Candidate hugo("Hugo", "Designer"); Candidate bernardo("Bernardo", "Designer"); Candidate daria("Daria", "Developer"); CandidateQueue q; q.push_player(&daniela); q.push_player(&hector); q.push_player(&berta); q.push_player(&hugo); q.push_player(&bernardo); q.push_player(&daria); Candidate** group1 = q.form_group(); cout << "First group:" << endl; cout << group1[0]->name() << " : " << group1[0]->role()<name() << " : " << group1[1]->role()<name() << " : " << group1[0]->role()<name() << " : " << group1[1]->role()< 

Candidate.h

#pragma once #include  using namespace std; class Candidate { public: // Initializes a player with the given name and role. role is either developer or designer Candidate(string name, string role); // Returns the name of the player string name(); // Returns the role of the player string role(); private: string _name; string _role; };

Candidate.cpp

#include "Candidate.h" Candidate::Candidate(string name, string role) { _name = name; _role = role; } string Candidate::name() { return _name; } string Candidate::role() { return _role; } 

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

5. Develop a self-management module for a training program.

Answered: 1 week ago