Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please do this in C or C++ Create a class/struct. Members: MaxSize const = 10 De

ID: 642633 • Letter: P

Question

Please do this in C or C++

Create a class/struct.

Members:
MaxSize const = 10
Define an array that holds 10 items.
Count - indicates how many items are on the queue.
Front - where the front of the queue is in the array.
Back - Where the end of the queue is in the array.


Methods:
En-queue
- Accepts a number and adds to the end of the queue.
- If the queue is full emit an error indicating full.
De-queue
- Returns a number from the front of the queue.
- If the queueis empty, emit an error indicating the queueis empty.
IsEmpty
- Returns a boolean indicating if the queue is empty.

*Note that the front and back can wrap around the end of the array over time. I.e. when the "back" of the queue gets to the last valid array index, the next insert will be into array index 0.

Make sure it runs before submitting please!

Explanation / Answer

#include<iostream>
#include<cstdlib>
#define MAX_SIZE 10
using namespace std;
class Queue{
private:
int item[MAX_SIZE];
int rear;
int front;
public:
Queue();
void enqueue(int);
int dequeue();
int size();
void display();
bool isEmpty();
bool isFull();
};
Queue::Queue(){
rear = -1;
front = 0;
}
void Queue::enqueue(int data){
item[++rear] = data;
}
int Queue::dequeue(){
return item[front++];
}
void Queue::display(){
if(!this->isEmpty()){
for(int i=front; i<=rear; i++)
cout<<item[i]<<endl;
}else{
cout<<"Queue Underflow"<<endl;
}
}
int Queue::size(){
return (rear - front + 1);
}
bool Queue::isEmpty(){
if(front>rear){
return true;
}else{
return false;
}
}
bool Queue::isFull(){
if(this->size()>=MAX_SIZE){
return true;
}else{
return false;
}
}
int main(){
Queue queue;
int choice, data;
while(1){
cout<<" 1. Enqueue 2. Dequeue 3. Size 4. Display all element 5. Quit";
cout<<" Enter your choice: ";
cin>>choice;
switch(choice){
case 1:
if(!queue.isFull()){
cout<<" Enter data: ";
cin>>data;
queue.enqueue(data);
}else{
cout<<"Queue is Full"<<endl;
}
break;
case 2:
if(!queue.isEmpty()){
cout<<"The data dequeued is :"<<queue.dequeue();
}else{
cout<<"Queue is Emtpy"<<endl;
}
break;
case 3:
cout<<"Size of Queue is "<<queue.size();
break;
case 4:
queue.display();
break;
case 5:
exit(0);
break;
}
}
return 0;
}

INPUT:

OUTPUT:

1. Enqueue