How to start a Printer queue?

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?
Last edited on
Your indentation sucks, so I'll say no.

> Write a program to simulate a printer queue
¿where's the simulation part?

> 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).
Nowhere say anything about a menu.

> node of the Priority Queue
You may want to use an array for the heap structure (children in 2*i+1, 2*i+2)
Or just use std::priority_queue http://www.cplusplus.com/reference/queue/priority_queue/


1
2
3
4
5
6
7
8
9
10
11
12
13
for( int K=0; K<1000; ++K ){ //a day
   job = add_job(); //26% return a (random) priority, else returns -1
   if( job.priority not_eq -1 )
      queue.push( job );

   for( auto &p: printers )
      p.work( queue );
}
//the day has ended, print jobs completed
for( auto &p: printers )
   p.print_report();
//unfinished jobs
show( queue );
note that the 20 units delay is missing, ¿does that count for the day or is it apart?
Last edited on
Topic archived. No new replies allowed.