Help

How do i 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"


#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;
default:
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;
break;
}
else //Step 3.c
pStr = rotate(pStr);

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

return pStr; //Step 5
}
It appears you posted the same problem here:
http://www.cplusplus.com/forum/beginner/196987/

This appears to be the code you were given by your professor. You have made no attempt to read from a file, or write to another file. As pointed out in the other thread, we will not do your homework for you. We will however help you if you have questions.

The following pages should help you with reading and writing files:
http://www.cplusplus.com/reference/fstream/ifstream/
http://www.cplusplus.com/reference/fstream/ofstream/?kw=ofstream

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Topic archived. No new replies allowed.