Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10pts] Assume the following delcarations and function definitions fill in the table. Note: "error" is a possiblity in the 2nd column. Note: each question is independent, i.e. no side effects of one expression shoudl eb taken to carry over to the next
    string s = "happy";
    string t = "sad";
    string foo()
    {
      return "good";
    }
    char bar(string str)
    {
      int i = str.length()-1;
      return str[i];
    }
    
    expressiontypevalue (or error!)
    s[1]
    t[2] + 'A' - 'a'
    foo() + 2.5
    s[0] = t[0]
    bar(foo())
  2. [90Pts] 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: 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 example. Remember to make sure you never try to index a character outside of the string!