Sep 7, 2016 at 12:56pm UTC
Using this code i have to 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". Also 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.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
#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
}
Sep 7, 2016 at 1:32pm UTC
I cant figure out where to put the in file at.
Sep 7, 2016 at 1:41pm UTC
If you're using an IDE, it'll most likely need to go in the same folder "main.cpp" is in. If you're just running the executable, it should be in the folder where the executable is.
Sep 7, 2016 at 1:43pm UTC
So where would i write in the code at on the program?
Sep 7, 2016 at 2:03pm UTC
So like this? if so i am getting an error saying a function-definition is not allowed here before { token
bool isVowel(char ch)
{
switch
{
/////////////////////////////////////
////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
int main()
{
ifstream inData;
ofstream outData;
inData.open("plFilein");
outData.open("plFileout");
{
string str;
cout << inData << endl;
cout << "The pig Latin form of " << str << " is: "
<< pigLatinString(str) << endl;
return 0;
}
bool isVowel(char charater)
{
switch (charater)
{
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";
}
cout << stringout << endl;
cin >> stringout;
stringin.close();
stringout.close();
return pStr;
}
Sep 7, 2016 at 3:15pm UTC
1 2 3 4 5 6
bool isVowel(char ch)
{
switch
{
/////////////////////////////////////
////////////////////////////////////
Where is the rest of that? It's cut off, you don't end it anywhere.
Edit: Please, for the love of GOD use the code tags. It makes it SO much easier to read.
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
bool isVowel(char ch)
{
switch
{
/////////////////////////////////////
////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);
int main()
{
ifstream inData;
ofstream outData;
inData.open("plFilein" );
outData.open("plFileout" );
{
string str;
cout << inData << endl;
cout << "The pig Latin form of " << str << " is: "
<< pigLatinString(str) << endl;
return 0;
}
bool isVowel(char charater)
{
switch (charater)
{
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" ;
}
cout << stringout << endl;
cin >> stringout;
stringin.close();
stringout.close();
return pStr;
}
Last edited on Sep 7, 2016 at 3:16pm UTC
Sep 7, 2016 at 5:06pm UTC
Line 37 there is a error saying a function-definition is not allowed here before { token
Sep 7, 2016 at 5:17pm UTC
Right, I saw that. Your syntax isn't correct.
You can't have a function definition INSIDE main. Move it outside of main.
Last edited on Sep 7, 2016 at 5:17pm UTC
Sep 7, 2016 at 7:29pm UTC
So i would move main below the rest of the code?
Sep 7, 2016 at 9:37pm UTC
Get rid of the extra brace on line 24.
Sep 13, 2016 at 3:57pm UTC
Use outfile <<
instead of cout <<
Sep 14, 2016 at 7:03pm UTC
I changed that on line 28. When i look at the output file there is no spaces between the words