The Programming Example: Pig Latin Strings converts a string into the pig Latin form, but it processes only one word. Rewrite the program so that it can be used to process a text of an unspecified length. 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:
Store the output in Ch7_Ex3Out.txt.
#include <bits/stdc++.h>
#include<iostream>
#include <stdio.h>
#include <string>
using namespace std;
char VowelsCheck(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 StrRotate(string str_pig)
{
int l;
l = str_pig.length();
str_pig=str_pig.substr(1,l-1)+str_pig[0];
return (str_pig);
}
void CreategPigStr(string PigStr)
{
if (VowelsCheck(PigStr[0])==1)
{
PigStr+="-way";
cout<<"\n\tPig Latin: " <<PigStr;
}
else
{
char falseflag=false;
PigStr+="-";
PigStr=StrRotate(PigStr);
for(int counter=1;counter<=PigStr.length()-1;counter++)
{
if (VowelsCheck(PigStr[0])==1)
{
cout<<"\n\tPig Latin: " <<PigStr+"ay";
falseflag=true;
break;
}
else
{
PigStr=StrRotate(PigStr);
}
}
if(!falseflag)
{
int size=PigStr.length();
PigStr=PigStr.substr(1,size)+"-way";
cout<<PigStr;
}
}
}
main(void)
{
string InputStr = "Hello! is ello-Hay!.";
cout<<"\nInput StringL: "<<InputStr;
cout<<"\nPig-Latin Form: ";
CreategPigStr(InputStr);
}
Comments
Leave a comment