Hands On C++: Project 15


The Projects

Your instructor will assign you one of the problems below. To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Following the pattern in the lab exercise, first, design using OCD; then code your design in C++ using stepwise translation; finally, test your program thoroughly.

Project #15.1: Write a program that reads in text from a file and tests to see if the parentheses are well balanced---that is, for every left parenthesis '(' there's always one close parenthesis ')' afterwards. Use a stack to keep track of the left parentheses.

For some extra fun, balance curly braces, square braces, and angle braces (i.e., < and >) as well, making sure the type of right brace matches the left brace you pop off.

Project #15.2: Use a stack to figure out if a string is a palindrome (i.e., it's reads the same backwards as forwards).

Project #15.3: Use a stack to print out the "palindrome" of each word in a file. ("The palindrome of 'Bolton' is 'Notlob'!") Read the file word by word, and for each word, reverse it using the stack.

Project #15.4: Write a program that processes the endnotes in a file. In this file, the user uses the text [[...]] to indicate that the text between the braces is an endnote, and should actually appear at the end of the file. Read in the file, and output immediately all of the normal text. For each endnote, store it in a queue until the entire input has been read in. Then print each endnote.

For some extra fun, automatically insert endnote numbers: for the first [[...]], output [1.] in the document text and label the endnote with 1. in the list of endnotes. In general, for the ith [[...]], output [i.] in the document text and label the endnote with i. in the list of endnotes.

Turn In

Turn the following things:

  1. This grade sheet.
  2. Your OCD.
  3. Your source program.
  4. The output from an execution of your program.


Lab Home Page | Lab Exercise
© 2003 by Prentice Hall. All rights reserved.
Report all errors to Jeremy D. Frens.