- 10

How to complete this case, please

#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; } //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; }

11th Dec 2020, 8:02 AM
Lidandi Biki
Lidandi Biki - avatar
19 Answers
+ 56
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; }
16th Jan 2021, 7:55 AM
CHAMIKA SATHSARA PATHIRAGE
CHAMIKA SATHSARA PATHIRAGE - avatar
+ 1
Queue operator+(Queue &obj) { Queue q3; for (int i=0;i<this->size;i++) { q3.add(this->queue[i]); } for (int i=0;i<obj.size;i++) { q3.add(obj.queue[i]); } return q3; } You can also try to understand by this
11th Jul 2021, 7:29 PM
PRATYUSH RAJ
PRATYUSH RAJ - avatar
+ 1
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; }
29th Jul 2021, 8:05 AM
Panchasara Jayesh Prakashbhai
Panchasara Jayesh Prakashbhai - avatar
+ 1
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; }
6th Apr 2023, 6:41 AM
Bereket Alemayehu Dige
Bereket Alemayehu Dige - avatar
0
Can you please add a description what your code should do and what is the problem
11th Dec 2020, 8:07 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
u need to do operator overload if u want to use + for your own class
11th Dec 2020, 8:22 AM
durian
durian - avatar
0
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.
11th Dec 2020, 10:40 AM
Lidandi Biki
Lidandi Biki - avatar
0
some changes are there in the prog code :- #include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.add(2); Queue q2; q2.add(8); q2.add(1); q2.add(128); q2.add(1); q2.add(128); Queue q3 = q1+q2; q3.print(); return 0; }
28th Feb 2021, 5:15 AM
Pushpak Ashwin Fasate
Pushpak Ashwin Fasate - 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 int main() { Queue q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue2 q2; .
11th Jan 2022, 8:10 AM
Chetana Patil
0
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; }
18th Feb 2023, 7:23 AM
Budhabhushan Waghmare
Budhabhushan Waghmare - avatar
0
Queue Management 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 version of the Queue for them. The only difference is the way the Queue is displayed: each number on a new line. You decide to create a new class called Queue2, which is derived from the Queue class and overrides the print() method, outputting each element of the queue on a new line. level Do not forget to change the access specifier of the Queue members, as they won't be inherited if private.
31st Mar 2023, 6:10 PM
SYED HASSAN ALI RIZVI
- 1
To overload the + operator: Queue operator+(const Queue& other){ //create new Queue and add values from this and other, then return it } It is just a function definition with a special name to overload the + operator
11th Dec 2020, 11:57 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
- 1
new code code :- #include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; }
28th Feb 2021, 5:17 AM
Pushpak Ashwin Fasate
Pushpak Ashwin Fasate - avatar
- 1
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 q1; q1.add(42); q1.add(2); q1.add(
7th Jun 2021, 4:25 AM
Monisha
Monisha - avatar
- 1
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; }
15th Aug 2021, 2:29 AM
Phùng Châu Quốc
Phùng Châu Quốc - avatar
- 1
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; } Good Luck
13th Dec 2021, 2:28 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
- 2
#include <iostream> using namespace std; class Queue { int size; int size1; int size2; int* queue; int* q1; int* q2; 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; } //your code goes here 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 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; }
13th Mar 2021, 7:13 AM
Dhaval Kanjariya
Dhaval Kanjariya - avatar
- 2
I need crt code, plz any one help me, I'm begginer
3rd Jun 2021, 3:18 PM
A.B.Rithika
A.B.Rithika - avatar
- 2
#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--; } } 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) {
7th Jun 2021, 4:35 AM
A.B.Rithika
A.B.Rithika - avatar