i am given an assignment with the following requirements
Assume that a major printer company have outsourced their printer spooling software to your group. You are tasked to write software that spools the print requests from users and send it to the printer. Assume that there are only one printer and few users sharing it, and printing is based on First Come First Serve basis. The software has a menu to simulate users sending the print job to the printer and the printer finish the print job randomly, ranging from 1 second to 10 seconds. Assume that the printer has a limited buffer and any subsequent print job added will be returned back to the sender and a message printer buffer full will be prompt. At anytime, the printer will display the current printing job spool. Any print job that have remained in the print queue that have exceed the maximum holding time need to be discarded. You are free to assume STL Queue as the data structure, and any other parameter declared. State any assumptions in the report.
how do i implement the program using class and queues and ctime ?
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**********\n";
cout<<"1. Add\n";
cout<<"2. Delete\n";
cout<<"3. Current job\n";
cout<<"4. Quit\n";
cout<<"Enter Your choice : ";
cin>>choice;
if(choice==1)
{
do
{
do
{
if(Qnumber<max)
{
cout<<"\nEnter name of print job to Be Added : ";
cin>>x;
spool.push(x);
Qnumber++;
}
else
cout<<"Queue Full";
cout<<"\nDo 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;
I have a few comments:
1. A queue knows if it's empty. You can call spool.empty() rather than using a seperate variable, Qnumber to track the number of items in a queue. You can find out how many items there are in a queue by calling spool.size().
2. Rather than holding a queue of just job names, a single char in this case, you can define a class that has a name and other details like time and so on, and have a queue of those.
If you wanted to use a name rather than just a char, you'd use a string. But if you wanted to add other information, you'd just add the fields as necessary.
Also, you don't have to use a class to represent a record, you can use struct. For example, if you wanted a record that contained an id, a name and the job time in seconds you might have: