#include<iostream>
#include<string>
#include<algorithm>
usingnamespace std;
bool isVowel(char ch);//method to check whether ch is vowel or not..
//if yes returns true//other wise false
/**
* Removes the first character of the string, and places it at the
* end of the string.
* @param pString the word to be rotated.
* @return the new reordered string
*/
string rotate(string pStr);
// Introduces pigLatinString
string pigLatinString(string pStr);
int main()
{
string str;
cout << "Enter a word: ";//prompting user to enter a word
if (cin.peek() == '\n') //returns the next character in the input sequence
{
cin.ignore(1, '\n');//if it is line then ignoring it
}
getline(cin, str);//reading line and storing in str
cout << endl;
// Output the text as pig Latin
cout << "The pig Latin form of " << str << " is: "
<< pigLatinString(str) << endl;//printing output
return 0;
}
bool isVowel(ch)//checking whether vowel or nor
{
switch (ch)//switch statement
{
//for each vowel,upper and lower...defining cases to perform actions
case'A':
case'E':
case'I':
case'O':
case'U':
case'Y':
case'a':
case'e':
case'i':
case'o':
case'u':
case'y':
returntrue;//after all cases this will execute
default:
returnfalse;
}
}
string rotate(string pStr)
{
string::size_type len = pStr.length();//finding string length
string rStr;//new variable declaration
rStr = pStr.substr(1, len - 1) + pStr[0];
/*removing first character from pstr,and adding at the end,
and assigned to rstr return rStr;//returning rotated string*/
}
string pigLatinString(string pStr)
{
string::size_type len;//variable declaration
bool foundVowel;
string::size_type counter;
if (isVowel(pStr[0]))//if first char in pStr is vowel then
pStr = pStr + "-way";//adding -way to pStr
else//if it is not vowel
{
pStr = pStr + '-';//then adding - , at end of pStr
pStr = rotate(pStr);//rotating pStr
len = pStr.length();//finding length of new pStr
foundVowel = false;
for (counter = 1; counter < len - 1; counter++)
{
if (isVowel(pStr[0]))//checking first char in pstr is vowel or not
{
foundVowel = true;//if vowel
break;
}
else
pStr = rotate(pStr); //rotating
}
if (!foundVowel)
pStr = pStr.substr(1, len) + "-way";
else //if it is vowel
pStr = pStr + "ay";
}
return pStr;
}
ok i added the return rStr and i am still getting an error message:
[code]
// Reid Radebaugh- This program converts a string to pig latin
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool isVowel(char ch);//method to check whether ch is vowel or not..
//if yes returns true//other wise false
/**
* Removes the first character of the string, and places it at the
* end of the string.
* @param pString the word to be rotated.
* @return the new reordered string
*/
string rotate(string pStr);
// Introduces pigLatinString
string pigLatinString(string pStr);
int main()
{
string str;
cout << "Enter a word: ";//prompting user to enter a word
if (cin.peek() == '\n') //returns the next character in the input sequence
{
cin.ignore(1, '\n');//if it is line then ignoring it
}
return rStr;
getline(cin, str);//reading line and storing in str
cout << endl;
// Output the text as pig Latin
cout << "The pig Latin form of " << str << " is: "
<< pigLatinString(str) << endl;//printing output
return 0;
}
bool isVowel(char ch)//checking whether vowel or nor
{
switch (ch)//switch statement
{
//for each vowel,upper and lower...defining cases to perform actions
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'Y':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
return true;//after all cases this will execute
default:
return false;
}
}
string rotate(string pStr)
{
string::size_type len = pStr.length();//finding string length
string rStr;//new variable declaration
rStr = pStr.substr(1, len - 1) + pStr[0];
/*removing first character from pstr,and adding at the end,
and assigned to rstr return rStr;//returning rotated string*/
}
string pigLatinString(string pStr)
{
string::size_type len;//variable declaration
bool foundVowel;
string::size_type counter;
if (isVowel(pStr[0]))//if first char in pStr is vowel then
pStr = pStr + "-way";//adding -way to pStr
else//if it is not vowel
{
pStr = pStr + '-';//then adding - , at end of pStr
pStr = rotate(pStr);//rotating pStr
len = pStr.length();//finding length of new pStr
foundVowel = false;
for (counter = 1; counter < len - 1; counter++)
{
if (isVowel(pStr[0]))//checking first char in pstr is vowel or not
{
foundVowel = true;//if vowel
break;
}
else
pStr = rotate(pStr); //rotating
}
if (!foundVowel)
pStr = pStr.substr(1, len) + "-way";
else //if it is vowel
pStr = pStr + "ay";
}
return pStr;
}
[code]