This week's project is a single person project. The project is to:
Professor Y.R. Teop from the English Department specializes in the study of Reverse Poems, which are poems that can be read either backwards or forwards, usually with significant changes to their meanings. For example, here is a poem titled Love?, whose author is unknown:
Love? Anonymous I don't love you anymore... I would be lying if I said That I still love you the way I always did. I'm sure Nothing was in vain. And I feel inside of me that You mean nothing to me I could never really say that Our time together matters. I feel more and more that I'm forgetting you... And I will never use the phrase I love you. I'm sorry but I must tell the truth.Reading the poem top-to-bottom produces one meaning, but reading the poem bottom-to-top produces a quite different meaning. However, actually reading the poem from bottom to top is clumsy and inconvenient.
Prof. Teop wants us to write a program that will make it easier to compare the forward and backward versions of a poem. Here is a program to do so:
/* main.cpp * ... */ #include "ReversePoem.h" #include <iostream> using namespace std; int main() { cout << "\nEnter the name of the poem file: "; string poemFile; cin >> poemFile; ReversePoem reversePoem(poemFile); cout << reversePoem.getTitle() << "\n" << reversePoem.getAuthor() << "\n" << "\n*** Top-To-Bottom ***\n\n" << reversePoem.getBody() << "\n*** Bottom-To-Top ***\n\n" << reversePoem.getBodyReversed() << endl; }To illustrate its execution, a sample run of the program might behave as follows:
Enter the name of the poem file: poems/love.txt Love? Anonymous *** Top-To-Bottom *** I don't love you anymore... I would be lying if I said That I still love you the way I always did. I'm sure Nothing was in vain. And I feel inside of me that You mean nothing to me I could never really say that Our time together matters. I feel more and more that I'm forgetting you... And I will never use the phrase I love you. I'm sorry but I must tell the truth. *** Bottom-To-Top *** I'm sorry but I must tell the truth. I love you. And I will never use the phrase I'm forgetting you... I feel more and more that Our time together matters. I could never really say that You mean nothing to me And I feel inside of me that Nothing was in vain. I'm sure That I still love you the way I always did. I would be lying if I said I don't love you anymore...
The problem is that the ReversePoem class does not exist. Your task is to complete the program for Prof. Teop by building the ReversePoem class that the preceding program uses. In terms of methods, you will need to define:
As with your Stack methods, you are to use test-driven development to create these methods and build an automated unit test to test each method. For that purpose, here is a very simple reverse poem:
Cats Leo J. Smada I love it when cats rub against me. I could never say I hate those furry felines.You may assume that each reverse poem begins with its title on one line, its author on the next line, then a blank line, and finally the body of the poem.
To achieve the desired performance, your ReversePoem() constructor should use your Stack template to solve this problem. To do so, your constructor will need to read the body of the poem from the input file one line at a time, push those lines onto your stack (which should be a local variable), and pop them from the stack in reverse order.
The twist is that in order for your ReversePoem constructor to handle poems of arbitrary sizes, you are to define your stack with an initial capacity of 1 and "wrap" your push() calls in a try-catch block. If push() throws an exception (i.e., because the stack is full), your exception-handler code should:
To help with your final testing, here are several reverse poems that you can use to try out your project. You can avoid cluttering your project by making a folder within your project named poems, and storing all of these poems within that folder.
If you get to the point where you cannot figure out what is wrong, practice and develop your skills using the debugger!
Create a script file in which you use ls to list all your project's files, use cat to display the contents of each file, and build+run your project to demonstrate that it works correctly. Make certain that your script file is located in your project folder.
Our grader will grade your submission based on the categories given in this grade sheet, so you should make certain all of those categories are covered.