CSCI 1300 - Extra Credit Program 3
Who Is the Mole?

This is an extra credit assignment worth a small amount of extra points (25). You should do this assignment if you finished the other work quickly. If you do not have time to do this work, don't worry because there will be many future opportunities to pick up a small amount of extra points if needed. Last day to submit this to Dora is Tuesday, Sep 17. No late work accepted.


Warning: This extra credit work must be done entirely on your own. It is like a take-home exam. You cannot talk with anyone except the instructors, nor use other students' work. As such, if you choose to submit this work, you will be asked to accept the Student Honor Pledge:

"On my honor, as a University of Colorado at Boulder student, I have neither given nor received unauthorized assistance on this work."

Even one violation of this Honor Pledge will result in a grade of F for the entire course and possible additional sanctions from the campus Honors Code Committee.


Extra Credit Program 3:

The purpose of this assignment is to make sure that you know how to write a program that contains functions that meet specific requirements. WARNING: Your work will receive no points if you solve the problem without implementing the two required C++ functions listed below (two versions of a C++ search function, one with a return value of bool and one with a return value of int). Moreover, your functions must work correctly for any valid arguments (not just for the particular numbers that your main program uses).

For the assignment, write a program that a person can use to search through a name to see whether the letters of some other word appear in order (but not necessarily consecutively) within the name. The program should ask for the name (with no spaces), then ask for the word, and then print a message indicating whether the letters of the word appear in order within the name. For example:

Please type a name with no spaces: monicalewinsky
Please type a word: mole
Answer: Yes, the word mole appears in order within monicalewinskey
The reason for the Yes answer is because the name monicalewinskey contains at some point: an m, and then later there is an o, and then later there is an l, and later there is an e. If the name does not contain the letters of the word in order, then a negative message is printed. For example:
Please type a name with no spaces: michaelmain
Please type a word: chile
Answer: No, the word chile does not appear in order within michaelmain
At the end of each computation, the program should ask the user whether he or she wants to continue (doing another computation).

Your program must include functions with these exact prototypes. Notice that both functions are called search. That is permitted so long as the functions have different parameter lists.

   int search(string name, char c, int start_position);
     // This search function starts at the given start_postion of the
     // name and searches for the first occurrence of the character c.
     // If it finds the character c, then the return value is the
     // position of that c within the name. If it does not find the
     // character c, then the return value is -1.
     // Remember that the position of the first string character is
     // always zero (not 1), so for example:
     //    search("michaelmain", 'm', 0) returns 0
     //    search("michaelmain", 'm', 4) returns 7
     //    search("michaelmain", 'm', 10) returns -1

   bool search(string name, string word);
     // This search function checks to see whether the letters of the word
     // appear in order (but not necessarily consecutively) in the name.
     // If so, then the function returns true; otherwise the function 
     // return false.
     // Two special cases that you want to be sure to test:
     // (1) If the word is the empty string (with no characters), then
     // the answer is always true. (2) If the name is empty but the word
     // is not empty, then the answer is always false. Here are examples:
     //    search("monicalewinsky", "mole") returns true
     //    search("michaelmain", "chile") returns false
     //    search("michaelmain", "") returns true
     //    search("", "chile") returns false
     //    search("", "") returns true

Hints: