Comp 116 Programming Assignment 07:
Weird Stacks and Queues

Due 11:59pm Wednesday, November 14 Saturday November 19 2018

This is an individual assignment. You must complete this lab on your own, although you may discuss lab concepts with other students. Please keep the Academic Integrity Policy in mind---do not show your code to anyone outside of the professors and ninjas, and do not look at anyone else's code for this lab. If you need help, please post a question on Piazza, or contact the professor.

The goal of this lab is to introduce you to review some of the concepts we have covered since the beginning of class and to prepare you for the first test. The concepts we review are:

Each problem is relatively short, but requires a bit of planning. The obvious solution could require a lightly longer program that needs to be written very carefully. A clever solution could require much less code and be much more straightforward to implement.

For each problem you have to solve, the solution should be written in a function that has the input / output behavior described in the problem.

Important: submit your solution to all problems in a single project called PrgAsst07. Each problem should have its own .h and .cpp file, and make sure that the names of the functions and classes, as well as the input / output behavior of the functions is exactly as described in this page.

Problem 1: Warmup — Text decoding

Write a function decodeText that two strings as input, an input file name, and an output file name, and returns nothing. The function should read the input file character by character, and decode it as follows:

The function should not skip whitespace, spaces and newline characters should be pushed on the stack like any other character. For example, a file containing the string "ta* **tse***" should be decoded to the string "a test".

After reading the entire input file, the decoded text should be written in the output file. However, your program should not crash or even open the output file if any of the following happen:

In any of the cases above, an appropriate message that described which of these errors has happened should be printed on screen.

You can find files that you can use to test your program here.

Problem 2: Weird Stack

Write a class WeirdIntStack that implements our stack ADT, but which is only allowed to use queues in the implementation. Your implementation is not allowed to use objects of any kind other than queues, and you are not allowed to use arrays. Integer-type variables are allowed.

The class should contain the following:

I also require that your implementation of pop and getTop run in $O(1)$ time. I have no other requirements on the other methods, except that they should not be unnecessarily slow.

If you want to use the STL implementation of queues, you should note that no assignment operator is implemented, so copies of queues must be made manually.

Hint: You should only need one queue in your class member variables, but some of your methods will require an additional queue as temporary storage.

Problem 3: Weird Queue

This problem is essentially a mirror image of the previous one. Write a class WeirdIntQueue that implements our queue ADT, but which is only allowed to use stacks in the implementation.

The class should contain the following:

I also require that your implementation of dequeue and getFront run in $O(1)$ time. I have no requirements on the other methods except that they should not be unnecessarily slow.

If you want to use the STL implementation of stacks, you should note that no assignment operator is implemented, so copies of stacks must be made manually.

Commenting and Coding Style Requirements

I will assign minor penalties for poor commenting and coding style.
Please review the Comp 116 Coding Style for good C++ style.