+ 11

Can anyone please solve the c++ Queue Management Part 4?

https://code.sololearn.com/cN9rBxhA9fix/?ref=app

22nd Nov 2020, 6:50 PM
Manthan Verma
Manthan Verma - avatar
21 Respuestas
+ 36
#include <iostream> using namespace std; template <class T> class Queue { int size; T* queue; public: Queue() { size = 0; queue = new T[100]; } void add(T 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; } }; int main() { Queue<int> q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue<string> q2; q2.add("Dave"); q2.add("John"); q2.add("Amy"); q2.print(); return 0; }
2nd Feb 2021, 6:26 AM
Namrata Dattani
Namrata Dattani - avatar
+ 16
template <class T> class Queue { int size; T* queue; public: Queue() { size = 0; queue = new T[100]; } void add(T); void remove() { ........ ....... template <class T> void Queue <T>::add(T data) { queue[size] = data; size++; }
15th Dec 2020, 10:33 PM
Hmd(inactive)
+ 7
Hmd i did tried adding the code you've provided, but seems the output gone error....
24th Jan 2021, 4:12 AM
Eirol Tulio
Eirol Tulio - avatar
+ 6
/*This was my solution, simple but complete*/ //Queue management part 4 #include <iostream> using namespace std; template <class T> /*Create template class T*/ class Queue { int size; T* queue;/*Modify int pointer to T class*/ public: Queue() { size = 0; queue = new T[100]; /*Modify int data type to T type*/ } void add(T data) { /*Modify int data type to T type*/ 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; } }; int main() { Queue<int> q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue<string> q2; q2.add("Dave"); q2.add("John"); q2.add("Amy"); q2.print(); return 0; }
13th Mar 2021, 2:05 PM
Jake
+ 1
That's why I am asking for i can't understand what's wrong with this code?
22nd Nov 2020, 7:03 PM
Manthan Verma
Manthan Verma - avatar
+ 1
Queue management par 3 correct sollution //Queue Management pt.3 //Create a new class called Queue2 //Queue2 should be a derived class from Queue //Overide the print() function to print each member of the queue on a new line #include <iostream> using namespace std; class Queue { public: int size; int* queue; public: Queue() { size = 0; queue = new int[100]; } public: void add(int data) { queue[size] = data; size++; } public: 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--; } } public: 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& q) { Queue newQ; for (int i = 0; i < this->size; i++) { newQ.add(this->queue[i]); } for (int i = 0; i < q.size; i++) { newQ.add(q.queue[i]); } return newQ; } }; class Queue2 : public Queue { public: void print() { if (size == 0) { cout << "Queue is empty" << endl; return; } for (int i = 0; i < size; i++) { cout << queue[i] << endl; } cout << endl; } }; //new print() function 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; }
28th Sep 2022, 9:45 AM
FATIMA USMAN TSOHO
FATIMA USMAN TSOHO - avatar
0
Thank you...
22nd Nov 2020, 7:13 PM
Manthan Verma
Manthan Verma - avatar
0
Thank you ssoooo muchh ❤️❤️❤️❤️❤️❤️❤️❤️❤️
11th Dec 2020, 7:37 AM
Aya Sherbak
Aya Sherbak - avatar
0
Help me in part 2 & 3
15th Dec 2020, 10:41 AM
Shayhan Sagufta
Shayhan Sagufta - avatar
0
Can anyone help me with queue management part 3
31st Dec 2020, 6:51 PM
SUMIT SANTOSH SAHU
SUMIT SANTOSH SAHU - avatar
0
Help with part 3
22nd Jan 2021, 6:03 AM
ADABALA BINDUSRI
24th Jan 2021, 1:12 PM
Hmd(inactive)
0
Thanks!
24th Jan 2021, 1:13 PM
Eirol Tulio
Eirol Tulio - avatar
0
welcome Eirol Tulio
24th Jan 2021, 1:14 PM
Hmd(inactive)
0
#include <iostream> using namespace std; template <class T> class Queue { int size; T* queue; public: Queue() { size = 0; queue = new T[100]; } void add(T 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; } }; int main() { Queue<int> q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue<string> q2; q2.add("Dave"); q2.add("John"); q2.add("Amy"); q2.print(); return 0; }
5th Feb 2021, 12:08 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
0
Part 3 please
14th Feb 2021, 9:01 AM
Omkumar giri
Omkumar giri - avatar
0
can anyone help me with with Queue management part 4?
7th Mar 2021, 10:43 AM
Alessio Testarella
Alessio Testarella - avatar
0
Part 3 #include <iostream> using namespace std; class Queue { public: 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--; } } virtual 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 : void print(){ for (int i = 0; i < size; i++
7th Mar 2021, 1:09 PM
Manthan Verma
Manthan Verma - avatar
0
#include <iostream> using namespace std; template <class T> class Queue { int size; T* queue; public: Queue() { size = 0; queue = new T[100]; } void add(T 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; } }; int main() { Queue<int> q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue<string> q2; q2.add("2"); q2.add("8"); q2.add("1"); q2.add("128"); q2.add("1"); q2.add("128"); q2.print(); return 0; }
9th Apr 2021, 3:06 PM
Jerome Ian Roxas
Jerome Ian Roxas - avatar
0
Visit here for better & easy solution :- https://code.sololearn.com/ca173a10813a
31st Jul 2021, 12:54 PM
RAJAT AGRAWAL
RAJAT AGRAWAL - avatar