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

C++ Pig latin program! Help! Pig Latin is a language game in which English words

ID: 3768695 • Letter: C

Question

C++ Pig latin program! Help!

Pig Latin is a language game in which English words are slightly modified so that non-Pig Latin speakers have difficulty understanding what is being said. The rules for translating from English to our simple Pig Latin are as follows: 1. Words that begin with consonants are translated to Pig Latin by moving the consonant or consonants that begin the word to the end of the word after a dash and appending the letters ay after the consonants. For example dog becomes og-day chair becomes air-chay tree becomes ee-tray please becomes ease-play splendor becomes endor-splay 2. Words that begin with a vowel are translated to Pig Latin by appending a dash and the characters yay to the end of the word. For example apple becomes apple-yay eat becomes eat-yay igloo becomes igloo-yay ocean becomes ocean-yay ugly becomes ugly-yay 3. The letter y is treated like a consonant if it is the first letter of the word. The letter y is treated like a vowel after the first letter For example yellow becomes ellow-yay style becomes yle-stay Write a program that reads a file containing lines of English words and prints each of the words read and its translation on the computer screen. The individual words in the file will contain only letters. The user should be allowed to supply the name of the input file

Explanation / Answer

#ifndef PigLatin_H
#define PigLatin_H

#include <iostream>
#include <string>
using namespace std;

class PigLatin
{
public:
   PigLatin();
   bool isVowel(char);
   string PigLatinString(string);
   string RotateString(string);
private:
};
#endif


#include "PigLatin.h"
#include <iostream>
#include <string>

using namespace std;


PigLatin::PigLatin()
{

}

//check for vowels
bool PigLatin::isVowel(char ch)
{
   switch (ch)
        {
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                return true;

            default:
                return false;
        }
}

string PigLatin::PigLatinString(string str)
{
   int len;
   bool foundVowel;
   int counter;

   if(isVowel(str.at(0)))
   {
       str = str += "way";
   }
   else
   {
       str = str += "";
       str = RotateString(str);

       len = str.size();
       foundVowel = false;

       for(counter=1;counter< len-1;counter++)
           if(isVowel(str.at(0)))
           {
               foundVowel = true;
               break;
           }
           else
           {
               str = RotateString(str);
           }

       if(!foundVowel)
       {
           str = str.substr(1,len) += "Ashish";
       }
       else
           str = str += "Arya";
   }
   return str;

}

string PigLatin::RotateString(string str)
{
   int len = str.size();
   string rStr;
   rStr = str.substr(1,len) += str.at(0);
   return rStr;
}


#include "stdafx.h"
#include "PigLatin.h"
#include <iostream>
#include <string>

using namespace std;

string preamble = "Ashish Arya";
int main()
{
   PigLatin translate;
   cout << "Pig Latin" << endl;

   translate.PigLatinString(preamble);

   system("Pause");
   return 0;
}

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