I got bored. So sue me. Redone in C++ (correctly this time, and probably more efficient than this or this.)
#include <iostream> #include <string> #include <vector> #include <cctype> using namespace std; bool isPunctuation( char c ); string latinize( string s ); bool isVowel( char c ); int main( ) { string input, output, temp; vector<string> words; vector<char> punctuation; cout< < "Enter a phrase you would like to latenize" << endl << "-> "; getline( cin, input ); for( int i = 0; i < input.length(); i++ ) { char c = tolower( input.at( i ) ); if( isPunctuation( c ) ) { words.push_back( temp ); punctuation.push_back( c ); temp.clear(); } else temp.append( 1, c ); } if( !temp.empty() ) { words.push_back( temp ); punctuation.push_back( ' ' ); } for( int i = 0; i < words.size(); i++ ) { string l = latinize( words.at( i ) ); output.append( l ); output.append( 1, punctuation.at( i ) ); } cout<< output << endl; return 0; } bool isPunctuation( char c ) { char punctuation[33] = { ',', '.', '/', '<', '>', '?', ';', '\'', ':', '"', '[', ']', '\\', '{', '}', '|', '`', '-', '=', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', ' ' }; for( int i = 0; i < 33; i++ ) if( c == punctuation[i] ) return true; return false; } string latinize( string s ) { string postfix, temp; for( int i = 0; i < s.length(); i++ ) { char c = s.at( i ); if( isVowel( c ) ) { postfix.append( "ay" ); temp = s.substr( i ); temp.append( "-" ); temp.append( postfix ); return temp; } else postfix.append( 1, c ); } } bool isVowel( char c ) { char vowels[5] = { 'a', 'e', 'i', 'o', 'u' }; for( int i = 0; i < 5; i++ ) if( c == vowels[i] ) return true; return false; }
