Need to Read text from a .txt file and convert to PIG LATIN


//This is what I have so far and it relies on manual cin. Can someone help me //change this to read a file ( //http://eilat.sci.brooklyn.cuny.edu/cis1_5/GettyburgAddress.txt)
//and output the PIG LATIN in another file ?





#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

bool isVowel (char);
string rotate (string); //string
string pigString(string); //Pig Latin String

int main()
{
string str; //Declare String Variable
cout <<"ENTER A STRING: "; //Enter the String
cin >>str; //Store the String
cout << endl;
cout << str << "in pig latin = "<<plString (str) <<endl;

ifstream.infile;
infile.open ("input.txt");
infile >>
while (infile)
{
cout<< plString(str) <<" ";
infile >> str;

}
cout << endl;
system ("PAUSE");
return 0;
}
/********************************************************************/
bool isVowel(char ch) //this function detects whether or not
//a character is a vowel
{
switch (ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'Y':
case 'y':
case 'u':
case 'o':
case 'i':
case 'e':
case 'a':
return true; //if any vowel lowercase or upper case return true
default:
return false;//if not a vowel return false
}
}
/********************************************************************/
string rotate(string str)

{
string::size_type len=str.length(); //the string size type is equal
//to the string size length and passed as a parameter
string str1; // Declare a String 1
str1 =str.substr (1,len -1) + (string [0]); //positions string to beginning
return str1;

}
/*********************************************************************/
string plString(string str)
{
string::size_typ len; //string size type for length
bool vowel;
string::size_type counter;
if (isVowel (str[0])) //Call isVowel - if first char is vowel...
str= str + "-way"; //add "-way"
else
{
str = str + "-"; //If the first Char is not vowel add hyphen
str = rotate(str); //Use Rotate Function
len = str.length();
vowel=false; //Set the vowel to false

for (counter=1; counter < len -1; counter++)
if (isVowel (str[0]))
{
vowel=true;
break; // if true we will exit the for loop
}
else
str=rotate(str);
if(!vowel) //if no vowel is found we will add "way"
str = str.substr(1,len) + "-way";
else
str= str +"ay";
}
return str;

}
Give your shell the command:

yourProgramName <infileName >outFileName
Topic archived. No new replies allowed.