Lab Assignment #11 Solution

$30.00

Description

For this assignment you are to use the STL queue and priority queue classes. You can do this with #include <queue>.

Create a class for a single chore. This class will have two attributes, a string describing what the chore is, and a priority number, with the highest number being the item that is most urgent. Overload the < operator so that it returns whatever the comparison of the priority levels is. Your class should have input and output functions as well, allowing the chore and its priority level to be input from the keyboard and output to the screen.

Now in the main declare an STL queue of chore. (Note: You are declaring a queue of chores, not pointers to chores.) You will also need a temp chore to handle input. Now start a little loop and type in five chores, along with their priority level. This will involve calling temp.input(); (OR cin>>temp; // depending on how you’ve done your chore input), and then q.push(temp); Note that the queue only allows you to push to one end. Once you have finished your output loop have a loop that outputs all the chores in the queue.

cout<<q.front(); OR q.front().output(); // depending on how you’ve done your chore //output.
q.pop(); // removes that item from the queue.

Run this program while doing a script file:

script output1
a.out
// all of your interaction with the program
ctrl-d // ends the script

Now change your main to that you are declaring a priority_queue of type chore. You will also have to change “front” to “top” in the output. Now compile this version.

Run this program while doing a script file:

script output2
a.out
// all of your interaction with the program
ctrl-d //ends the script

When you compare the two script files you should see a different ordering of the chores, with the second being ordered by priority. Submit a copy of your final source code files along with both script files according to the instructions of your TA.