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

Program Lab #7StringsYou have been asked to construct a program that will transl

ID: 3641354 • Letter: P

Question

 Program Lab #7StringsYou have been asked to construct a program that will translate English to Pig Latin.  Following good programming practice, yourealize that the solution will make heavy use of functions.  You plan to start by constructing a function that will convert anEnglish word into Pig Latin.  Pig Latin is a fictitious language derived from English using a few simple rules.1.) If a word starts with a vowel (a, A, e, E, i, I, o, O, u, U) then the translation is formed by adding a "way" to the end ofword. e.g. "at" becomes "atway", "egg" becomes "eggway"2.) If a word contains no vowels (a, A, e, E, i, I, o, O, u, U) then the translation is formed by a adding a "way" to the end ofword. e.g. "my" becomes "myway", "by" becomes "byway"                3.) If a word starts with a consonant and contains a vowel, the translation is formed by moving the consonant(s) up to the firstvowel to the end of the word and adding an "ay". e.g. "bat" becomes "atbay", "that" becomes "atthay", "three" becomes "eethray"4.) Words that start with an initial capital letter should be translated to words with an initial capital letter.e.g. "Houston" becomed "Oustonhay", "Iceland" becomes "Icelandway", "Marry" becomes "Arrymay"=================================================================================================================================Deliverables:Write a program using good style, indents, descriptive variable names, comments, etc..Greet the user and provide a few lines about what the program is/does.Prompt the user to enter an English word.Translate the word from English to Pig Latin.Output the original word and the translated word.Prompt the user to continue.=================================================================================================================================Hints: You are free to construct any functions you may need to perform the translation.  Be sure to keep a copy of the original word.  You can use assume a string size of 50, though most words will be much smaller.You will probably want functions to:Input the word.Find the length of a word.Determine if a given letter is a vowel. (a helper function to make life easy for you)Determine if a word starts with a vowel (rule 1).Determine if a word contains a vowel (rule 2).Determine where the vowel is in the word (rule 3).Determine if the word has an initial capital letter (rule 4).Output the English and Pig Latin words.=================================================================================================================================Example Output:This program will translate a word from English to Pig Latin.Please enter a word: CatCat becomes Atcay.Would you like another word? (Y/N) yPlease enter a word: byby becomes byway.Would you like another word? (Y/N) YPlease enter a word: AwayAway becomes Awayway.Would you like another word? (Y/N) YPlease enter a word: atat becomes atway.Would you like another word? (Y/N) YPlease enter a word: treetree becomes eetray.Would you like another word? (Y/N) nAnkthay ouyay!

Explanation / Answer

// PigLatin.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> using namespace std; bool isVowel(char c) { switch(c) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': return true; default: return false; } } bool containsVowel(string word) { int len=word.length(),i; for(i=0;i<len;i++) if(isVowel(word[i])) return true; return false; } string toLowerCase(string x) { string allSmall=""; int i,len=x.length(); for(i=0;i<len;i++) allSmall.push_back(tolower(x[i])); return allSmall; } bool isCapital(char c) { if(c>='A'&&c<='Z') return true; else return false; } string capitalFirst(string res,string orig) { string capFirst=""; if(isCapital(orig[0])) { capFirst.push_back(toupper(res[0])); capFirst.append(res.substr(1)); return capFirst; } else return res; } int findFirstVowel(string word) { int i,len; len=word.length(); for(i=0;i<len;i++) { if(isVowel(word[i])) return i; } return -1; } string pigLatin(string word) { string backup,ans; backup=word; word=toLowerCase(word); //Rule 1 if(isVowel(word[0])) { ans=word+"way"; } else if(containsVowel(word))//Rule 3 - Starts with consonant, contains vowel { int posVowel=findFirstVowel(word); ans=word.substr(posVowel)+word.substr(0,posVowel)+"ay"; } else//Rule 2 { ans=word+"way"; } ans=capitalFirst(ans,backup);//Rule 4 return ans; } int main() { cout<<"This program will translate a word from English to Pig Latin"<<endl<<endl; char more; string word; do { cout<<"Please enter a word: "; cin>>word; cout<<"The word "<<word<<" becomes "<<pigLatin(word); cout<<" Would you like another word(Y/N) ?: "; cin>>more; } while(more=='Y'||more =='y'); return 0; } // PigLatin.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> using namespace std; bool isVowel(char c) { switch(c) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': return true; default: return false; } } bool containsVowel(string word) { int len=word.length(),i; for(i=0;i<len;i++) if(isVowel(word[i])) return true; return false; } string toLowerCase(string x) { string allSmall=""; int i,len=x.length(); for(i=0;i<len;i++) allSmall.push_back(tolower(x[i])); return allSmall; } bool isCapital(char c) { if(c>='A'&&c<='Z') return true; else return false; } string capitalFirst(string res,string orig) { string capFirst=""; if(isCapital(orig[0])) { capFirst.push_back(toupper(res[0])); capFirst.append(res.substr(1)); return capFirst; } else return res; } int findFirstVowel(string word) { int i,len; len=word.length(); for(i=0;i<len;i++) { if(isVowel(word[i])) return i; } return -1; } string pigLatin(string word) { string backup,ans; backup=word; word=toLowerCase(word); //Rule 1 if(isVowel(word[0])) { ans=word+"way"; } else if(containsVowel(word))//Rule 3 - Starts with consonant, contains vowel { int posVowel=findFirstVowel(word); ans=word.substr(posVowel)+word.substr(0,posVowel)+"ay"; } else//Rule 2 { ans=word+"way"; } ans=capitalFirst(ans,backup);//Rule 4 return ans; } int main() { cout<<"This program will translate a word from English to Pig Latin"<<endl<<endl; char more; string word; do { cout<<"Please enter a word: "; cin>>word; cout<<"The word "<<word<<" becomes "<<pigLatin(word); cout<<" Would you like another word(Y/N) ?: "; cin>>more; } while(more=='Y'||more =='y'); 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