1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
using namespace std;
char engtomol (char[], char[], int);
char moltoeng (char[], char[], int);
int main ()
{
char capalpha[26] = {'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'};
char morse[26] = {'.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..'};
char text, morsecode;
char choice;
char repeat='y';
int lengthoftext=text.length();
while (repeat =='y')
{
cout << "Select 1 to encode English text to Morse code. " << "\n" << "Select 2 to decode Morse code to English text." << endl;
cin >> choice;
if (choice==1)
{
cout << "Type in a text that you would like to translate." << endl;
getline(cin,text);
cout << "TEXT: " << text << endl;
cout << "MORSE CODE: " << engtomol (capalpha, morse, lengthoftext) << endl;
}
if (choice==2)
{
cout << "Type in a morse code that you would like to translate." << endl;
cin >> morsecode;
cout << "MORS CODE: " << morsecode << endl;
cout << "TEXT: " << moltoode (capalpha, morse, lengthoftext) << endl;
}
cout << "Would you like to try again? Hit y to continue." << endl;
cin >> repeat;
}
return 0;
}
char engtomol (char capalpha[], char morse[], int lengthoftext)
{
for (int k=0; k<lengthoftext; k++)
{
capalpha[k]=morse[k];
return morse[k];
}
}
char moltoeng (char capalpha[], char morse[], int lengthoftext)
{
for (int k=0; k<lengthoftext; k++)
{
morse[k]=capalpha[k];
return capalpha[k];
}
}
|