Starting from:
$35

$29

Homework 3 Solution

The goal of this homework is get you familiar with protected/private inheritances and their alternatives.

    1. You need to implement a double queue class that hold strings. Your double queue class should allow the insertion of data from both left and right, and the deletion of data from both left and right.

    2. You need to implement a stack class that privately inherit from the double queue class.

Your stack class should only allow the insertion of data from the left and the deletion of data from the left. Your class should have at least three functions: push, pop, and top.

    3. You need to implement a queue class that has a data member of your double queue object. Your queue class should only allow the insertion of data from the left and the deletion of data from the right. Your class should have at least three functions: push, pop, and full.

    4. In your main functions, you should have the following code:

    (1) Instantiate a double queue object, insert 5 strings, namely “string1”, “string2”, “string3”, “string4”, and “string5”, from the left, and insert 3 strings, namely “string6”, “string7”, and “string8”, from the right, remove all strings in the double queue from left to right, and print all strings in the order that they are removed, which should be “string5”, “string4”, “string3”,
“string2”, “string1”, “string6”, “string7”, “string8”.

    (2) Instantiate a stack object, insert 4 strings, “string100”, “string200”, “string300”, and “string400”, then remove all strings in the stack, and print all strings in the order that they are removed, which should be “string400”, “string300”, “string200”, “string100”.

    (3) Instantiate a queue object, insert 4 strings, “string10”, “string20”, “string30”, and

“string40”, then remove all strings in the queue, and print all strings in the order that they are removed, which should be “string10”, “string20”, “string30”, “string40”.



Turn in one file via handin: the zip file of your whole NetBean directory. The name of your file should be: LastName_FirstName. For example, if your name is John Smith, you should turn in a file named Smith_John.zip.

More products