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

Hi I need help with this c++ programming homework and this program is about the

ID: 3601311 • Letter: H

Question

Hi I need help with this c++ programming homework      and this program is about the queue and also tho s project should make a use of the array implementation. Also all other instructions are on the attached photo please read that and don't copy and past from old work. please try to explane the code. thank you.


ezogtanming Assiment Abstract Uata Type Oueue Application Categoriaing Data e toblem Specification Categorizing data: it is often necessacy to ceatrange data without destcoying their relative positional order. As a simple example. consider a list of numbees that is to be grouped snt.o categories white maintaining their original relative pos Example: Given the data set: 322 12 6 10 34 6529 9 30814519 2574499 We want to categorize the data into four different groups 1 to 9, 10 to 19. 20 to 29, and 30 oc moe The r sult is the categorized data: 1 to s 10 to 19 20 to 29 30 or more 12 10 19 22 29 20 34 65 30 81 57 44 99 The result is not a sorted list but cather s list eategorized according to the specific requirenents for the categories. The numbers in each group have kept their relative positional order The underlying ADT tor this application program is the ADT: Queue Hhose implementation has already been completed. Consequently, it should be possible to write this application progtam without having to become involved with any "lou level" data structure details. . This program should nake use of the ARRAY IMPLEMENTATION of the ADT: queue This requires struct QUEUE I INO RC i1301 int back; and "the function prototypes tunction definitions for: create-queue (q, empty(qi enque (q, deque (q, L) purge(q) 2. For this application program, define INFO RC to be equivalent to the data type int: typedef int INFO RC: Note: this must be placed betore the data structure declaration tor QUEUE.

Explanation / Answer

#include <iostream>
#include<fstream>
using namespace std;

typedef int INFO_RC;

//create a queue structure
struct QUEUE {
INFO_RC i[30]; //array to store the queue element
int back1; //index to keep track of last element(rear)
};

typedef struct QUEUE q;

//initialise the queue
void create_queue(q& queue1)
{
queue1.i[0] = 0;
queue1.back1 = 0;
}

//Add elements from back of queue
void enque(q& queue1, INFO_RC item)
{

if(queue1.back1 == 30)
{
cout<<"queue is full";
}
else {

//insert the value at the end of the queue and increment the back;
queue1.i[queue1.back1] = item;
queue1.back1++;
}
}

//return the front element
int deque(q & queue, int front)
{
return queue.i[front];
}

//create queue of initial data set
void form_queue(q & data)
{
int no_item, item;
//initialise data queue
create_queue(data);
cout<<"Enter number of elements in the data set"<<endl;
cin>>no_item;

cout<<"Enter the data set"<<endl;
for(int i = 0; i < no_item; i++)
{
  
cin>>item;
enque(data, item);
}

}

//check if queue is empty
bool empty(q & queue1, int front)
{
//if front index is greater than or equal to back index queue is empty;
if(front >= queue1.back1)
return true;
return false;
}


//print the output to a file
void print_queue(ofstream & ofs, string name , q & queue)
{
ofs<<name<<":";
int index = 0;
  
//remove element from queue and write it to a file
while(!empty(queue,index))
{
int item = deque(queue,index);
ofs<<" "<<item;
index++;
}
ofs<<endl;
}
int main()
{
q data;
form_queue(data); //create a queue for data set

// Initialise the category queues
q q_1_9, q_10_19, q_20_29, q_30_more;
create_queue(q_1_9);
create_queue(q_10_19);
create_queue(q_20_29);
create_queue(q_30_more);

int index = 0; //index to keep track of front of the queue
while(!empty(data, index))
{
int item = deque(data, index);
if(item >= 1 && item <= 9)
enque(q_1_9, item);
if(item >= 10 && item <= 19)
enque(q_10_19, item);
if(item >= 20 && item <= 29)
enque(q_20_29, item);
else
enque(q_30_more, item);
index++;
}

// write the output to a file
ofstream ofs;
ofs.open("output.txt");
print_queue(ofs, "1 to 9", q_1_9);
print_queue(ofs, "10 to 19", q_10_19);
print_queue(ofs, "20 to 29", q_20_29);
print_queue(ofs, "30 to more", q_30_more);
ofs.close();
return 0;
}