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

c++ Using heaps and priority queues To do so, you must use Heaps and Priority Qu

ID: 3570636 • Letter: C

Question

c++ Using heaps and priority queues

To do so, you must use Heaps and Priority Queues.

The program will display a menu and prompt the user to enter a choice:

Printer queue
=========
1. Add job
2. Print job
3 View jobs
4. Exit
Enter choice:

You may assume the user enters 1, 2, 3 or 4. No input validation is required.

Add Job

If the user chooses Add job, then the program asks the user who is requesting the job:

Instructor (I or i)
TA (T or t)
Student (S or s)

You may assume that the the user enters I, i, T, t, S or s. No input validation is necessary.

The program then adds the print job to the priority queue. The data added reflects who the job is for (instructor, TA or student) and the number of the print job (an incrementing number, starting with 1, then 2, 3, 4, etc.). Hint: You may want to sue a structure.

Print Job

If the user chooses Print job, if there are any print jobs in the queue, then the program outputs, for the highest priority print job, who the job is for (instructor, TA or student) and the number of the print job. That print job also is removed from the priority queue. However, if there are no print jobs in the queue, then the program outputs: "No print jobs in queue."

View Jobs

If the user chooses Print job, then the program outputs, for each print job in the queue, and in order of priority, who the job is for (instructor, TA or student) and the number of the print job. However, if there are no print jobs in the queue, then the program outputs: "No print jobs in queue."

Explanation / Answer

#include <iostream>
#include <ctime>
#include <queue>


using namespace std;


void set_time ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}


int main()
{

int max=5,choice,Qnumber=0,Q=0;
char ans,x;
srand((unsigned)time(0));
queue<char>spool;
queue<char>spool1;

do
{
cout<<"********Queue Program********** ";
cout<<"1. Add ";
cout<<"2. Delete ";
cout<<"3. Current job ";
cout<<"4. Quit ";
cout<<"Enter Your choice : ";
cin>>choice;
if(choice==1)
{
do
{
do
{
if(Qnumber<max)
{
cout<<" Enter name of print job to Be Added : ";
cin>>x;
spool.push(x);
Qnumber++;

}
else
cout<<"Queue Full";
cout<<" Do you want to print more?[y/n]: ";
cin>>ans;
}while(ans=='y'||ans=='Y');

}while(choice=='y'||choice == 'Y');
}
else if(choice==2)
{
do
{
do
{
if(Qnumber!=0)
{
cout<<"Print Job "<<spool.front()<<" has been deleted"<<endl;
spool.pop();
Qnumber--;
}
else
{
cout<<"Queue Empty"<<endl;
}
cout<<"Want to Delete More[y/n]? ";
cin>>ans;


}while(ans=='y'||ans=='Y');

}while(choice=='y'||choice=='Y');
}
else if(choice==3)
{
if(Qnumber==0)
cout<<" Queue Empty!!";
else
{
cout<<" Displaying Queue ";
while(!spool.empty())
{
for(int d =1;d<=Qnumber;d++)
{
cout<<d<<". "<<spool.front()<<endl;
spool1.push(spool.front());
spool.pop();
}
}
while(!spool1.empty())
{
spool.push(spool1.front());
spool1.pop();
}
for(int d =1;d<=Qnumber;d++)
cout<<d<<". "<<spool.front()<<endl;
}
}
else if (choice==4)
exit(1);

cout<<" Want To Go To The Main Menu[y/n]? ";
cin>>ans;

/*srand((unsigned)time(0));
int n=(rand()%10)+1;
for(int j=n;j>0;j--)
{
set_time(1);
}*/
}while(ans == 'y'|| ans == 'Y');

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote