Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: Accompanying this question is a skeleton of a program that partially d

ID: 3578293 • Letter: Q

Question

Question:

Accompanying this question is a skeleton of a program that partially defines a Queue class, as well as a main function that uses an instance of the Queue. Finish the Queue class by completing the method Queue::show so that the output of the program matches the output below. No modifications to the Queue class nor the main function are required, such changes are prohibited.

Code:

#include<iostream>
#include<string>
using namespace std;

#define CAP 5
class Queue {
public:
   void enq(string name);
   string deq();
   int count();
   bool isFull();
   bool isEmpty();
   void show();
private:
   string line[CAP];
   int size = 0, front = 0, back = 0;
};

bool Queue::isFull() {
   return (size == CAP);
}

bool Queue::isEmpty() {
   return (size == 0);
}

void Queue::enq(string name) {
   if (isFull()) {
       /* Queue is full */
       return;
   }
   line[back] = name;
   back = (back + 1) % CAP;
   size++;
}

string Queue::deq() {
   if (isEmpty()) {
       /* Queue is empty */
       return "";
   }
   string s = line[front];
   front = (front + 1) % CAP;
   size--;
   return s;
}

void Queue::show() {
   /*
   * Complete me
   */
}

int main(void) {
   Queue q;
   cout << "Enqueueing 5 people" << endl;
   q.enq("fred");
   q.enq("barney");
   q.enq("wilma");
   q.enq("steve");
   q.enq("april");
   q.show();

   cout << "Dequeueing 5 people" << endl;
   q.deq(); q.deq(); q.deq(); q.deq();   q.deq();
   q.show();

   cout << "Enqueueing 3 people" << endl;
   q.enq("jack");
   q.enq("jill");
   q.enq("claire");
   q.show();

   cout << "Dequeueing 1 person" << endl;
   q.deq();
   q.show();
  
   cout << "Enqueueing 2 people" << endl;
   q.enq("brad");
   q.enq("janet");
   q.show();

   return 0;
}

Example Output:

Enqueueing 5 people

fred barney wilma steve april

Dequeueing 5 people

Enqueueing 3 people

jack jill claire

Dequeueing 1 person

jill claire

Enqueueing 2 people

jill claire brad janet

Press any key to continue . . .

Explanation / Answer

//show method of class Queue ,rest of the program unchanged

void Queue::show() {
   /*
   * Complete me
   */
   for (int i = 0 ; i < size ; i++)
   {
       cout << line[front+i] << " ";
   }
   cout << endl;
}

------------------------------------------------------------

output exactly as shown in examle

Enqueueing 5 people
fred barney wilma steve april
Dequeueing 5 people

Enqueueing 3 people
jack jill claire
Dequeueing 1 person
jill claire
Enqueueing 2 people
jill claire brad janet

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote