Write a program to simulate a printer queue (priority queue or heap – Bentley article has code)
where 3 printers are “fed” by this queue. Each print job has an unchanging priority and higher
priority jobs go first (although once started, a job isn't stopped to let a higher one go). For each
unit of time, there is a 26% probability that a job will be added to the queue and all jobs take 8
time units to complete. Print job priorities are between 5 and 100. The queue opens 20 time units
prior to the start of printing for adding print “jobs”. A print “day” is 1000 time units.
The output from your program is:
1) A list of jobs completed with their priorities for each printer
2) A list of jobs not completed (if any).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "priorityQueue.h"
using namespace std;
int main()
{
//local declarations
int option,priority;
PriorityQueue pq;
char ch;
string jobName;
int number = 0;
do
{
cout << "1.Completed Jobs\n";
cout << "2.List of uncompleted Jobs\n";
cout << "3.Exit\n";
cout << "Enter your option : ";
cin >> option;
switch(option)
{
case 1:
break;
case 2:
break;
case 3:
break;
default :
cout << "Wrong option\n";
}
}
while(option != 4);
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
// node of the Priority Queue
struct node
{
//local declarations
int priority;
int snumber;
string jobName;
struct node *next;
};
//PriorityQueue
class PriorityQueue
{
private:
node *front;
//constructor
public:
PriorityQueue()
{
front = NULL;
}
|
Am I doing this right so far?