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

Write a program that translates a text to Fake Latin and back. English is transl

ID: 3872195 • Letter: W

Question

Write a program that translates a text to Fake Latin and back. English is translated to Fake Latin by taking the first letter of every word, moving it to the end of the word and adding ‘ay’ to each word. As an example, if your program reads from the keyboard the string “The quick brown fox” then it should print on the screen the following text: “Hetay uickqay rownbay oxfay”. You should also implement the reverse of this, reading "Iay ikelay rogrammingpay" should print on the screen "I like programming". i need it in java

Explanation / Answer

//

// FakeLatin.cpp

#include <string>

#include <sstream>

#include <iostream>

#include <cctype>

//Function converts sentence into FakeLatin

std::string toFakeLatin(const std::string& sentence){

std::stringstream is(sentence);

std::stringstream os;

std::string word;

  

while(is >> word){

//check if first letter is capital

bool iscapital = std::isupper(word[0]) != 0;

  

//adds 'ay' and also puts first letter in right position

std::string r = word.substr(1) + (char)std::tolower(word[0]) + "ay";

  

//capitalize if necessary

if(iscapital){

r[0] = (char)std::toupper(r[0]);

}

os << r << " ";

}

  

return os.str();

}

//Function converts FakeLatin into sentence

std::string fromFakeLatin(const std::string& sentence){

std::stringstream is(sentence);

std::stringstream os;

  

std::string word;

  

while(is >> word){

if(word.length() <= 2) continue;

  

//check if first letter is capital

bool iscapital = std::isupper(word[0]) != 0;

  

//remove 'ay' and also puts first letter in right position

std::string r = word[word.length()-3] +

word.substr(0, word.length()-3);

  

//capitalize if necessary

if(iscapital){

r[0] = (char)std::toupper(r[0]);

}

os << r << " ";

}

  

return os.str();

}

int main(){

std::cout << toFakeLatin("The quick brown fox") << std::endl;

std::cout << fromFakeLatin("Iay ikelay rogrammingpay") << std::endl;

}

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