Question
Queue Management We continue to develop our Queue management system that we made in the previous module. You are asked to add a new functionality:
Queue Management We continue to develop our Queue management system that we made in the previous module. You are asked to add a new functionality: adding two queues together. The result should be a new queue, where the elements of the first queue come first, followed by the second queue's elements. Given the Queue class, overload the + operator, so that the code in main works and successfully adds two queues. The overloaded operator should return a new Queue object, which contains the elements of the first queue, followed by the elements of the second queue.
#include
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
void add(int data) {
queue[size] = data;
size++;
}
void remove() {
if (size == 0) {
cout << "Queue is empty"< return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"< return; } for (int i = 0; i < size; i++) { cout< } cout << endl; } //your code goes here }; int main() { Queue q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); Queue q2; q2.add(3); q2.add(66); q2.add(128); q2.add(5); Queue q3 = q1+q2; q3.print(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started