Assignment 04

Due: Tuesday, March 2, 2021, at noon, 100 points

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Of course, you will submit in the usual (correct) way.

Background: Bart has been having second thoughts about his life as a street urchin in Springfield. So, he's looking into other ideas about life. I really don't have any idea where this train of thought is going, but we did need some background. You can think of some nonsense to write here.

Specifications: Your program is to present the user with a main menu for a translator. This translator will have the user enter an alphabetic character and give options to convert it into and display its morse code equivalent, or display its ASCII value. But that in itself is kinda boring, isn't it. So, implementing this program with a menu of options, one option will be to generate a random message and its morse code translation. And, of course, your menu of options should have a quit. The menu should look like this:

TRANSLATE --------- 1. Enter a character (alphabetic) prompts for and reads in a valid alpha char 2. Morse code equivalent displays the morse code equivalent of entered letter 3. ASCII value displays the ASCII value of that letter 4. Secret Message this is described below...in a special box...below...below here 5. Kwit quit

Details: The foremost detail for this assignment is that you are required to use functions for much of this code. This does not mean that you will write one or two functions. No, you will use many functions to simplify the overall coding landscape in your program. Here is a suggested main function in pseudocode:

begin main declare necessary variables greetings do option = present_menu() quit = option_handler(option,input,entered) while (!quit) goodbyes end main function

Clearly, the present_menu() function will present the menu of options and return an option that you will pass to the option_handler() function. That function will return a bool indicating quit/notquit. The option_handler() will act upon the option passed and would look something like this:

bool option_handler(char option, char alpha, bool option1_chosen) quit = false decide on (option) option is 1 alpha = get_input_from_user() option1 chosen is true option is 2 if option1_chosen

output morse(alpha) else error_message() option is 3 if option1_chosen output ascii(alpha) else error_message() option is 4 .......you get the idea ......... option is 5 set quit flag return quit end option_handler function

There are some details here that we leave for you to figure out. Furthermore, this is just one idea for how to build the program. There are others, of course, and it is up to you how you want to do it. Another idea would be simply leave the switch statement in main....but this is your decision.

Further Details: The result of choosing option #4 is this. A "message" of randomly chosen letters is generated in the pattern 4 - 3 - 4; that is, a 4-letter word, followed by a 3-letter word, followed by a 4-letter word; printed vertically. (A 'word' is a contiguous string of non-whitespace characters.) A single blank line should be between each word of regular alphabetic characters. In addition, each letter's morse code equivalent is output on the same line as the regular letter spaced over 4 spaces. Here's an example.

TRANSLATE --------- 1. Enter a character (alphabetic) 2. Morse code equivalent 3. ASCII value 4. Secret Message 5. Kwit

Choice: 4

k -.-

d -..

h ....

s ...

k -.-

e .

r .-.

s ...

j .---

d -..

u ..-

Remember: When writing your code, be sure to:

    • Use meaningful variable names.

    • Use proper spacing for indentations.

    • Use constant variable declarations where appropriate.

    • Include the comment block at the head of your file.

    • Comment code that needs it.

    • Be literate in your welcoming/signing-off messages and prompts and output.

    • Make the output pretty and user-friendly.

Note: Don't underestimate the time that it will take to write this program!

As always, if you have questions, don't hesitate to ask your instructor or the LEAD tutors.