Name: ____________________________________________________ Alpha: _____________________

1. [12pts] Assume the following declarations and function definitions. Next to each expression, write the type and value of that expression. Note: "error" is a possibility. Each question is independent, i.e. no side effects of one expression should be taken to carry over to the next
string s = "happy";
string foo() {
return "good";
}
char bar(string str) {
int i = str.length()-1;
return str[i];
}
  **expression**
s[1]

t[2] + 'A' - 'a'

foo() + 2.5

s[0] = t[0]

bar(foo())

foo()[3]
1. [88Pts] Write a program that reads a target string A and a test string S and tells the user whether A is a substring of S. A is a substring of S means that A appears (in order and together!) in S somwhere. For example: low is a substring of allowable (see it? "allowable"), but not of withhold (see the letters are there but not in order in "withhold"), nor in landowner (see the letters are there and in order but not together in "landowner"). A typical run of your program should look like this:

~/$./prog Enter target string: act Enter test string : reactionary The target act is a substring of the test string reactionary! ~/$ ./prog
Enter target string: ar
Enter test string  : reactionary
The target ar is a substring of the test string reactionary!
~/$./prog Enter target string: ryes Enter test string : reactionary The target ryes is not substring of the test string reactionary! Turn in a printout of your program, along with a screen capture showing it run on the above examples. Remember to make sure you never try to index a character outside of the string! Additional Examples: ~/$ ./prog
Enter target string: isp
Enter test string  : mississippi
The target isp is not a substring of the test string mississippi!
~/$./prog Enter target string: sip Enter test string : mississippi The target sip is a substring of the test string mississippi! ~/$ ./prog
Enter target string: issi
Enter test string  : mississippi
The target issi is a substring of the test string mississippi!
~/\$ ./prog
Enter target string: sss
Enter test string  : mississippi
The target sss is not a substring of the test string mississippi!

Hint: It's not a bad idea to start off by trying to determine if a target string A matches a test string S starting at index i of S. So that, for example, if A="the" and S="other" you wouldn't find a match starting at index 0 of S, but you would find a match starting at index 1 of S.