CMSC 313 Project 2

Morse Code

Assigned Monday, Feb 14, 2011
Program Due 11:59pm Sunday Feb 27, 2011
Points 60
Updates  

Objective

This project will give you some experience with functions, file I/O, strings, characters, and separate compilation using a makefile.

Background

Morse code, patented by Samuel F. B. Morse in 1837, is the language that was used to send messages by telegraph from the middle of the nineteenth century until the advent of the modern telephone and today's computer-controlled communications systems. In Morse code, each letter in the alphabet and each digit are represented by a series of dots and dashes as shown in the table below: A .- H .... O --- V ...- B -... I .. P .--. W .-- C -.-. J .--- Q --.- X -..- D -.. K -.- R .-. Y -.-- E . L .-.. S ... Z --.. F ..-. M -- T - G --. N -. U ..- 0 ----- 1 .---- 2 ..--- 3 ...-- 4 ....- 5. ..... 6. -.... 7 --... 8 ---.. 9 ----. The International Morse code has expanded on the set of characters which can be sent via Morse code. For more on Morse code, check out Wikipedia

The Task

Your task for this project is to write a program that will translate English text into Morse code and will also translate Morse code back to English. Your program will prompt the user for an input file and an output file, and then ask the user which translation he wishes to perform. Your program will then read the input file and write the requested translation to the output file.

Since your program is doing both translations, in theory, the output from translating an English file into Morse code could follow whatever conventions you chose for separating characters, separating words and handling special characters such as punctutation. However, we require that you follow the translation rules below so that the Morse code produced by all students is the same (so they can be verified) and so that we can provide our own Morse Code files for your program to convert into the original English text.

English to Morse Code

When translating a file with English text into Morse code, abide by the following rules. Although the current International Morse Code system provides codes for (almost all) non-alphanueric characters we will "translate" these character according to our own rules. See the translated sample files below.
  1. Translate all alphabetic and numeric characters into the appropriate Morse code sequence of dashes and dots according to the table above.
  2. Since a period is a dot, translate it into the pound ('#') character.
  3. Since a hyphen is a dash, translate it into the caret ('^') character.
  4. Separate Morse code sequences for each character within a word with a single space.
  5. Use the pipe ('|') character to denote the last Morse code sequence of a word.
  6. Other than period and hyphen, all other characters (punctuation, whitespace, etc) should written to the output file without translation.

Morse Code to English

As you can see from the rulse above, the Morse code files you will be translating are really a mix of special characters, punctuation, whitepsace, and Morse code sequences. Your translation should abide by the following rules which are essentially the converse of those above.
  1. Morse code sequences should be translated back into the appropriate alphabetic or numeric character.
    Note that Morse code does not distiguish between upper- and lower-case for alphabetic characters. Use upper-case.
  2. The pound character ('#') should be translated into a period.
  3. The caret character ('^') should be translated into a hyphen.
  4. All other characters (other than the pipe ('|') which has special meaning) should be output without translation.

Requirements, Hints and Notes

    Requirements

  1. The order of user input is
    1. Input filename
    2. Output filename
    3. Translation -- use E2M for English to Morse code and M2E for Morse code to English.
  2. If you are unable to open either file, print an appropriate message and exit your program.
  3. You must make appropriate use of functions for this project. In particular, you must write separate functions to translate an alphanumeric character into Morse code and to translate Morse code back to an alphanumeric character. Since these functions can be used by any application that deals with Morse code, these two functions must be placed into their own .c file.
  4. You must provide a makefile that will compile all .c files you submit and create an executable named Project2 when the graders type make.
  5. You must make appropriate use of static for variables and functions.
  6. You must make appropriate use of #define and const variables.
  7. Hints

  8. This project is harder than it seems. Start early.
  9. Consider reading the input file one character at a time using fgetc( ).
  10. To test your code, translate an English language file into Morse code. Your program should be able to reproduce the original English file from the Morse code produced.
  11. Since one alphanumeric character may result in a Morse code sequence of up to 5 dots/dashes, start with small files and short lines when testing your code.
  12. Notes

  13. Since '#', '^', and '|' have special meaning in the Morse code file, they will not appear in any English text file you are asked to translate.

Sample Files

Below is a short English text file and the Morse code file that results from translation. This file is just a small sample and is not intended to represent all possible file contents. Your program should be able to translate the English file into the Morse code file and vice versa.

English text file:

Hello "bob!".
123 454 Hello?

??? Hello      "Johnny   "?

Resulting Morse code file

.... . .-.. .-.. ---| "-... --- -...|!"#
.---- ..--- ...--| ....- ..... ....-| .... . .-.. .-.. ---|?

??? .... . .-.. .-.. ---|      ".--- --- .... -. -. -.--|   "?

Project Grading

Grading for this project will be broken into two parts. Point values shown below represent an apporximate breakdown.
  1. Functionality (45 points)
    Note that your functionality score will be zero if your code does not compile or create an executable.
  2. Code (15 points)

Submitting the Program

You can submit your project using the submit command.

submit cs313 Proj2 makefile <list of .c and .h files>

See this page for a description of other project submission related commands. To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show all files that you submitted in a format similar to the Unix 'ls' command.

submitls cs313 Proj2