Question
This is a C++ program. Help me to include or import in order to get the g-mail or any email into this program called it
This is a C++ program. Help me to include or import in order to get the g-mail or any email into this program called it Morse Code translator(I already wrote it) and then this program can convert the mail from English text to Morse Code and vice versa.
Here is my code. Thanks!
#include
using namespace std;
string engToMorse(string, string const[]); string morseToEng(string, string const[]);
int main() { string const morse[27] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
string text, morseCode; char choice; char repeat = 'y';
while (repeat == 'y' || repeat == 'Y') { cout << " Select 1 to encode English text to Morse code. Select 2 to decode Morse code to English text. "; cout << endl << "Please make your selection: "; cin >> choice; cin.ignore(80, ' ');
if (choice == '1') { cout << " NOTE. DO NOT INPUT A NON ENGLISH CHARACTER. " << " THIS TRANSLATOR EXCLUSIVELY TRANSLATES ENGLISH TEXTS (CAPITALIZED AND NON CAPITALIZED). "; cout << " Enter text to translate, each word seperated by a space if you want to translate more than one word: "; getline(cin, text);
cout << " TEXT: " << text << endl; cout << " MORSE CODE: " << engToMorse(text, morse) << endl; } else if (choice == '2') { cout << " Enter a morsecode to translate, each letter code seperated by a space. " << " If you want to translate more than one word, have 2 spaces between each word. " << "(for example, ... --- ... ... --- ...): "; getline(cin, morseCode);
cout << " MORSECODE: " << morseCode << endl; cout << " TEXT: " << morseToEng(morseCode, morse) << endl; } else cout << " INVALID SELECTION " << endl;
cout << " Would you like to continue? Press y to repeat. Press any other key to exit. "; cin >> repeat; }
system("Pause"); // pause the system for a while return 0; }
string engToMorse(string text, string const morse[]) { int textLength = text.length(); string morseValue; string spacesBtwLetters = " "; string spacesBtwWords = " "; //1 space between words
for (int k = 0; k < textLength; k++) { //Validate each character. If the character is not a valid english alphabet //Return a warning message if ((toupper(text[k]) < 'A' || toupper(text[k]) > 'Z') && text[k] != ' ') { morseValue = " INVALID CHARACTER USED "; return morseValue; }
if (text[k] != ' ') //if the word(s) did not encounter a space { text[k] = toupper(text[k]); //upper case letters and lower case letters are the same hence have the same appropriate morse code. morseValue += morse[text[k] - 'A'] + spacesBtwLetters; //A is the first value of the array. }//By subtracting its finding the appropriate morse code for each letters
if (text[k] == ' ') { morseValue += spacesBtwWords; // 2 spaces when there is a space between words } }
return morseValue; }
string morseToEng(string morseCode, string const morse[]) { int const characters = 26; string output = ""; //output for function int index = 0;
while (index < morseCode.size()) { //find current morse code string letter = "";
while (morseCode[index] != ' ' && index < morseCode.size()) { //Validate each character in the morse letter. if the morse letter //contains other than ., -, send a warning message if (morseCode[index] != '.' && morseCode[index] != '-') { output = " INVALID CODES ARE USED "; return output; }
letter += morseCode[index++]; }
//find this code in the morse alphabet int position = 0;
while (morse[position] != letter && position < 26) { ++position; }
//check whether the letter is a valid morse letter or not if (letter != "" && position == 26) { output = " INVALID CODES ARE USED "; return output; }
if ('A' + position == '[') output += ' '; else output += 'A' + position; ++index; //to get rid of the space character. }
return output; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started