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 astack
to figure out if astring
is a palindrome (i.e., it's reads the same backwards as forwards).
Project #15.3: Use astack
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 thestack
.
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 aqueue
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 with1.
in the list of endnotes. In general, for the ith[[
...]]
, output[i.]
in the document text and label the endnote withi.
in the list of endnotes.
Turn the following things: