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

use Pseudocode to help finish the c++ code Pseudocode for the interpreter Pseudo

ID: 3676664 • Letter: U

Question

use Pseudocode to help finish the c++ code

Pseudocode for the interpreter


Pseudocode for the input and output should look familiar by now:

Title: "Pig Latin Interpreter"
Prompt: "Enter a word in English: "
Store input in strInput

and

Display "Pig Latin: " strOutput

Between the input and the output is where the interpretation takes place.

The first character has to be checked to see if it is a vowel or a consonant. And then the letters in the word have to be rearranged and the suffix added.

To make things work smoother, I would write three functions: IsVowel will return true if the first letter of the word is a vowel, PigVowel will interpret a word that starts with a vowel, and PigConsonant will interpret a word that starts with a consonant.

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

use the following c++ code to finish it....

Explanation / Answer

Please find the completed code below :

#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 = strIn;
char c = strIn[strIn.length()-1];
if(c=='y')
strOut = strOut + "ay";
else
strOut = strOut + "yay";
return strOut;
}

string PigConsonant(string strIn)
{
string strOut = strIn.substr(2,strIn.length());
char c = strIn[strIn.length()-1];
strOut = strOut + c + "ay";
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;
}