Created
May 14, 2015 23:57
-
-
Save Lomeli12/80695668fee036068d4d to your computer and use it in GitHub Desktop.
Ubify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
char replacementChar[12] = { 'a', 'e', 'i', 'o', 'u', 'y'}; | |
string ubify(string baseString); | |
bool matches(char c); | |
int main(int argc, char *argv[]) { | |
if (argc >= 2) { | |
for (int i = 1; i < argc; i++) { | |
cout << ubify(argv[i]).c_str() << " "; | |
} | |
cout << endl; | |
} else { | |
bool cont = true; | |
do { | |
string line = ""; | |
cout << "Input something to ubify (type /exit to quit): " << endl; | |
getline(cin, line); | |
if (!line.empty()) { | |
if (line.compare("/exit") == 0) | |
cont = false; | |
else | |
cout << ubify(line) << endl; | |
} | |
} while (cont); | |
} | |
return 0; | |
} | |
string ubify(string baseString) { | |
string out = ""; | |
int size = baseString.size(); | |
for (int i = 0; i < size; i++) { | |
char ch = baseString[i]; | |
if (matches(ch)) { | |
if (isupper(ch)) | |
out += "Ub"; | |
else | |
out += "ub"; | |
} else | |
out += ch; | |
} | |
return out; | |
} | |
bool matches(char c) { | |
for (int i = 0; i < sizeof(replacementChar); i++) { | |
if (tolower(c) == replacementChar[i]) | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment