Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A - Characters to Morse Code Format You are going to create a Morse Code translator in C/C++. You may use either C or

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Part A - Characters to Morse Code Format You are going to create a Morse Code translator in C/C++. You may use either C or C++ for this assignment. This program will read an input file which will have a series of words using the English Alphabet characters a-z, A-Z. These words will be space delimited with no punctuation. Sentences will terminate with a newline. A file might look something like this: this is a test this too is a test SOS We will be using the International Standard of Morse Code: Remember, you should be handling both lowercase and uppercase letters the same. Characters 'a' and 'A' should translate to the same pattern ".-". The input file will consist of several lines of words with the maximum length of a line being 255 characters (including spaces). There can be any number of lines in a file.Read the file a line at a time as a C-Style String (character array that ends in \\0). Process through each character in the line to translate that character into the appropriate Morse Code pattern. Output that pattern to the output file. Each character should be separated by a | and an actual space should be outputted as a /. If you read in the line "the cat" the output would be: "the cat" > -| . ...1.1/1-.-. | . -I- This is a Row-by-row, character-by-character algorithm. DO NOT try to be clever here. DO NOT just read a single character at a time from the file. Part A Notes: . Remember you are outputting the Morse Code to an output file! o You may also output it to stdout as well if you choose . use some form of getline () to read an entire line from the file o C's getline() can take a file pointer as the source parameter o C++'s cin. getline can be used with your ifstream, if your ifstream is named infile you can do infile. getline() . fscanf("%s") won't be helpful here because scanf delimits on spaces and newlines after reading a whole line from the file, you can use strtok() with space as your delimeter to split up the line into words if you want o process each word a character at a time o You can also just process the whole line a character at a time without tokenizing. . The maximum line length will be 255 characters.Part B - Translate Morse Code back into English Alphabet In Part B, you're going to take a Morse Code file and translate it back into the English Alphabet. This is "easy" if you use strtok() properly and stromp() properly. Reach the Morse Code file a line at a time. The line will be a maximum of ~1785 characters. I think the worse the line can be is 255 characters that translate to a 4 pattern in morse code with a space between each character ie: ----1/| Output the English Character to the output file. Part B Notes: . Remember you're outputting to an output file o You may also output to stdout if you choose . You really only have one delimeter to worry about here | o / represents a space, so handle it accordingly . Look up stromp in #include trust me Requirements: Command line interface: This program will not have any menu interface. It will work entirely as a command line utility. Syntax: Sample translate to morse code: ./morse message_orig. txt -mc message.mc Sample translate to English: ./morse message.mc -e message. txt If the user does not provide the proper command line arguments you should output an error message proving proper usage information!Required Functions: englishToMorse() You should create a function called englishToMorse that takes a character as a parameter and returns a string literal representation as shown above. If a character is passed in other than a-f, A-F or space; return "eeee" Remember a space pass in should return "/" Prototype: const char* englishToMorse(char) ; Very simple input -> output function that will give you a short string literal that you can write to your output file. DO NOT pass the entire line to this function. morseToEnglish() You should create a function called morseToEnglish that takes const char* as a parameter and returns and English character as shown above. If the pattern "eeee" is passed in the function should return a # symbol. Remember a "/" passed in should return a space . '. Prototype: char morseToEnglish (const char*) ; Very simple input -> output function that will give you a character that you can write to your output file. DO NOT pass the entire line to this function.General Notes: . Your program should be able to handle upper-case or lower-case letters o A-F, a-f o There is a simple trick you can do with a switch statement to make this easy . When translating Morse Code back to English you can choose either upper- or lower-case characters for your output. . You should not handle this by relying on a library call to force upper-case or lower-case o You may write YOUR OWN function to do this if you like though . If the user doesn't run the program with proper command-line syntax, you should report an error and give them proper usage . You should not be doing the file 1/0 one character at a time o For English->Morse: . read a whole line, tokenize, then process the tokens one character at a time o Morse->English . read a whole line, tokenize, then process the tokens . Your output should have the same line structure as the input o i.e. newlines should be in the right place\f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions