+ 1

I need help with the last project on C++ course

24th Aug 2022, 5:21 PM
Marlon Batista Iglesias
Marlon Batista Iglesias - avatar
5 Answers
+ 1
size type should be always int so make int size; And queue must be of type T So change to queue = new T[100]; And remaining are fine I think.
24th Aug 2022, 6:06 PM
Jayakrishna 🇼🇳
0
What help? post your try along description..
24th Aug 2022, 5:54 PM
Jayakrishna 🇼🇳
0
I've to transform Queue class to admit more than 1 data type. I'm using template for it, send you capture
24th Aug 2022, 5:57 PM
Marlon Batista Iglesias
Marlon Batista Iglesias - avatar
0
#include <iostream> using namespace std; template<class T> class Queue { T size; T* queue; public: Queue() { size = 0; queue = new int[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;
24th Aug 2022, 6:02 PM
Marlon Batista Iglesias
Marlon Batista Iglesias - avatar
0
Thanks son much bro
24th Aug 2022, 6:41 PM
Marlon Batista Iglesias
Marlon Batista Iglesias - avatar