In: Computer Science
Create a C++ project called RobberyLanguage. Ask the user to enter a word. Write a function that will receive the word, use the word to compile a new word in Robbery language and return the new Robbery language word. In the function: Use a while loop and a newline character (‘\0’) to step through the characters in the original string. How to compile a word in Robbery language: Double each consonant and put the letter ‘o’ between the two consonants. For example:" ENTER THE WORD: Welcome
original word is welcome , Robbery language: wowelolcocomome
process returned 0 (0*0) execution time :
press any key to continue "
Example of the definition of the function: string compileRobLanWord(char word[50]) Hints: Declare a new character string for the Robbery language word. A word in Robbery language has more characters than the original word. Therefor the new string must have its own index value. How it looks like in memory: Original word: S a m \0 2 0 1 2 3 Robbery language: S o S a m o m \0 0 1 2 3 4 5 6 7 Note: Remember to add the \0 character as the last character of the new word. In the main function: Example of the call statement in the main function: newWord = compileRobLanWord(word); Display the original word and the Robbery language word.
C#(VISUAL STUDIO)
#include<iostream>
#include<sstream>
#include<string>
using namespace std;
// FUNCTION PROTOTYPES
string compileRobLanWord(char word[50]);
bool isAlphabet(char c);
bool isConsonant(char c);
int main()
{
char origWord[50];
string robberyWord;
cout << "ENTER THE WORD: ";
cin >> origWord;
robberyWord = compileRobLanWord(origWord);
cout << "\nOriginal word is: " << origWord
<< endl;
cout << "Robbery language is: " <<
robberyWord << endl;
return 0;
}
// FUNCTION IMPLEMENTATIONS
string compileRobLanWord(char word[50])
{
string res = "";
stringstream ss;
for (int i = 0; i < 50; i++)
{
if (isAlphabet(word[i]))
{
if
(isConsonant(word[i]))
{
ss << word[i] << 'o' <<
word[i];
}
else
{
ss << word[i];
}
}
}
res = ss.str();
return res;
}
bool isAlphabet(char c)
{
if ((c >= 'A' && c <= 'Z') || (c >=
'a' && c <= 'z'))
return true;
else
return false;
}
bool isConsonant(char c)
{
if (c != 'A' && c != 'a' && c != 'E'
&& c != 'e' && c != 'I' && c != 'i'
&& c != 'O' && c != 'o' && c != 'U'
&& c != 'u')
return true;
else
return false;
}
******************************************************* SCREENSHOT ********************************************************
CODE SCREENSHOTS :
CONSOLE OUTPUT :