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

C++ PROGRAMMING LANGUAGE!!!! C++ Question: Pig Latin Design a program that has t

ID: 3828357 • Letter: C

Question

C++ PROGRAMMING LANGUAGE!!!!

C++

Question: Pig Latin

Design a program that has two functions to perform the following tasks:

word separator function: this function accepts a string as argument. The string is actually a sentence in which all of the words are run together, but the first character of each word is uppercase. The function will then convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRoses." would be converted to "Stop and smell the roses." (hint: the toLower library function can be used to convert a single uppercase character to it's lowercase.) The function will return the result string.

pig latin function: this function accepts a string as argument and converts each word in the string to "Pig Latin". In one version of Pig Latin you convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word. The function will return the result pig latin string.

Example:

input string: StopAndSmellTheRoses             

after calling the word separator function the result string will be: Stop and smell the roses

after calling the pig latin function, the result string will be: topSay ndaay mellsay hetay osesray

In the main function of the program, ask the user to enter an input string, then call the word separator function with the input string as argument and display the result string. Then call the pig latin function with the result string of the word separator function as argument and display the result pig latin string.

Explanation / Answer

#include<iostream>
#include<string>


using namespace std;

string wordSeperator(string input) {
   for (int i = 1; i<input.length(); i++)
       if (input[i] >= 'A' && input[i]<='Z'){ //find letter in UPPER CASE
           input[i] = (char)(input[i] + 32); //convert it to lower
           input.insert(i," "); //insert a blank before that
       }
   return input;
}

string pigLatin(string input) {
   string ay = "ay"
   string ch = input[0]+ay; //get starting char and concat with 'ay
   input.erase(0,1);
   int i;
   for (i = 0; i<input.length(); i++) {
       if(input[i]==' ') {
           input.insert(i,ch);//insert the first char along with ay
           i = i + 3; //increment counter
            ch = input[i+1]+ay; //get starting char of next word and concat with 'ay
           input.erase(i+1,1);//erase the starting char of next word
       }
   }
   input.insert(i,ch); //for the last word we need to insert manuallly since we dont get a blank space there
   retrun input;
}

int main() {
   string a = "AppleIsGreen";
   cout<<pigLatin(wordSeperator(a));
}

I have commented almost every line of the code for you and I hope you like it. If incase you still face any trouble, please let me know. I shall be glad to help you.

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