Hi I need help with this c++ programming homework and this program is about the
ID: 3602195 • Letter: H
Question
Hi I need help with this c++ programming homework and this program is about the queue and also this project should make a use of the array implementation. Also, all other instructions are in the attached photo please read that and don't copy and paste from old work. please try to explain the code and when you compile don't make another output file or .txt so don't use ofstream just try to show the answer in the compiler because i am using xcode its hard to find that file. thank you.
************************************************************************************************************************************************************************************************
Question
************************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************************
The answer should be THIS at the end when you compile.
************************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************************
Few mor instrections about how the answer look like.
************************************************************************************************************************************************************************************************
1) At the end, it should ask for entering how many numbers are there in the data set.
2) Ask to enter each number.
3) Show the answer as a categorized data (as seen in the image)
Prog ramming Assignment:Abstract Data Type Queue Application: Categorizing Data Problem Specification Categorizing data: it is often necessacy to destroying their relative positional order. As a simple example consider a List of numbers that is maintaining their original elative positiona [ea r range daa wihout to be grouped into categories while l ordet Example Given the data set: 3 22 12 6 10 34 65 29 9 30 81 4 5 19 20 57 44 99 ategorize the data into four different group.s 1 to 9, 10 to 19, 20 to 29, and30 or mote The cesult is the categorized data: Categor l to 9 10 to 19 20 to 29 30 or more 12 10 19 22 29 20 34 65 30 8 57 44 99 ther a list categorized açcording The result is not a sorted list but ra to the specific requirements for the categories. group have kept their relative positional order. The numbers in each The underlying ADT for this application program is the ADT: Queue whose implementation has already been completed. Consequently, it should be possible to write this applica become involved with any "low level tion program without having to " data structure details. Prograiruning Notes This program should make use of the ARRAY IMPLEMENTATION of the ADT: queue This requires: struct QUEUE INFO RC i[30]; back; and the function prototypes / function definitions for create queueq) empty (qenque g, (q, i purge(q 2. For this application ion program, define INFO RC to be equivalent to the INFO data type int: typedef int INFO RC; Note this must be placed before the data structure declara QUEUEExplanation / Answer
#include <stdio.h>
#define MAX 50
int queue_array[MAX];
int rear = - 1;
int front = - 1;
main()
{
int choice;
while (1)
{
printf("1.Insert element to queue ");
printf("2.Delete element from queue ");
printf("3.Display all elements of queue ");
printf("4.Quit ");
printf("Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice ");
} /*End of switch*/
} /*End of while*/
} /*End of main()*/
insert()
{
int add_item;
if (rear == MAX - 1)
printf("Queue Overflow ");
else
{
if (front == - 1)
/*If queue is initially empty */
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
} /*End of insert()*/
delete()
{
if (front == - 1 || front > rear)
{
printf("Queue Underflow ");
return ;
}
else
{
printf("Element deleted from queue is : %d ", queue_array[front]);
front = front + 1;
}
} /*End of delete() */
display()
{
int i;
if (front == - 1)
printf("Queue is empty ");
else
{
printf("Queue is : ");
for (i = front; i <= rear; i++)
printf("%d ", queue_array[i]);
printf(" ");
}
}
#include<iostream.h>
#include<conio.h>
class queue
{
public:
int q[5],front,rear,x,result;
void enq();
void dque();
void disp();
queue()
{
front=0;
rear=0;
}
};
void queue::enq()
{
if(rear>=5)
cout<<" Queue overflow!! ";
else
{
cout<<" Enter the number to be inserted: ";
cin>>x;
rear++;
q[rear]=x;
cout<<" Number pushed in the queue:"<<q[rear];
}
}
void queue::dque()
{
if(rear==0)
cout<<" Queue underflow!! ";
else
{
if(front==rear)
{
front=0;
rear=0;
}
else
front++;
}
cout<<" Deleted element is:";
result=q[front];
cout<<result;
}
void queue::disp()
{
if(rear==0)
cout<<" Queue underflow!! ";
else
cout<<" Contents of queue is:";
for(int i=front+1;i<=rear;i++)
cout<<q[i]<<" ";
}
void main()
{
int c;
queue qu;
clrscr();
// cout<<" *****";
// cout<<" QUEUE";
// cout<<" *****";
do
{
cout<<" 1.Insertion 2.Deletion 3.Display ";
cout<<" Enter your choice:";
cin>>c;
switch(c)
{
case 1:
qu.enq();
break;
case 2:
qu.dque();
break;
case 3:
qu.disp();
break;
default:
cout<<" Invalid choice!! ";
}
}
while(c<4);
getch();
}
#include<conio.h>
#include<iostream.h>
#include<process.h>
# define MAX_SIZE 150
class queues
{
int front,rear;
int queue[MAX_SIZE];
public:
queues() // Constructor
{
front=(-1);
rear=(-1);
}
void insert_rear(int);
void delete_front();
void display();
};
void queues::insert_rear(int item)
{
if((front==0 && rear==MAX_SIZE) || (front==(rear+1)))
{
cout<<"Queue is full! Overflow";
getch();
exit(0);
}
else
{
if(front==(-1) && rear==(-1))
{
rear=0;
front=0;
}
else if(front!=0 && rear==MAX_SIZE)
rear=0;
else
rear=rear+1;
queue[rear]=item;
}
}
void queues::delete_front()
{
if(front==(-1) && rear==(-1))
{
cout<<"Queue is empty! Underflow";
return;
}
else
{
if(front==rear)
front=rear=(-1);
else if(front==MAX_SIZE && rear==MAX_SIZE)
front=0;
else
front=front+1;
}
cout<<" Item deleted.";
getch();
}
void queues:: display()
{
int ptr;
if(front==0 && rear==0)
{
cout<<"Queue is empty";
getch();
return;
}
cout<<" The queue is ";
if(front<=MAX_SIZE && rear<=front)
{
for(ptr=front;ptr<MAX_SIZE;ptr++)
cout<<queue[ptr]<<" ";
for(ptr=0;ptr<=rear;ptr++)
cout<<queue[ptr]<<" ";
}
else
for(ptr=front;ptr<=rear;ptr++)
cout<<queue[ptr]<<" ";
}
int main()
{
clrscr();
int length,i,element,choice;
queues q1;
while(1)
{
clrscr();
cout<<"1: Insert an item. 2: Delete an item.";
cout<<" 3: Display elements 4: Exit";
cout<<" Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"How many elements are in the queue: ";
cin>>length;
cout<<"Enter "<<length<<" elements: ";
for(i=0;i<length;i++)
{
cin>>element;
q1.insert_rear(element);
}
q1.display();
getch();
break;
case 2:
q1.delete_front();
q1.display();
getch();
break;
case 3:
q1.display();
getch();
break;
case 4:
exit(0);
break;
default:
cout<<"Please re-enter tour choice.";
getch();
break;
}
}
getch();
return(0);
}