cp ~dbennett/230/hw2/doit .
sh doit ./palindrome
void OpenFile(ifstream & infile){
void Foo(string dogName, int dogAge, float dogCost); void Foo(string,int, float);
string s; cout << s.size()-1 << endl;
same = true;
for (i=0;i<phrase.size();i++) {
if (phrase[i] != reverse[i]) {
same = false;
}
}
strippedSame = true;
for (i=0;i<strippedPhrase.size();i++) {
if (strippedPhrase[i] != strippedReverse[i]) {
strippedSame = false;
}
}
void Foo(int a, int b, int c, int & out) {
a = 7;
b = 5;
c = 12;
out = a+b/c;
return;
}
// this is bad and can lead to errors
if (a == b) {
DoSameFunction();
}
if (a != b) {
DoDifferentFunction();
}
// prefer this
if (a == b) {
DoSameFunction();
} else {
DoDifferentFunction();
}
// this is error prone
if (condition)
statement
// this is better
if (condition) {
statement
}
int main() {
DoMain();
return 0;
}
bool CompareStrings(string s1, string s2) {
// assume both strings are the same.
bool same = true;
size_t i;
if (s1.size() != s2.size() ) {
same = false;
}
if (same) {
for(i=0; i < s1.size(); i++) {
if (s1[i] != s2[i]) {
same = false;
// this is confusing code.
i = s1.size()
}
}
}
return same;
}
// I think this is better code
bool CompareStrings(string s1, string s2) {
// assume both strings are the same.
bool same = true;
size_t i;
if (s1.size() != s2.size() ) {
same = false;
}
for(i=0; same and i < s1.size() ; i++) {
if (s1[i] != s2[i]) {
same = false;
}
}
return same;
}
void Foo(string phrase) {
string reverse = Reverse(phrase);
string stripped = Strip(phrase);
string rstripped = Reverse(stripped);
...
if (phrase == reverse) {
...
}
cout < '"' << phrase << "\" is a " << palClass << endl;
PrintResults(phrase, palType);
getline(inFile, phrase):