How do you solve this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How do you solve this code?

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

6th Oct 2023, 7:55 AM
irene
irene - avatar
8 Answers
+ 5
Rakesh Deep Please don't give readymade code, otherwise opponent will not try by yourself.
6th Oct 2023, 12:47 PM
Sakshi
Sakshi - avatar
+ 3
do it from yourself,, this question is in the c++ intermediate course , and solve it yourself cuz a real coder is not who ask questions , the real question is who finds the solution
7th Oct 2023, 3:54 PM
Alhaaz
Alhaaz - avatar
+ 2
Sina Ghorbanian Don't provide readymade code give the member hint let them try to learn themself.
6th Oct 2023, 2:57 PM
R💠🇮🇳
R💠🇮🇳 - avatar
0
Okay, thank you
6th Oct 2023, 10:38 AM
irene
irene - avatar
0
Queue management test module 2 c++ intermediate
6th Oct 2023, 10:42 AM
irene
irene - avatar
0
#include <iostream> using namespace std; class Queue { private: 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; } // Operator overloading for adding two queues Queue operator+(const Queue& other) { Queue result; for (int i = 0; i < this->size; i++) { result.add(this->queue[i]); } for (int i = 0; i < other.size; i++) { result.add(other.queue[i]); } return result; } }; 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; }
6th Oct 2023, 1:34 PM
Sina Ghorbanian
Sina Ghorbanian - avatar
0
ul {list-style:none; color:56494c;} li::before {content: "•"; color:brown;} p {color:56494c; font-family:georgia; background-color:;} form {color:56494c;}
7th Oct 2023, 6:37 PM
أفكار ؟
أفكار ؟ - avatar
0
Try writing it in Html
7th Oct 2023, 7:23 PM
Richman Akinosho