Okay, I wrote a code to translate a character into Morse Code.
However, I was reading back over my assignment and I was actually supposed to define a macro PRINT_DOT which prints a period, and a macro PRINT_DASH, which prints an underscore. Then define macros PRINT_A, PRINT_B, etc.
Is there any way to easily change what I have, to what I am supposed to have?
Thanks! Here is my code.
#include <iostream.h>
int main ()
{
char ch;
while (ch != '=')
{
cout<<"What character would you like to generate into Morse Code (= to exit)? ";
cin>>ch;
cout<<endl;
switch (ch)
{
case 'a':
case 'A': cout<<".-"<<endl<<endl;
break;
case 'b':
case 'B': cout<<"-..."<<endl<<endl;
break;
case 'c':
case 'C': cout<<"-.-."<<endl<<endl;
break;
case 'd':
case 'D': cout<<"-.."<<endl<<endl;
break;
case 'e':
case 'E': cout<<"."<<endl<<endl;
break;
case 'f':
case 'F': cout<<"..-."<<endl<<endl;
break;
case 'g':
case 'G': cout<<"--."<<endl<<endl;
break;
case 'h':
case 'H': cout<<"...."<<endl<<endl;
break;
case 'i':
case 'I': cout<<".."<<endl<<endl;
break;
case 'j':
case 'J': cout<<".---"<<endl<<endl;
break;
case 'k':
case 'K': cout<<"-.-"<<endl<<endl;
break;
case 'l':
case 'L': cout<<".-.."<<endl<<endl;
break;
case 'm':
case 'M': cout<<"--"<<endl<<endl;
break;
case 'n':
case 'N': cout<<"-."<<endl<<endl;
break;
case 'o':
case 'O': cout<<"---"<<endl<<endl;
break;
case 'p':
case 'P': cout<<".--."<<endl<<endl;
break;
case 'q':
case 'Q': cout<<"--.-"<<endl<<endl;
break;
case 'r':
case 'R': cout<<"-.-"<<endl<<endl;
break;
case 's':
case 'S': cout<<"..."<<endl<<endl;
break;
case 't':
case 'T': cout<<"-"<<endl<<endl;
break;
case 'u':
case 'U': cout<<"..-"<<endl<<endl;
break;
case 'v':
case 'V': cout<<"...-"<<endl<<endl;
break;
case 'w':
case 'W': cout<<".--"<<endl<<endl;
break;
case 'x':
case 'X': cout<<"-..-"<<endl<<endl;
break;
case 'y':
case 'Y': cout<<"-.--"<<endl<<endl;
break;
case 'z':
case 'Z': cout<<"--.."<<endl<<endl;
break;
case ',': cout<<"--..--"<<endl<<endl;
break;
case '.': cout<<".-.-.-"<<endl<<endl;
break;
case '?': cout<<"..--.."<<endl<<endl;
break;
case ':': cout<<"---..."<<endl<<endl;
break;
case '/': cout<<"-..-."<<endl<<endl;
break;
case '(':
case ')': cout<<"-.--.-"<<endl<<endl;
break;
case '-': cout<<"-....-"<<endl<<endl;
break;
default: cout<<"Cannot be generated. "<<endl<<endl;
}
}
return 0;
}