+ 11
Can anyone please solve the c++ Queue Management Part 4?
21 Answers
+ 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;
}
+ 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++;
}
+ 7
Hmd i did tried adding the code you've provided, but seems the output gone error....
+ 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;
}
+ 1
That's why I am asking for i can't understand what's wrong with this code?
+ 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;
}
0
Thank you...
0
Thank you ssoooo muchh ❤️❤️❤️❤️❤️❤️❤️❤️❤️
0
Help me in part 2 & 3
0
Can anyone help me with queue management part 3
0
Help with part 3
0
Eirol Tulio see this code https://code.sololearn.com/crV2V4bvfRAA/?ref=app
0
Thanks!
0
welcome Eirol Tulio
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;
}
0
Part 3 please
0
can anyone help me with with Queue management part 4?
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++
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;
}
0
Visit here for better & easy solution :-
https://code.sololearn.com/ca173a10813a