In: Computer Science
Can't seem to get the program working. I have the same program as a friend, but mine says void getNextWord fuction not found. I need getNextWord fuction Any Help would be great.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool isPunct(char);
bool isVowel(char ch);
string rotate(string pStr, string::size_type len);
string pigLatinString(string pStr);
void getNextWord(ifstream& inf, char& ch,
string& word);
//global declaration
int main()
{
string str;
//declaration
char ch;
ifstream infile;
ofstream outfile;
//input
infile.open("Sentence.txt");
if (!infile) {
cout << "Cannot open input
file. Program terminates." << endl;
return 1;
}
outfile.open("Piglatin.txt");
infile.get(ch);
while (infile) {
while (ch != '\n' &&
infile) {
if (ch == ' ')
{
outfile << ch;
infile.get(ch);
}
else {
getNextWord(infile, ch, str);
outfile << pigLatinString(str);
}
}
outfile << endl;
infile.get(ch);
}
infile.close();
outfile.close();
return 0;
}
bool isVowel(char ch)
{
cout << "in isvowel()" << endl;
bool isV = false;
switch (ch) {
case 'A': case 'a':
case 'I': case 'i':
case 'U': case 'u':
case 'E': case 'e':
case 'O': case 'o':
case 'Y': case 'y':
isV = true;
break;
default:
isV = false;
}
return isV;
}
bool isPunct(char ch)
{
cout << "in isPunct()" << endl;
bool isP = false;
switch (ch)
{
case ',':
case '?':
case '.':
case ';':
case ':':
case '!':
isP = true;
break;
default:
isP = false;
}
return isP;
}
string rotate(string pStr, string::size_type len)
{
cout << "in rotate()" << endl;
string rStr;
rStr = pStr.substr(1, len - 1) + pStr[0];
return rStr;
}
string pigLatinString(string pStr)
{
string::size_type len = pStr.length();
bool foundVowel; //done = false;
bool isPunctuation = isPunct(pStr[len - 1]);
char puncMark;
string::size_type counter;//loop counter
if (isPunctuation) {
puncMark = pStr[len - 1];
len -= 1;
}
if (isVowel(pStr[0])) {
pStr = pStr.substr(0, len) +
"-way";
}
else
{
pStr = pStr.substr(0, len) +
'-';
pStr = rotate(pStr, len);
len = pStr.length();
foundVowel = false;
for (counter = 1; counter <
len - 1; counter++)
{
if
(isVowel(pStr[0]))
{
foundVowel = true;
break;
}
else {
pStr = rotate(pStr, len);
}
}
cout << "line 157: " <<
pStr;
if (!foundVowel) {
pStr =
pStr.substr(1, len) + "-way";
}
else {
pStr +=
"ay";
//pStr = pStr +
"ay";
}
cout << "line 165: " <<
pStr << endl;
}
if (isPunctuation) {
pStr = pStr + puncMark;
}
cout << "line 170: " << pStr <<
endl;
return pStr;
}
void getNextWord(ifstream& inF, char& ch, string& word)
{
word = ch;
while (ch != ' ' && ch != '\n')
{
inF.get(ch);
if (ch != ' '
&& ch != '\n') {
word
= word + ch;
}
}
}
**************************************************
You are missing the body of the function.. hence error. Please use the above function at the last of your code.
Thanks for your question. We try our best to help you with detailed
answers, But in any case, if you need any modification or have a
query/issue with respect to above answer, Please ask that in the
comment section. We will surely try to address your query ASAP and
resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.