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

Programming Language : C++ Write the functions using code provided IsVowel() Fun

ID: 3818041 • Letter: P

Question

Programming Language : C++

Write the functions using code provided

IsVowel()

Function: IsVowel
Input: strIn as string
If first character of strIn is a, e, i, o, or u (upper or lower case) then
   Return true
Else
   Return false
End if

PigVowel

Function: PigVowel
Input: strIn as string
Set strOut = strIn
If the last character of strIn is y then
   Append ay to strOut
Else
   Append yay to strOut
End if
Return: strOut

PigConsonant

Function: PigConsonant
Input: strIn as string
Set strOut = strIn from 2nd character of strIn to last character or strIn
Append first character of strIn to strOut
Append ay to strOut
Return: strOut

The main function will:

Store input in strInput
If strInput is vowel
   strOutput is set by PigVowel
Else
   strOutput is set by PigCononant
End if
Display strOutput

-----------------------------------------------------------------------------------------

#include "stdafx.h"

#include <iostream>

#include <iomanip>

#include <string>


using namespace std;


bool IsVowel(string strIn)

{

if (strIn.length() > 0)

{

char c;

c = toupper(strIn[0]);

if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')

return true;

}

return false;

}
string PigVowel(string strIn)

{

string strOut;
return strOut;

}
string PigConsonant(string strIn)

{

string strOut;

return strOut;

}


int _tmain(int argc, _TCHAR* argv[])

{
string strInput = "";

int iPosition = 0;

string strOutput = "";


cout << "Pig Latin Interpreter" << endl << endl;

cout << "Enter a word in English: ";

cin >> strInput;
cout << endl;

cout << "Pig Latin: " << strOutput << endl << endl;
system("Pause");

return 0;

}

Explanation / Answer

//program

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

bool IsVowel(string strIn)
{
   if (strIn.length() > 0)
   {
       char c;
       c = toupper(strIn[0]);
       if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
           return true;
   }
   return false;
}
string PigVowel(string strIn)
{
   string strOut = strIn;
   int strLen = strIn.length();
   string strApp = "yay";
   if (strIn[strLen - 1] == 'y')
   {
       //if last character of strIn is y ,append ay to strOut
       strOut += "ay";
   }
   else
   {
      
       //append yay to strOut
       strOut += "yay";
   }
   return strOut;
}
string PigConsonant(string strIn)
{
   string strOut ;
   int strLen = strIn.length(),j = 0;
   //assign strOut from 2nd charecter of strIn
   for (int i = 1 ; i < strLen; i++)
   {
       strOut+= strIn[i];
   }
   //now assign first character of strIn to strOut
   strOut += strIn[0];
   //now append ay to strOut
   strOut += "ay";
   return strOut;
}

int main(int argc, char **argv[])
{
   string strInput = "";
   int iPosition = 0;
   string strOutput = "";

   cout << "Pig Latin Interpreter" << endl << endl;
   cout << "Enter a word in English: ";
   cin >> strInput;
   cout << endl;
   if (IsVowel(strInput))
   {
       //call pigVowel
       strOutput = PigVowel(strInput);
   }
   else
   {
       strOutput = PigConsonant(strInput);
   }
   cout << "Pig Latin: " << strOutput << endl << endl;
   system("Pause");
   return 0;
}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

//output

Pig Latin Interpreter

Enter a word in English: append

Pig Latin: appendyay

----------------------------------------

//output2

Pig Latin Interpreter

Enter a word in English: angry

Pig Latin: angryay

-------------------------------

//output3

Pig Latin Interpreter

Enter a word in English: string

Pig Latin: tringsay

Press any key to continue . . .