Ok first of I know my code is all over the place which is probably why I'm lost but anyways this program is supposed to have a word separator and pig latin function. The word separator basically separates
"ExceedYourExpectations" to "Exceed your expectations".
I am confident I got this function right but I am having problems translating that result string to pig latin which moves the first letter of the word to the end and add "ay" to it which would display the pig latin string of
"xceedEsay ourysay xpectationsesay"
However the pig latin translation isn't working. Can anyone help me? Would very much appreciate it. Thanks!
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
usingnamespace std;
// function prototype
void wordSep(string&);
string pigLatinString(string);
int main()
{
string input;
string converted;
//display unformatted sentence
cout << "Enter An Input String: " << endl;
cin >> input;
//seperate the words according to format
wordSep(input);
// display new formatted sentence
cout << "\nResult String: " << input << endl;
pigLatinString(input);
converted += pigLatinString(input) + " ";
cout << "\nPig Latin: " << converted << endl;
converted = "";
return 0;
}
// ====================================================
// function definition - converts input to a string where words are separated by spaces and only the
//first word starts with a capital letter
void wordSep(string &input)
{
char tempLetter; //temporarily stores a letter from &input
int length;
length = input.size(); // get original length to use in the loop
for (int count = 1; count < length; count++) // count starts at 1 to ignore first word(1st capitalization)
{
tempLetter = input[count];
// if uppercase character is found add a space
if (isupper(tempLetter))
{
input.insert(count, 1 ,' ');
++count; //after insertion of a space character we need to add 1 to the index (this makes count go back to the capital letter)
//set the letter to lowercase (b/c only first word starts with an uppercase letter)
input[count] = tolower(input[count]);
}
}
}
string pigLatinString(string input)
{
string firstChar = input.substr(0,1);
string restChar = input.substr(1, input.size()-1);
return restChar + firstChar + "ay";
}
Thank you for helping, but the code is supposed to have 2 functions and the "Exceed Your Expectations" was just an example. Is it possible if you just tweak my original code? I know I'm doing something wrong or I'm missing something.
This is what I was assigned to do:
1. Ask the user to enter an input string.
2. Call the word separator function with the input string as attachment
3. Display result string
4. Call Pig Latin function with the result string of the word separator function as argument
5. Display the result pig latin string.
However when I run the program, the pig latin isn't working.
you can reverse engineer the solution into the 2 functions required quite easily. lines 10-29 become the word separator function - i'd choose it's return value to be the std::vector<std::string> myVec as in the previous post and then pass this vector to the Pig Latin function (corresponding to lines 31-45 above) which then returns void - play around with the code or try and/or glean some ideas from it and adapt it to your exact requirements