Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program: Translating Text to Morse Code Program needs to be able to translate a character of input into the equivalent Morse code. The mappings

C++ Program: Translating Text to Morse Code

Program needs to be able to translate a character of input into the equivalent Morse code. The mappings of the characters to Morse code will be in an input file that your program will read in.

First of all, need at least 4 functions (including main function). General areas of delegation: file input, character translation, and primary processing loop (read in data from cin and translate it to Morse code)

Text to be translated will be read in from cin. Program will read in text from cin and translate it to Morse code as long as the user hasn't entered in the text quit as the input. Characters read in from cin should be folded into upper case (input of a and A should both map to Morse code .- character sequence). Space character should map to a space character. A character that doesn't map to Morse code (like $) should be ouput in double quotes (like "$") to indicate that text wasn't translated.

Processing:

Program will first ask for name of file that contains the mapping. Program should the open this file and read values into two arrays. One array will contain the characters that are being mapped from and second array will contain equivalent Morse code. Once array have been built, the program will read in text from cin and translate it into Morse code. An input text that contains lower case characters: quit will indicate that programming should stop.

Input File Format & Requirements:

Input file will contain mappings from characters to the equivalent Morse code. Program should be able to handle any mapping files that is given to it. Standarad verison of Morse code is defined by the mapping.txt file. This maps 39 characters to Morse code. There's a second file, mapping2.txt, that maps some additional characters and implements an extended version of Morse code. Program must be able to handle either of these files or any other files that follow the same format as mapping.txt and mapping2.txt files.

Character Mappings:

Program must dynamically read in the input file and create two arrays. Size of these arrays is the first value in the input file. Program must dynamically create two arrays based on size read in from the input file. Program must also free up memory used by two arrays before it ends. Program must work with any number of mappings and shouldn't be limited to values specified in two sample files.

Translation of Characters:

Most of the mappings of input characters to output characters is determined by the contents of the two arrays you create from input file. When you translate a space character, you must map that to a space character. Any character not in the input file will map to itself, but will be enclosed in double quotation marks in the output.

You want to read in an entire line of text from cin for your translations. You should use getline to do this.

Stopping the Program:

Program will terminate if input file can't be opened. You need to output an error message in this case. Your program will read in multiple lines of text from cin. value of quit will terminate the program.

Additional Requirements:

You must pass values from one function to another. No global variable are allowed in this program.

Program Output:

Here is some sample output. Your output of the text file must match what is shown here fro the same input.

Enter in the name of the input file that contains the mapppings (strings to Morse code)

mapping.txt [Enter]

Enter the string to be translated (or quit to exit)

Starting out w/C++: [Enter]

Translate to

... . .-.. .-.. --- .-- --- .-. .-.. -.. "!"

Enter the string to be translated (or quit to exit)

quit [Enter]

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

=+1. What do the authors mean by theories of caring?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago