Please need help !!!

This exercise addresses queues, I need help. In this example, we have will use an array to implement a circular queue, that is, wrapping the queue around when you reach the end of the array instead of shifting elements. Suppose the array represents a queue of print jobs for the lab printer. Each item in the queue contains the following items of information: the user_id, the size of the job, and the text to be printed. The information will be read from a file, called "printjobs.txt" whose format looks like the following (obviously the text to be printed is artificially severely reduced and will be no more than 100 characters). The # is used as a delimiter between the different pieces of information for one job. You should construct such a file to test your program.

vcs#100#Assignment 1 for data structures ............. DUE Monday Sep 15.
ra#50#Mail from the dean................................... Respond soon.
ks#250#List of students in CSC .............................300 in total.
vcs#300#....
vcs#200#....
ks#500#....
ra#1000#....
tr#300#...
tr#350#...
tr#200#...
dw#100#....
dw#150#....
dw#100#....
...

Your program is driven by a simple simulator that uses the random number generator (rand) to generate the numbers 0 to 3, with the following meanings:
• 0 means remove a print job from the queue and print. If the queue is empty, your program should print so and continue generating random numbers until a non-zero number is obtained.
• 1, 2, 3 mean read 1, 2, and 3 jobs from the file respectively. If the queue has room, you actually read the specified number of jobs from the file and enqueue them in the order in which they are read from the file. If the queue does not have room, then only read as many as you can enqueue. Then print that the queue is full and continue generating random numbers until a 0 is obtained and you can dequeue a job.
The program alternates between generating random numbers and trying to carry out the action corresponding to the number generated. The interaction should look something like this, assuming your queue can only accommodate MAXQUEUE = 10 elements. The queue starts out empty.

Generated 0:
No jobs in print queue
Generated 1:
Added JobId = 001, UserID = vcs, Size = 100
Queue contains 1 element
Generated 2:
Added JobId = 002, UserID = ra, Size = 50
Added JobId = 003, UserID = ks, Size = 250
Queue contains 3 elements
Generated 0:
Printing JobId = 001, UserID = vcs, Size = 100
Queue contains 2 elements
Generated 3:
Added JobId = 004, UserID = vcs, Size = 300
Added JobId = 005, UserID = vcs, Size = 200
Added JobId = 006, UserID = ks, Size = 500
Queue contains 5 elements
Generated 2:
Queue is full.
Generated 1:
Queue is full.
Generated 0:
Printing JobId = 002, UserID = ra, Size = 50
Generated 1:
Added JobId = 007, UserID = ra, Size = 1000
Queue contains 5 elements

And so on, until you reach the end of the "printjobs.txt" file. At that point your program can take a rest.
You should use a constant DEBUG that you define at the top of your program like this:

#define DEBUG 0 // takes the value 0 or 1

When DEBUG has value 0, your program runs as above. When it has value 1, in addition to the above output, it tells you information about the current position of the front and the rear of the queue.
Topic archived. No new replies allowed.