Project #28936 - morse code to english program

This program needs to be written in visual studio in C code. This needs to be in 3 file format (header.h, functions.c, main.c)

Write a program that converts English-language phrases into Morse code and Morse code back to English-language phrases. The program should also keep track of the number of characters converted from English text to Morse code and vice versa. For this program, you will need to prompt the user to determine the conversion option (-m means convert from English text to Morse code, -t means convert from Morse code to English text) and the source and destination file names. The source filename will be the file from which you read and the destination filename will be the file to which you will write.  For example:

[Your Prompt]:   -m    english.txt    morse.txt

would indicate that the file called english.txt should be opened for reading and that the file morse.txt should be opened for writing. Essentially the file english.txt, which contains the English-language text (with no punctuation or special characters), needs to be converted to Morse Code and outputted to morse.txt.

If you type -t    morse.txt    english.txt at the prompt, then you will need to convert the Morse code contents of morse.txt to English text and output to english.txt. You may assume that the user enters the format of the strings at the prompt correctly, i.e. the number of strings is always three, etc. The only error checking that you will have to perform for the user input is that the files may be opened for read or write.

I highly recommend that when you are performing English text to Morse code conversion, that you read character-by-character from the English text file. Once you have read a character convert it to uppercase (you may want to use <ctype.h> for this!). As you process each English character you will need to output the corresponding Morse string to the specified output file. All white spaces in the English text file should be preserved in the Morse code file. Also, all newline characters should be preserved. When you convert from Morse code to English text, I would recommend reading on Morse string at a time. Remember these strings will be separated by white space.

Hints and Requirements

1. Create two File pointers, one for accessing the source and destination file. Create an integer for keeping track of the total number of English characters converted to Morse code or the number of Morse strings converted if converting from Morse code to English text.

2. Create one two dimensional array of characters that will be used to store the Morse strings. Remember that a two dimensional array of characters may be used to store an array of strings, where the number of rows is the number of strings that may be stored and the number of columns is the maximum length of each string. For this program you will be required to use the ASCII value of the English character as the row index of the corresponding Morse string. Thus, you will be required to declare a two dimensional array of 91 rows because 'A' - 'Z' correspond to ASCII values of 65 - 90. According to the above table you notice that the longest Morse string is five characters (see the digit strings) plus one for the null character. I recommend declaring the array as follows:

        morse_strings[91][6];

3. Setup the morse_strings array with the correct Morse code as provided in the above table. You will be required to use strcpy(). We know that 'A' has an ASCII value of 65 and corresponds to Morse code .- and that character '0' has an ASCII value of 48 and corresponds to Morse code ----- The below fragment of code illustrates how to setup the array:

     strcpy (morse_strings['A'], ".-"); // You need to initialize all alpha characters

     strcpy (morse_strings['0'], "-----"); // You need to initialize all digit characters

4. Open source file for read mode and the destination file for write mode. Perform error checking when trying to open the files.

5. When performing English text to Morse code conversion, read character-by-character from the source file, convert the character to uppercase, and write the corresponding Morse string (found in morse_strings array) to the output file. Make sure that you separate each morse string corresponding to a single English character by whitespace. Be careful with whitespaces and newlines! Think about how you will perform the Morse code to English text conversion!

6. When performing English text to Morse code conversion (or Morse code to English text conversion), print the total number of English characters (or Morse code strings) converted to the screen in following form:

        Total characters converted successfully: 24

7. Close the text files.

Sample Execution

[Your prompt]:   -m    english.txt    morse.txt

english.txt

    This is a sample

    program

morse.txt

    - .... .. ...  .. ...  .-  ... .- -- .--. .-.. .

    .--. .-. --- --. .-. .- --

Output

        Total characters converted successfully: 24     // including the newline and white spaces

 

 

Subject Computer
Due By (Pacific Time) 04/30/2014 04:00 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy