Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
string s = "happy";
string t = "sad";
string foo()
{
return "good";
}
char bar(string str)
{
int i = str.length()-1;
return str[i];
}
bool mkcap(char& c)
{
if ('a' <= c && c <= 'z')
{
c = c - 'a' + 'A';
return true;
}
return false;
}
| expression | type (or error!) | value (or error!) |
s[1] | ||
t[2] - 'a' + 'A' | ||
foo() + 2.5 | ||
s[0] = t[0] | ||
bar(foo()) | ||
foo()[3] | ||
bar(s[0]) | ||
mkcap(s) | ||
mkcap(s[0]) | ||
mkcap(s[0] + t[0]) |
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!
Important 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.
Turn in This page, and 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! Also submit via the submit script as:~/bin/submit -c=IC210 -p=Hw20 hw20.cppPlease fill in: After submitting my hw, I passed ______________ (all/some/none) of the tests.
~/$ ./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!