Spring 2006 - Programming Project 5
20 points
Out: March 15, 2006
Due: March 22, 2006
This project consists of writing two short applications, one
that uses STL vectors and STL lists and one that uses STL stacks.
A side note regarding syntax: normally the compiler does not care about whitespace in instantiating a template class, so to declare a vector of lists of strings, we might type:
vector <list <string>> vectorOfStringLists;But when we do this, the compiler will interpret the ``»'' as an attempt to use the input operator. So when you instantiate a template class with another template class, you must put a space between the two >'s and type:
vector <list <string> > vectorOfStringLists;
This program must take two command-line arguments, the input file name and the output file name. You will write your own test files. You must submit 1 non-trivial test file. By non-trivial, we mean a test file of at least several lines, with words beginning with a variety of letters, and with duplicates. Please note that there should be no punctuation, no digits, and no lowercase. Name this file sampletext.txt.
(10 points) Using a stack, write a program in the file
match.cpp that reads (non-whitespace) characters one at a
time from a file, and determines if the delimiter pairs ( ),
{ }, and [ ] in the file match up properly. (I.e., it
ignores all other characters.) Delimiters match properly if, for each
left delimiter, there is a corresponding right delimiter, and the
pairs are properly nested. For example,
([ ]{( )}) - delimiters match
([{ ]( )}) - delimiters do not match
([ ]{( )} - delimiters do not match
[ ]{( )}) - delimiters do not match
Where d1 is the current delimiter being considered and
d2 is the delimiter that is expected. For the second example
above, the mismatch occurs when the ] is read and a }
is expected (to match the preceding {), so the output for this
example should be:
Mismatched delimiter ] found. Expecting delimiter }.The program should exit when this occurs.
This situation occurs in the third and fourth examples above. Note that d could be either a left or right delimiter. For the third example,the output would be:
Extra delimiter ( found.For the fourth example, the output would be:
Extra delimiter ) found.The program should exit when this occurs.
This program must take one command line argument, the input file name. You will write your own test files. You must submit 2 non-trivial test files, one where the delimiters match and one where the delimiters do not match. By non-trivial, we mean a test file larger than the examples above, including characters other than the delimiters, and of more than one line. Name them matched.txt and unmatched.txt, respectively. One input test file you might try is a very simple C++ source file without comments or string literals. (Properly written C++ code should have matched delimiters. However, it is possible to have unmatched delimiters in comments and string literals.)
You are not required to submit a makefile for either program.
Submit a tarfile containing concordance.cpp,
sampletext.txt, match.cpp, matched.txt, and
unmatched.txt. Turn in a hardcopy of
concordance.cpp and match.cpp (only).
Follow the guidelines in the C++ Programming Style
Guideline for CS 215 handout. As stated in the syllabus, part of the
grade on a programming project depends on how well you adhere to the
guidelines. The grader will look at your code listing and grade it
according to the guidelines.
REMINDER: Your project must compile for it to be
graded. Submissions that do not compile will be returned for
resubmission and assessed a late penalty.