Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rules of Priority for Printer Queue Engineering #107 had only one printer. The instructor, the TA and students all sent their print jobs to this

Rules of Priority for Printer Queue

Engineering #107 had only one printer. The instructor, the TA and students all sent their print jobs to this one printer.

The print jobs were not done first in, first out (a queue). The instructor's favorite motto, from George Orwell's Animal Farm: "All animals are equal, but some animals are more equal than others."

Accordingly, student jobs were done first in, first out. But all TA print jobs were done before any student print job, with the TA's print jobs being done first in, first out. And you guessed it -- All instructor print jobs were done before any TA print job, with the instructor's print jobs being done first in, first out.

Your Task

Your job is to write the software to manage the printer queue. To do so, you must use Heaps and Priority Queues.

The program will display a menu and prompt the user to enter a choice:

Printer queue ========= 1. Add job 2. Print job 3 View jobs 4. Exit Enter choice:

You may assume the user enters 1, 2, 3 or 4. No input validation is required.

If the user chooses 4. Exit, then the program ends. The following discusses the other 3 choices.

Add Job

If the user chooses Add job, then the program asks the user who is requesting the job:

Instructor (I or i) TA (T or t) Student (S or s)

You may assume that the the user enters I, i, T, t, S or s. No input validation is necessary.

The program then adds the print job to the priority queue. The data added reflects who the job is for (instructor, TA or student) and the number of the print job (an incrementing number, starting with 1, then 2, 3, 4, etc.). Hint: You may want to use a structure.

Print Job

If the user chooses Print job, if there are any print jobs in the queue, then the program outputs, for the highest priority print job, who the job is for (instructor, TA or student) and the number of the print job. That print job also is removed from the priority queue. However, if there are no print jobs in the queue, then the program outputs: "No print jobs in queue."

View Jobs

If the user chooses Print job, then the program outputs, for each print job in the queue, and in order of priority, who the job is for (instructor, TA or student) and the number of the print job. However, if there are no print jobs in the queue, then the program outputs: "No print jobs in queue."

Number of Jobs

You could use a vector and just allocate elements dynamically. But if you want to use an array, you can choose a large number so you don't run out of job numbers.

Resources

The textbook covers Priority Queues and Heaps in Sections 9.1 and 9.2.

The Assignment #1 Information module on this class' CANVAS website contains a downloadable zip file of .h and .cpp files from which you can create a project which is a simple implementation (listing inputted numbers in descending order) of a priority queue and a heap. Please see the Template Classes module for how to run these files in a project. The Assignment #1 Information module also contains several handouts which explain Heaps and Priority Queues.

You also can post questions (or help others who post questions) in the discussion forum on this class' CANVAS website. Remember, you can post a few lines of code to provide context to your question, but please don't post all your code.

What You Turn In

Turn in to CANVAS (per the assignment submission instructions) a zip file of your .h and .cpp files, named as follows:

heap.h - declaration file for heap.

heap.cpp - implementation file for heap.

pqtype.h - declaration file for priority queue. pqtype.cpp - implementation file for priority queue.

test.cpp - driver file.

readme.txt or pleaformercy.txt (optional) - additional comments you wish to add.

Sample Input/Output

Here is sample input/output. After the first menu output, I have [menu output] instead of displaying the menu again to shorten the sample input/output. Printer queue ========= 1. Add job 2. Print job 3. View jobs 4. Exit Enter choice: 3 No print jobs in queue. [menu output] Enter choice: 2 No print jobs in queue. [menu output] Enter choice: 1 Instructor (I or i), TA (T or t), or Student (S or s)? s [menu output] Enter choice: 3 job #1: Student [menu output] Enter choice: 1 Instructor (I or i), TA (T or t), or Student (S or s)? i [menu output] Enter choice: 3 job #2: Instructor job #1: Student [menu output] Enter choice: 1 Instructor (I or i), TA (T or t), or Student (S or s)? t [menu output] Enter choice: 3 job #2: Instructor job #3: TA job #1: Student [menu output] Enter choice: 1 Instructor (I or i), TA (T or t), or Student (S or s)? i [menu output] Enter choice: 3 job #2: Instructor job #4: Instructor job #3: TA job #1: Student [menu output] Enter choice: 2 Now printing job #2: Instructor [menu output] Enter choice: 3 job #4: Instructor job #3: TA job #1: Student [menu output] Enter choice: 2 Now printing job #4: Instructor [menu output] Enter choice: 3 job #3: TA job #1: Student [menu output] Enter choice: 2 Now printing job #3: TA [menu output] Enter choice: 3 job #1: Student [menu output] Enter choice: 2 Now printing job #1: Student [menu output] Enter choice: 3 No print jobs in queue. [menu output] Enter choice: 2 No print jobs in queue. [menu output] Enter choice: 4 Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions