Starting from:

$35

CSE030-Lab 10 Queues Solved

(Exercise 1)  
In this part of the lab, you will be implementing your own Queue class, comprised of a class declaration (Queue.h) and class definition (Queue.cpp).  You will also create a

simple main program to test your queue class (Exercise1.cpp).  This part of the lab will use int as the type for elements in the Queue (Linked List nodes). Similar to your stack implementation in Lab#11, your Queue class will inherit the LinkedList class so that any functions available inside the LinkedList class can be used by the Queue class.  Take a look at the Inheritance_example_files from lecture to see how to use inheritance.  As you will see when you implement the Queue class, inheriting the LinkedList class will make this part of the lab very simple.  Your Queue class will be comprised of the following functions, which you need to implement (note that the Queue class does not need any variables, since those from the inherited LinkedList are all you need):

•       Default Constructor (Queue()): does nothing

•       Destructor (~Queue()): does nothing

•       void enqueue(int value): inserts a new element (value) at the back of the Queue, by calling the appropriate LinkedList function.

•       int dequeue(): removes the first element of the Queue, by calling the appropriate LinkedList function. It also returns the value of the element that has been dequeued.

•       int& front(): returns a reference to the front element of the Queue.

You also need to create your own main program (Exercise1.cpp) to test the various Queue functions:

•       Create a queue of at least 10 elements in your main program and call various member functions to manipulate the queue (as you have seen in your HW2 problem).

•       Call enqueue to insert integer to the queue

•       Call front to return to the front of the queue

•       Call dequeue to remove elements from the queue

•       Check the size of the queue by calling a function inherited from Linked List.

•       Check if the queue is empty by calling a function inherited from Linked List.

•       Print the content of the queue by calling a function inherited from Linked List and verify if the member functions work correctly.

Note:

•       Your Queue implementation should be very simple and short. It will be similar to your implementation of Stack in Lab#11. Remember that since you are inheriting the LinkedList class, you can call any functions/variables that were defined inside the LinkedList class.

•       Unlike your Stack implementation in Lab#11, you must generate exceptions where appropriate: you should throw exceptions in both dequeue and front functions whenever these functions would fail.  You will need to catch the exceptions and print the following error messages if an exception is generated: “Call to front() generated an exception, because the queue is empty” OR “Call to dequeue() generated an exception, because the queue is empty”

o   You should throw an exception (an integer value) inside the appropriate Queue’s functions.  (i.e. in Queue.cpp)  See the online tutorial in exceptions for examples on how to implement exceptions.  All you need to do is to throw an integer value when an error arises.


o   For each call to the dequeue and front functions, you should try to catch the exception (the integer value thrown from the functions) in the main file (Exercise.cpp) and print the appropriate error to the screen.   

 

  

(Exercise 2)  
In this part of the lab, you will make the following changes to the code developed in Exercise 1:

•      Change your Queue and Linked List classes so that they use char type instead of int.  Name them Queue_char.h/Queue_char.cpp and LinkedList_char.h/ LinkedList_char.cpp to avoid the confusion between the classes created in Exercise 1. 

•      Create a main program (Exercise2.cpp) to produce the following output similar to what was illustrated in the lecture.   

•      You do not need to produce the table lines, but need to use tabs in between columns and newlines for each row.  Columns do not need to be aligned between rows.  

More products