Question

In: Computer Science

Can't seem to get the program working. I have the same program as a friend, but...

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;
  
}

Solutions

Expert Solution


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.


Related Solutions

I need to write a program and can't seem to make it run properly. Someone can...
I need to write a program and can't seem to make it run properly. Someone can help with the coding? It's with python Thanks! Here is the program: The rules of Shut the Box are as follows (abbreviated version): + You have two 5-sided die + You have 5 wooden blocks (labeled 1 through 5) + Each turn, you roll the dice and knock down the blocks corresponding to the number on each die + You have to knock down...
I am struggling with this assignment. I can't get the program to run when I enter...
I am struggling with this assignment. I can't get the program to run when I enter a number with the $ symbol followed by a number below 10. any help would be greatly appreciated. Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that accept an int, double, or string bid. Each method should display the bid and indicate whether it is over the minimum acceptable...
Java Counter Program I can't get my program to add the number of times a number...
Java Counter Program I can't get my program to add the number of times a number was landed on for my if statements for No12 through No2. My Code: import java.util.Scanner; import java.util.Random;    import java.lang.*;       public class Dice    {               public static void main(String[] args)        {            Scanner in = new Scanner(System.in);            int Continue = 1;            //randomnum = new Random();           ...
I cant not seem to get this right. I have tried and tried can I please...
I cant not seem to get this right. I have tried and tried can I please get help. Thank you! Writing a Modular Program in Java Summary In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values...
This isn't a homework but since I can't seem to find any answers for it, I...
This isn't a homework but since I can't seem to find any answers for it, I would like to receive some insights from you experts! So, I heard that UK has official left the European Union on Jan 31st (aka Brexit). Are there any trade deals that have been signed? or any negotiations that has been reached? please provide me with some updates I can't seem to find any info on which trade deals were signed and etc. thanks! p.s...
I need to draw a cylinder in java with user input, and I can't seem to...
I need to draw a cylinder in java with user input, and I can't seem to get my lines to line up with my ovals correctly from the users input... I know I will have to either add or subtract part of the radius or height but I'm just not getting it right, here is how I'm looking to do it.            g.drawOval(80, 110, radius, height);            g.drawLine(?, ?, ?, ?); g.drawLine(?, ?, ?, ?);   ...
Hi there, I am having a bit of an issue that I just can't seem to...
Hi there, I am having a bit of an issue that I just can't seem to figure it out. My code is supposed to read from another file and then have an output of a number for each categorie ////////Required Output/////// Movies in Silent Era: 0\n Movies in Pre-Golden Era: 7\n Movies in Golden Era: 581\n Movies in Change Era: 3445\n Movies in Modern Era: 10165\n Movies in New Millennium Era: 15457\n My program is: import java.util.ArrayList; public class MovieReducerEraCount...
I'm trying to make this C++ loan calculator but I can't get the program to output...
I'm trying to make this C++ loan calculator but I can't get the program to output what I need. For instance I know the formula is right and when I enter 100000 1.5 20 as my cin variables I should get 482.55 but I get 1543.31. What am I not seeing as the issue? Also this should cout only 2 decimal places right? I'm not allowed to alter the #include and add any fixed setprecision. This is what I have....
I have tried this multiple times and I can't get the right answer. The 2014 balance...
I have tried this multiple times and I can't get the right answer. The 2014 balance sheet of Jordan’s Golf Shop, Inc., showed long-term debt of $5.2 million, and the 2015 balance sheet showed long-term debt of $5.45 million. The 2015 income statement showed an interest expense of $170,000. The 2014 balance sheet showed $520,000 in the common stock account and $5.5 million in the additional paid-in surplus account. The 2015 balance sheet showed $560,000 and $5.7 million in the...
Were learning about hypothesis testing procedures, but I cannot seem to get the same responses question3....
Were learning about hypothesis testing procedures, but I cannot seem to get the same responses question3. An investigator hypothesizes that cholesterol levels in children might be affected by educating their parents on proper nutrition and exercise. A sample of 40 families with a child between the ages of 10-15 who has been diagnosed with high cholesterol agree to participate in the study. All parents are provided educational information on nutrition and exercise. After following the prescribed program, their child's total...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT