+ 2
how do i start the add() method?
You are working on a Queue management system and need to create the class to hold the queue data, which are customer IDs (integers). You make a Queue class, which has a size attribute, and an array, to hold the data of the queue. The class has a remove() method to remove the front item of the queue, a print() method to output the queue. You need to create an add() method for the Queue class, that will take an item and add it to the end of the queue. The code needs to be fully working, so that the Queue declaration and manipulation code in main() works.
19 Respuestas
+ 40
[SOLVED]
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
+ 4
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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 add(int x){
queue[size]=x;
size++;
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
+ 1
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
Good Luck
+ 1
1000% working
//your code goes here
int add(int a){
size++;
queue[size-1]=a;
a++;
+ 1
void add(int item){
this->size++;
for(int i = 0; i < size; i++){
queue[size -1] = item;
}
}
0
lensear namocatcat before we are going to help you, please present your attempt here. if you haven't done a try by yourself so far, please do so, and post it here. thanks!
0
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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 add(int x){
queue[size]=x;
size++;
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
0
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
0
void add( int x ) {
if( size != 100 ) {
queue[size] = x;
size++;
}
}
0
Plz help me to solve this, I have tried a lot ,but it won't crt
0
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
0
Please help me for this problem only.
0
[SOLVED]
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
0
it is vary difficult to pass the next
0
Please can you explain how your code works in relation to the question please Dinilalim
0
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
0
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
0
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add( int newData ) {
if( size != 0 || size != 100 ) {
size++; //increment size
queue[size-1] = newData; //make new element as the last element
}
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}
- 1
sorry, I'm just a beginner and this is all i could add to the code hehehe
#include <iostream>
using namespace std;
class Queue {
int size;
int* queue;
public:
Queue() {
size = 0;
queue = new int[100];
}
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
void add(int item) {
for(int i=0; i < size; i++) {
queue[i] = queue[i + 1];
queue[i] = item;
}
size++;
}
};
int main() {
Queue q;
q.add(42); q.add(2); q.add(8); q.add(1);
q.print();
q.remove();
q.add(128);
q.print();
q.remove();
q.remove();
q.print();
return 0;
}