Smack my head. He may as well have said "you MUST write bad code for this project."
Okay, to avoid array code, you can use a switch() statement to convert from a character to morse code. The great irony here is that the compiler will probably turn this into an array of sorts (a jump table).
1 2 3 4 5 6 7 8 9 10 11
|
const char *toMorse(char ch)
{
switch (ch) {
case 'a': return ".-";
case 'b': return "-...";
...
case '0': return "-----";
case '1': return ".----";
// etc for all the letters, digits and punctuation
default: return "#"
}
|
Ask the professor if it's okay to use array syntax to go through the input strings. If not then you might use pointers instead.
I'd divide this up so that one person is writing the user interface and the other person is writing the toMorse() function and the function to print a sentence.
To do it as a pair, create a header file that declares those two functions and contains comments explaining exactly what they do.
Then each of you goes off and writes his/her part. The one writing toMorse and printSentence (or whatever you call it) will create their own main() program to test these functions. Meanwhile, the other partner, the one writing the "real" main() function and user interface, will create dummy versions of toMorse() and printSentence() so that he/she can test the user interface. The dummy toMorse() might just return "blip" and printSentence() might print "this is a sentence".
If you do this right, then when you're both done with your part, you'll just have to get together, combine the two parts, delete the test code that each of you have, and voila! The program should work.