Assignment 2, due Thursday February 3 at noon.

You must submit your program electronically via gsubmit on csa.

 Under no circumstances will late assignments be accepted.

 The code you submit must conform with the programming guidelines.


Program Description

Submit one file called find.cpp.  In this file write a one function

int find(string s, string t)

that employs a recursive algorithm to test whether the string t is contained in the string s. If so, it returns the offset of the first match. If not, it returns -1. For example,

find("Mississippi", "is") returns 1.
find("Mississippi", "Miss") returns 0.
find("Mississippi", "pi") returns 9.
find("Mississippi", "hip") returns -1.

Hint: If t is longer than s, you can return -1 with confidence.  Otherwise, compare t and the initial substring of s with t.length() characters.  If those are the same strings, then return 0. Otherwise call the function recursively with the tail of s (that is, s without the first character).

Note: Only submit the function int find(string s, string t) in find.cpp.  Do not submit a program main().

Note:: You cannot add input arguments, change types, or otherwise make changes to the function interface as defined in the prototype: int find(string s, string t);.


Program Wrapper

To help you get started, here is a main program, debugging function, include file, and Makefile:

main.cpp
print_find.cpp
funcs.h
Makefile

 Here is a wrapper function.

 find.cpp

 Modify this wrapper, filling in the missing pieces needed to complete the assignment.

You are responsible for thoroughly testing your program to make sure that it works. In grading your program, we will test your program on some standard tests. 

Grading Criteria

Refer to the grading criteria file: p2.criteria


Academic Honesty and Collaboration

Cooperation is recommended in understanding various concepts and system features. But the actual solution of the assignments, the programming and debugging must be your individual work, except for what you specifically credit to other sources. (Your grade will be based on your own contribution.) For example, copying without attribution any part of someone else's program is plagiarism, even if you modify it and even if the source is a textbook. The University takes acts of cheating and plagiarism very seriously: first time violators are routinely suspended for a semester.