Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this part of the project, you will add the functionality to translate a complete message into morse code and the functionality to process a

For this part of the project, you will add the functionality to translate a complete message into morse code and the functionality to process a data file containing multiple records. You will also modify your input validation code to give the user an unlimited number of chances to enter valid responses. Your program should continue to run until the user chooses a quit option from your menu. Instructions: Add an option to the menu to offer the user a choice of processing a data file. Add another option to quit the program. The menu should be the first thing displayed when your program begins executing. The menu format should match the one in the Sample Output on page 3. Allow the user to continue making menu choices until they choose the option to quit. Always display the menu before prompting the user for a menu option. Properly handle an invalid menu choice. The user should have an unlimited number of chances to enter a valid menu choice. Modify the code you wrote in Project 2 to validate the users input for payment amount to allow user an unlimited number of chances to enter a valid payment amount. Modify the code you wrote in Project 2 to translate a single letter into a morse code. Your code should now be able to efficiently translate a complete message into morse code. (no code duplication). All white spaces in message should be translated into 3 corresponding white spaces in morse code. HINT: Use the string class member functions at() and length(). If any part of the message cannot be translated into morse code, instead of displaying an error message like you did in Project 2, your code should display the untranslated character. Add functionality to create and display telegram bills by reading input from the TelegramData.txt text file. When the user selects the option to process a data file, telegram bills should be created and displayed for every record in the file without the user needing to do anything else. The TelegramData .txt file contains 5 records, but your program must be able to process an identically formatted file with any number of records without counting the records. You do not need to process payment information if this option is chosen by the user.

I can only use knowledge from Chapter 1 - 5 in the bookStarting Out With Cpp From Control Structures Through Objects 8th Edition

PROJECT 2 CODE:

#include #include #include using namespace std; int main() { //variables string cName, stAddress, city, state; char letter; int zip, wordsSent, recieved, change, choice; float total; const float fiveBlock = 1.50; const float singleBlock = 0.50; //input cout << "Welcome to Western Union Telegraph Company" << endl; cout << "1 - Process Telegram Bill" << endl << "2 - Translate to Morse Code"; cout << endl << endl; cout << "Enter your choice: "; cin >> choice; cin.ignore(); switch (choice) { case 1: cout << "Enter the name of the customer: "; getline(cin, cName); cout << "Enter the customer's address: "; getline(cin, stAddress); cout << endl << "Enter city: "; getline(cin, city); cout << "Enter state: "; getline(cin, state); cout << "Enter zip code: "; cin >> zip; cout << "Enter the number of words sent: "; cin >> wordsSent; total = ((wordsSent /5) * fiveBlock) + ((wordsSent %5) *singleBlock); cout << endl << cName << endl << stAddress << endl; cout << city << ", " << state << " " << zip << endl; cout << "Amount Owed: $" << setprecision(2) << fixed << total << endl << endl; total *= 100; cout << "Enter the amount recieved from the customer: "; cin >> recieved; if (recieved >= total) { change = recieved - (total); cout << " Denomination Number" << endl; cout << "-------------- ---------------" << endl; cout << " Dollars " << change /100 << endl; change %= 100; cout << " Quarters " << change / 25 << endl; change %= 25; cout << " Dimes " << change / 10 << endl; change %= 10; cout << " Nickels " << change / 5 << endl; change %= 5; cout << " Pennies " << change << endl; } else { cout << "Sorry this customer has not paid enough."; } break; case 2: cout << endl << "Enter a single letter: "; cin >> letter; if (!(letter >= 'a' || letter <= 'z') || !(letter >= 'A' && letter <= 'Z')){ cout << "Sorry I can't convert that" << endl << endl; } else if (letter == 'A' || letter == 'a') { cout << "The letter " << letter << " translates to .-" << endl << endl; } else if (letter == 'B' || letter == 'b') { cout << "The letter " << letter << " translates to -..." << endl << endl; } else if (letter == 'C' || letter == 'c') { cout << "The letter " << letter << " translates to -.-." << endl << endl; } else if (letter == 'D' || letter == 'd') { cout << "The letter " << letter << " translates to -.." << endl << endl; } else if (letter == 'E' || letter == 'e') { cout << "The letter " << letter << " translates to ." << endl << endl; } else if (letter == 'F' || letter == 'f') { cout << "The letter " << letter << " translates to ..-." << endl << endl; } else if (letter == 'G' || letter == 'g') { cout << "The letter " << letter << " translates to --." << endl << endl; } else if (letter == 'H' || letter == 'h') { cout << "The letter " << letter << " translates to ...." << endl << endl; } else if (letter == 'I' || letter == 'i') { cout << "The letter " << letter << " translates to .." << endl << endl; } else if (letter == 'J' || letter == 'j') { cout << "The letter " << letter << " translates to .---" << endl << endl; } else if (letter == 'K' || letter == 'k') { cout << "The letter " << letter << " translates to -.-" << endl << endl; } else if (letter == 'L' || letter == 'l') { cout << "The letter " << letter << " translates to .-.." << endl << endl; } else if (letter == 'M' || letter == 'm') { cout << "The letter " << letter << " translates to --" << endl << endl; } else if (letter == 'N' || letter == 'n') { cout << "The letter " << letter << " translates to -." << endl << endl; } else if (letter == 'O' || letter == 'o') { cout << "The letter " << letter << " translates to ---" << endl << endl; } else if (letter == 'P' || letter == 'p') { cout << "The letter " << letter << " translates to .--." << endl << endl; } else if (letter == 'Q' || letter == 'q') { cout << "The letter " << letter << " translates to " << endl << endl; } else if (letter == 'R' || letter == 'r') { cout << "The letter " << letter << " translates to .-." << endl << endl; } else if (letter == 'S' || letter == 's') { cout << "The letter " << letter << " translates to ..." << endl << endl; } else if (letter == 'T' || letter == 't') { cout << "The letter " << letter << " translates to -" << endl << endl; } else if (letter == 'U' || letter == 'u') { cout << "The letter " << letter << " translates to ..-" << endl << endl; } else if (letter == 'V' || letter == 'v') { cout << "The letter " << letter << " translates to " << endl << endl; } else if (letter == 'W' || letter == 'w') { cout << "The letter " << letter << " translates to .--" << endl << endl; } else if (letter == 'X' || letter == 'x') { cout << "The letter " << letter << " translates to -..-" << endl << endl; } else if (letter == 'Y' || letter == 'y') { cout << "The letter " << letter << " translates to -.--" << endl << endl; } else if (letter == 'Z' || letter == 'z') { cout << "The letter " << letter << " translates to --.." << endl << endl; } break; default: cout << "Sorry " << choice << " is not a valid choice." << endl; break; } return 0; }

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_2

Step: 3

blur-text-image_3

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago