Project 14


The Projects

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

Extra: Also 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 #14.2: Use a stack to determine if a string is a palindrome (i.e., it reads the same backwards as forwards).

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

Project #14.4: Write a program that processes the endnotes in a file. In this file, the user uses [[...]] 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 end of the file is reached. Then output the endnotes.

Extra: 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.


Back to the Lab Exercise

Back to This Lab's Home Page


Report errors to Larry Nyhoff (nyhl@cs.calvin.edu)