- 2

Help with “Queue management part 3” and “Queue management part 4”

Please share the solution to these two problems (complete code)

15th Feb 2021, 8:49 PM
Anton Shapoval
Anton Shapoval - avatar
6 Réponses
+ 2
People should not share complete codes. You won't learn correctly that way.
15th Feb 2021, 10:32 PM
Sonic
Sonic - avatar
+ 2
E.g. in part3 write a Queue2 class that is derived from the Queue class and overrides the print() method.
15th Feb 2021, 10:35 PM
Sonic
Sonic - avatar
0
post your attempts first and we will help
15th Feb 2021, 9:19 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
0
for part 3 just look how to inherit Queue2 from Queue, at lesson 74.1 Abstract Classes there are some good examples about it. Then just change the void print() func a bit and don't forget to change access specifier for some variables. Without posting the code this is all i can write ı guess.
16th Feb 2021, 6:34 PM
Berke
Berke - avatar
0
for part 4 you really have to understand template. 79.1 Class Templates lesson would be a great way to understand what is going on. With the help of a compiler you really can manage to do that. There are 4 parts to change in code so good luck.
16th Feb 2021, 9:32 PM
Berke
Berke - avatar
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) { 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; }
29th Mar 2021, 7:37 AM
Kingston Jay Macabiog
Kingston Jay Macabiog - avatar