1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/*
English to Pig Latin Program
Write a program that converts a sentence input by the user into pig Latin.
You can assume that the sentence contains no punctuation. The rules for pig
latin are as follows:
•For words that begin with consonants, move the leading consonant to the end
of the word and add "ay". Thus, "ball" becomes "allbay"; "button" becomes
"uttonbay"; and so forth.
•For words that begin with vowels, add "way" to the end. Thus "all" becomes
"hallway"; "one" becomes "oneway"; and so forth.
*/
#include <iostream>
#include <string>
using namespace std;
//Declarations
const int stringSize = 100;
string englishPhrase[];
string PigLatin(string englishPhrase[]);
string str;
//English to Pig Latin conversion function
string PigLatin(string englishPhrase[])
{
PigLatin(englishPhrase->c_str[stringSize]);
int len = englishPhrase.length(); //Length of phrase english phrase
entered
string replaceString = englishPhrase->c_str.substr(1, len - 1) +
englishPhrase[0];
bool isVowel = false;
if (englishPhrase[0] == "A,E,I,O,U,Y,a,e,i,o,u,y")
englishPhrase += 'way';
else
{
englishPhrase = replaceString;
}
for (counter = 1; counter < (len - 1); counter++)
if (englishPhrase[0] == "A,E,I,O,U,Y,a,e,i,o,u,y")
{
isVowel = true;
return 0;
}
else
{
englishPhrase = replaceString.c_str;
}
if (!isVowel)
{
englishPhrase = PigLatin.substr(1, len) + "way";
}
else
{
englishPhrase += 'ay';
return englishPhrase->c_str;
}
}
int main()
{
string englishPhrase[stringSize];
int i;
cout << "Enter a short sentence to translate into Pig Latin (enter Q
to quit): " << endl;
getline(cin, englishPhrase[stringSize]);
//Loop for user to quit if not output pig latin conversion of the
phrase
for (char i = 0; i < stringSize; i++)
{
while ((englishPhrase[i] != "Q") || (englishPhrase[i] !=
"q"))
{
cout << "The sentence entered is " << englishPhrase
<< endl;
PigLatin(englishPhrase->c_str[stringSize]);
}
}
system("Pause");
return 0;
}
|