Spring 2006 - In-class exercise for 4/06/06
15 points
This exercise should be completed in pairs. The purpose of this exercise is to work with vectors and strings to implement the Search algorithm introduced in lecture. The following is a problem statement, and an analysis and design for the complete program in file inclass23.cpp.
Write a program that reads strings from a file, prints them to the screen one on a line, and searches for a target.
| Objects | Type | Kind | Name |
| Maximum characters in file name (80) | int | constant | MAX_FILE_NAME |
| Vector of strings | vector<string> | variable | names |
| Target to search for | string | variable | target |
| Position of target | int | variable | position |
0. Create a new project, then download file
inclass23.cpp from the course webpage under today's date to
your project folder. Also download file inclass23.dat into
the C:\WINDOWS folder (this is for KC-267 only, otherwise save
it in the project folder).
Build and run this program using inclass23.dat for
the input file. If it can't find your file, you might need to type
the full name of your file including the drive and folder path, or
move the file to the expected folder location.
Since the program doesn't actually search the vector, yet, it
will always say the target is not in the vector.
1. (9 points) Study the program in inclass23.cpp and
answer the following questions.
2. (6 points) Modify this program in the following way:
When you have completed this exercise, print out your program
file and turn it in with one copy of this exercise sheet with your
answers to the questions.