Saint Louis University |
Computer Science P125
|
Dept. of Math & Computer Science |
Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
The C++ string class is a very useful one indeed. It offers a very convenient way to represent a sequence of characters as well as many useful associated utility methods. One such method that we have already discussed is the method find which was used to find the leftmost occurrence of a pattern in an existing string, even when constrained to the portion of the existing string starting at a given index. If no such occurrence exists, this is denoted by a special return value.
Of course there was a time before the C++ string class existed, more notably before the language C++ existed. The C++ language is an extension of an earlier language known as C. In C, character strings are represented more directly as an array of characters. In fact, even in C++ the writers of the string class still use an array of characters behind-the-scenes. These are typical referred to as C-style strings in contrast, and are discussed in our text in Chapters 2.7.1 and 9.2.4.
In this assignment, we are going to have you write code to implement a routine such as find, but directly using an array of characters to represent the original string and the pattern to be found. This should give you a taste of what it would be like to live without the C++ string class (or to have been an original designer of that class).
Your task will be to implement a function with the following syntax and semantics:
Your goal is to find the first occurrence of the pattern starting at an index greater than or equal to startIndex in the given text. You are to return the starting index in the text where such a pattern begins. In the case where no such occurrence exists, you are to return the integer value -1.int find(char text[], int textLength, char pattern[], int patternLength, int startIndex)
For example, given the text: "
You are responsible for ensuring that your code works correctly with all legitimate inputs. Please make sure to spend ample time testing your program in a variety of settings.
To aid you in testing, we will provide you with a main routine that prompts the user for a piece of text and a pattern, and then finds all occurrences of the pattern in the text based on a series of calls to your routine. Please keep in mind that your routine is only responsible for finding one occurrence per call.
You will need a single file find.cpp which contains our main routine and a prototype for the function which you must complete. You may either download the file via a browser, or else copy it directly to your current directory on turing with the command:
cp -Rp ~goldwasser/csp125/programs/find .
find.cpp
This is the source code file which you must complete.
Again, we also ask for you to estimate the amount of time you spent on the assignment, and to let us know of any difficulties you had or other issues you wish to discuss.
The assignment is worth 10 points.
coming soon...perhaps something about search and replace