Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int again = 1, choice, stringLength, start, finish;
- string morseCode[39] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",".----","..---","...--","....-",".....","--...","---..","----.","-----",".-.-.-","-....","--..--","..--.."};
- string alphabet[39] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0","Stop",",","?"};
- string englishToMorse, morseToEnglish, anotherString, yetAnotherString;
- while(again == 1)
- {
- anotherString = "";
- cout << "\n\n\nPlease enter the number corresponding to your choice...\n"
- << "1) English to Morse\n"
- << "2) Morse to English\n"
- << "3) Quit\n";
- cin >> choice;
- cout << string(50, '\n');
- switch(choice)
- {
- case(1):
- cout << "Input English sentence to be translated..." << endl;
- cin.ignore();
- getline(cin, englishToMorse);
- stringLength = englishToMorse.length();
- cout << string(50, '\n');
- cout << "\t\t( / REPRESENTS A SPACE BETWEEN WORDS )" << endl;
- cout << "\nYour sentence: " << englishToMorse << endl;
- cout << "The translation: ";
- for(int n = 0; n < stringLength; n++)
- {
- englishToMorse[n] = toupper(englishToMorse[n]);
- anotherString = englishToMorse[n];
- if(anotherString == " ")
- {
- cout << "/ ";
- }
- for(int i = 0; i < 39; i++)
- {
- if(anotherString == alphabet[i])
- {
- cout << morseCode[i] << " ";
- }
- }
- }
- break;
- case(2):
- cout << "Input Morse Code to be translated..." << endl;
- cin.ignore();
- getline(cin, morseToEnglish);
- stringLength = morseToEnglish.length();
- cout << string(50, '\n');
- cout << "\t\t( USE / TO SEPERATE WORDS )" << endl;
- cout << "\nYour code: " << morseToEnglish << endl;
- cout << "The translation: ";
- start = 0;
- for(int n = 0; n < stringLength; n++)
- {
- anotherString = morseToEnglish[n];
- if(anotherString == " ")
- {
- finish = n;
- yetAnotherString = morseToEnglish.substr(start, finish);
- for(int i = 0; i < 39; i++)
- {
- if(yetAnotherString == morseCode[i])
- {
- cout << alphabet[i];
- yetAnotherString = "";
- }
- }
- }
- start = finish;
- }
- break;
- case(3):
- again = 0;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement