Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add comments to the program (code below ) describing what each section of code d

ID: 3680538 • Letter: A

Question

Add comments to the program (code below ) describing what each section of code does. Then, modify the program so that it can be used to process a text of an unspecified length from a file and outputs Pig Latin to a different file. An example input file is attached for you to use for testing. If a word ends with a punctuation mark, in the pig Latin form, put the punctuation at the end of the string. For example, the pig Latin form of Hello! is ello-Hay!. Assume that the text contains the following punctuation marks: , (comma), . (period), ? (question mark), ! (exclamation point), ; (semicolon), and : (colon). The output file should have the same whitespace (spaces, tabs, and newline characters) as the original.

Solve this problem with the use of two additional functions:

isPunctuation that accepts a character and returns a Boolean value.

isWhitespace that accepts a character and returns a Boolean value.

#include <iostream>
#include <string>

using namespace std;
bool isVowel(char ch);


string rotate(string pStr);

string pigLatinString(string pStr);

int main()
{
   string str;

   // Get a word from the user
   cout << "Enter a word: ";
   cin >> str;
   cout << endl;

   // Output the text as pig Latin
   cout << "The pig Latin form of " << str << " is: "
       << pigLatinString(str) << endl;

   return 0;
}
//Checks to see if it containes vowels
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]))
       pStr = pStr + "-way";
   else
   {
       pStr = pStr + '-';
       pStr = rotate(pStr);

       len = pStr.length();
       foundVowel = false;

       for (counter = 1; counter < len - 1; counter++)
       {
           if (isVowel(pStr[0]))
           {
               foundVowel = true;
               break;
           }
           else
               pStr = rotate(pStr);
       }

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

   return pStr;
}

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;
bool isVowel(char ch);


string rotate(string pStr);

string pigLatinString(string pStr);

int main()
{
     string str;

    // Get a word from the user
     cout << "Enter a word: ";
     cin >> str;       //to store the word in str
     cout << endl;      // prints the word

    // Output the text as pig Latin
     cout << "The pig Latin form of " << str << " is: "
         << pigLatinString(str) << endl;       //prints the latin form of word

    return 0;
}
//Checks to see if it containes vowels
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(); //to find the string length

    string rStr;

    rStr = pStr.substr(1, len - 1) + pStr[0];

    return rStr;    
}

string pigLatinString(string pStr)
{
     string::size_type len;   //method size_type len

    bool foundVowel;

    string::size_type counter;

    if (isVowel(pStr[0]))
{
         pStr = pStr + "-way";
}
     else
     {
         pStr = pStr + '-';
         pStr = rotate(pStr);

        len = pStr.length();
         foundVowel = false;

        for (counter = 1; counter < len - 1; counter++)
         {
             if (isVowel(pStr[0]))
             {
                 foundVowel = true;
                 break;
             }
             else
                 pStr = rotate(pStr);
         }

        if (!foundVowel)
             pStr = pStr.substr(1, len) + "-way";
         else
             pStr = pStr + "ay";
     }
     public:
string::static bool IsPunctuation(pstr c)
   {
return bool value;
   }

    return pStr;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote