Week 13 Lab
Q&A on Material
- Strings: character arrays (cstrings) vs. the standard string
- Substring function (first example of function overloading)
- Lexicographical comparison using string
- String size function
Sign in to lab!
Homework Questions or help
If you have general questions about HW11 and approaches to solving it please discuss as a group. If you have more specific questions, please wait for individual Q&A at the end of the session.
Exercises
Walk through these exercises and complete them as a group (if time allows):
cpp/cs102/practice12/letterReplace
cpp/cs102/practice13/stringTF
cpp/cs102/practice9/forCapitalization
cpp/cs102/practice13/secretAgent
Tracing Exercise
Try this tracing exercise at home when you study.
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char input);
bool isConsonant(int input);
bool isNumeral(int input);
int main()
{
string str1 = "2019 is finally the year of the Clippers";
string str2 = "";
for (int i = 0; i < str1.size(); i++)
{
if( isVowel( tolower(str1[i])) )
{
str2 = str2 + "_";
} else if ( isConsonant( (int) tolower(str1[i])) )
{
str2 = str2 + str1[i];
} else if ( isNumeral((int) str1[i]) )
{
str2 = str2 + "#";
} else
{
str2 = str2 + " ";
}
}
cout << str2 << endl;
return 0;
}
bool isVowel(char input)
{
return (input == 'a') || (input == 'e') || (input == 'i') || (input == 'o') || (input == 'u');
}
bool isConsonant(int input)
{
return (input > 97) && ( input < 123) && ( input != 101) && ( input != 105) && ( input != 111) && (input != 117);
}
bool isNumeral(int input)
{
return (input >= 48 ) && (input <= 57);
}
Open-ended Help
Any students with questions may stay after to get help. Anyone else may leave at this stage.