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.
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.