Modified Piglatin Script
Apr 27, 2015 at 1:32am UTC
I have an assignment to modify the below script. It currently only does one word at a time, but I'm supposed to change it so that it will do a whole sentence at a time, and place the punctuations (if any) at the end of the word.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
#include<iostream>
#include<cstdlib>
#include<cctype>
#include<iomanip>
using namespace std;
//declare user functions
bool isVowel (char ch);
string rotate (string pStr);
string pigLatinString (string pStr);
int main()
{
string str;
cout<<"Enter a string: " ;
cin>>str;
cout<<endl;
cout<<"The pig Latin for of " <<str<<" is: " <<pigLatinString(str)<<endl;
//end program
cout<<endl<<endl;
system("pause" );
return 0;
}
//user defined functions
int isvowel (char ch)
{
//change to upper case
toupper (ch);
//check to see if first letter is a vowel
switch (ch)
{
case 'A' :
case 'E' :
case 'I' :
case 'O' :
case 'U' :
case 'Y' :
return true ;
break ;
default :
return false ;
break ;
}
}
string rotate (string pStr)
{
string::size_type len = pStr.length();
//declare return string
string rStr;
//take off first letter and add it to the back
rStr = pStr.substr(1, len - 1) + pStr[0];
//return the new string
return rStr;
}
string pigLatinString (string pStr)
{
string::size_type len;
bool foundVowel;
string::size_type counter;
if (isVowel (pStr[0]))
{
pStr = pStr + "-way" ;
}
else
{
pStr = pStr + '-' ;
pStr = rotate(pStr);
len = pStr.length();
foundVowel = false ;
for (counter = 1; counter < len - 1; counter ++)
{
if (isVowel (pStr[0]))
{
foundVowel = true ;
break ;
}
else
{
pStr = rotate (pStr);
}
}
if (!foundVowel)
{
pStr = pStr.substr(1, len) + "-way" ;
}
else
{
pStr = pStr + "ay" ;
}
}
return pStr;
}
I'm not looking for someone to do it for me, but I have no idea where to start.
Topic archived. No new replies allowed.