0
Your Queue class is up and working in a customer service company. The company opens up a new branch and asks you to make another
Could someone help me create a c++ code for this question
16 Réponses
+ 1
Thanks so much... The fix actually works on the program that i was stuck... Thanks for the help...
0
Hi! First you should try to do it yourself
0
I tried but am stuck somewhere
0
In this case, please show us your code attempt
0
#include <iostream>
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"<<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;
}
Queue operator+(Queue &obj) {
Queue res;
for(int i=0;i<this->size;i++) {
res.add(this->queue[i]);
}
for(int i=0;i<obj.size;i++) {
res.add(obj.queue[i]);
}
return res;
}
};
//your code goes here
class Queue2 : public Queue {
public:
Queue2(){
};
void print(){
if(size==0){
0
cout<<"Queue is empty"<<endl;
return;
}
for(int i=0; i<size; i++){
cout<<queue[i]<<"\n";
}
cout<<endl;
}
};
int main() {
Queue q1;
q1.add(42); q1.add(2); q1.add(8); q1.add(1);
q1.print();
Queue2 q2;
q2.add(3); q2.add(66); q2.add(128); q2.add(5);q2.add(111);q2.add(77890);
q2.print();
return 0;
}
0
That is the whole code...
0
it is advisable to place such a large code in your code platform for convenience and give a link to it in this question
0
Lemme try this
0
Done
0
Am not sure if i have gotten what you said exactly... Could you try to show me what you mean and where
0
Okay, I read the assignment. Here's the task. You want to inherit Queue2 from Queue. You did that. So disregard my previous post. The ONLY task is to override the print() method so that it outputs in a slightly different way. At first glance, the code you have should work.
What is the error you are having?
0
'int Queue::size' is declared private within its context
0
I don't know if this is the desired solution, but to fix that problem, I changed the declaration in the "class Queue()" to public. It says private. I changed it to public.
Like this:
class Queue {
public:
int size;
int* queue;
0
Okay... Lemme check