Class and object. Please help me for solve this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Class and object. Please help me for solve this

You are working on a Queue management system and need to create the class to hold the queue data, which are customer IDs (integers). You make a Queue class, which has a size attribute, and an array, to hold the data of the queue. The class has a remove() method to remove the front item of the queue, a print() method to output the queue. You need to create an add() method for the Queue class, that will take an item and add it to the end of the queue. The code needs to be fully working, so that the Queue declaration and manipulation code in main() works.

6th Jan 2021, 2:35 PM
MD. Omar Faruk Maruf
MD. Omar Faruk Maruf - avatar
3 Answers
0
Please provide your attempt.
6th Jan 2021, 2:41 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
#include <iostream> using namespace std; class Queue { int size; int* queue; public: Queue() { size = 0; queue = new int[100]; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; 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"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout <<endl; } //your code goes here }; int main() { Queue q; q.add(42); q.add(2); q.add(8); q.add(1); q.print(); q.remove(); q.add(128); q.print(); q.remove(); q.remove(); q.print(); return 0; }
6th Jan 2021, 2:45 PM
MD. Omar Faruk Maruf
MD. Omar Faruk Maruf - avatar
0
Where's your implementation attempt of add()? You need to provide your try in order to get help.
6th Jan 2021, 2:54 PM
你知道規則,我也是
你知道規則,我也是 - avatar