• Did you order new AirTags? We've opened a dedicated AirTags forum.


macrumors newbie
Original poster
Jan 27, 2019
Russellville, Arkansas
Using the attached pigLatinString.cpp as a starting point, create a Pig Latin Converter program that will read in a file called "pigLatinFile.in" of English sentences, convert them into Pig Latin, and will output them back to a file called "pigLatinFile.out".


1) While I may not use the same input file provided to you, you can be assured that it will contain no more than 500 words on the same line like the sample input file provided here.

2) You can name your cpp file for this assignment anything you wish, so long as you attach it with your submission and it will read in and output the exact file names above and like the sample files.

Special Requirements:

1) The comma (,) and period(.) characters will be considered special punctuation characters, and even after conversion to Pig Latin, these characters will need to still appear at the end of each word. All other characters can be left where Malik's "rotate" function puts them in the word.

2) If the first letter of the English word is capitalized, then the first letter of the word converted into Pig Latin should also be capitalized.

An Example of these Requirements is "David," converted into Pig Latin by your program should be "Avid-day,"

#include <iostream>
#include <string>

using namespace std;

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 form of " << str << " is: "
<< pigLatinString(str) << endl;

return 0;

bool isVowel(char ch)
switch (ch)
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;
return false;

string rotate(string pStr)
string::size_type len = pStr.length();

string rStr;

rStr = pStr.substr(1, len - 1) + pStr[0];

return rStr;

string pigLatinString(string pStr)
string::size_type len;

bool foundVowel;

string::size_type counter;

if (isVowel(pStr[0])) //Step 1
pStr = pStr + "-yay";
else //Step 2
pStr = pStr + '-';
pStr = rotate(pStr); //Step 3

len = pStr.length(); //Step 3.a
foundVowel = false; //Step 3.b

for (counter = 1; counter < len - 1;
counter++) //Step 3.d
if (isVowel(pStr[0]))
foundVowel = true;
else //Step 3.c
pStr = rotate(pStr);

if (!foundVowel) //Step 4
pStr = pStr.substr(1, len) + "-way";
pStr = pStr + "ay";

return pStr; //Step 5
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.