Answer to Question #183017 in C++ for Vincenzo Santoro

Question #183017

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:

  • , (comma),
  • . (period),
  • ? (question mark),
  • ; (semicolon),
  • : (colon).

Store the output in Ch7_Ex3Out.txt.


1
Expert's answer
2021-04-29T03:14:17-0400


#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS