| HINT: Use the string class member functions at() and length(). See code example on Moodle. 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. 5. 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. ****** LINK FOR TelephoneData.txt***** https://moodle.cpcc.edu/pluginfile.php/1098482/mod_assign/intro/TelephoneData.txt *** Data that is in Link above: Leslie Knope 1456 Plymouth Street Pawnee IN 47408 117 Tom Haveford 689 Lil Sebastian Avenue Eagleton IN 47320 34 April Ludgate 1123 9th Avenue Wamapoke IN 48034 60 Jery Gergich 3124 Woodbridge Road Pawnee IN 47407 378 Donna Meagle 1200 Elysian Fields Blvd Eagleton IN 47322 245 **** SAMPLE OUTPUT: | Welcome to Western Union Telegraph Company 1 Process Telegram Bill 2 Translate to Morse Code 3 Process a Data File 4 - Quit Enter your choice: 2 Enter a message: Thats it! Translation: - . . . . . - - . . . . . - ! 1 Process Telegram Bill 2 Translate to Morse Code 3 Process a Data File 4 - Quit Enter your choice: 3 Leslie Knope 1456 Plymouth Street Pawnee, IN 47408 Amount Owed: $35.50 Tom Haveford 689 Lil Sebastian Avenue Pawnee, IN 47408 Amount Owed: $11.00 April Ludgate 1123 9th Avenue Wamapoke, IN 48034 Amount Owed: $18.00 | Jery Gergich 3124 Woodbridge Road Eagleton, IN 47322 Amount Owed: $114.00 Donna Meagle 1200 Elysian Fields Blvd Eagleton, IN 47322 Amount Owed: $73.50 1 Process Telegram Bill 2 Translate to Morse Code 3 Process a Data File 4 - Quit Enter your choice: 44 44 is not a valid choice 1 Process Telegram Bill 2 Translate to Morse Code 3 Process a Data File 4 - Quit Enter your choice: 4 Thank you. Closing program. | ********** EXISTING CODE********** #include // needed for cin/cout class #include // needed for string class #include // needed for output formatting using namespace std; int main() { //declear const double Per_Five = 1.50; const double Per_Single = 0.50; //declear string CustName, street, city, state, zip; int words, BlockFiveWords, remSingleWords, payment, change, dollars, quarters, dimes, nickels, pennies, choice; double amountDue; char letter; cout<< "Welcome to Western Union Telegraph Company " << "1 - Process Telegram Bill " << "2 - Translate to Morse Code"< cout<<"Enter your choice:" << endl; cin>>choice; cin.ignore(); switch (choice) { case 1: //prompts for input cout<< "Enter the name of the customer: "; getline(cin, CustName); cout << "Enter street address: "; getline(cin,street); cout<<"Enter the city:"; getline(cin,city); cout<<"Enter State: "; getline(cin,state); cout<<"Enter zip:"; getline(cin,zip); cout<<"Enter the number of words to be sent: "; cin>>words; // find the number of 5 blocks of words and the remainder BlockFiveWords = words /5; remSingleWords = words % 5; //calculate total amount due amountDue = (BlockFiveWords * Per_Five) + (remSingleWords * Per_Single); //display input cout<< endl << CustName << endl; cout<< street << endl; cout<< city << "," << state << " " << zip << endl; //display amount owned,fixed decimal at 2 places cout<< setprecision(2)<< fixed; cout << "Amount Owned: " << amountDue << endl; // enter amount in pennies cout<< endl<< "Enter the amount recieved from customer: "; cin>>payment; if (payment>=amountDue) { //calculat the amount of each denomination change = payment - (amountDue * 100); dollars = change / 100; quarters = (change % 100 ) / 25; dimes = ((change % 100 )- (quarters*25)) / 10; nickels+(change - (dollars*100)-(quarters*25)-(dimes*10))/5; pennies = change - (dollars*100)-(quarters*25)-(dimes*10)-(nickels*5); //Display change due in appropriate denominations cout <<\ endl << left < cout << left << setw(15) << "-----------" << right << setw(15)<< "----------" << endl; cout << "Dollars " << right << setw(15) < cout << "Quarters" << right << setw(15) << quarters << endl; cout << "Dimes" << right << setw(18) << dimes << endl; cout << "Nickles" << right << setw(16) << nickels << endl; cout << "Pennies" << right << setw(16) << pennies << endl; } else { cout<<"Erorr! The customer has not paid enough." << endl; } break; case 2: cout<< endl << "Enter a single letter: " << endl; cin>>letter; if (letter =='A'|| letter =='a') {cout<< "The letter" << " " << letter << " " << "translates to .-" << endl; } else if (letter == 'B'|| letter =='b') { cout<< "The letter" << " "<< letter << " " << "translates to -..." << endl; } else if (letter =='C'||letter == 'c') { cout<< "The letter" << " "<< letter << "translates to -.-." << " " << endl; } else if (letter =='D'|| letter =='d') { cout<< "The letter" << " "<< letter << " " << "translates to -.." < else if (letter=='E'|| letter=='e') { cout<< "The letter" << " "<< letter << " " << "translates to ." << endl; } else if (letter=='F'||letter=='f'){ cout<< "The letter" << " " << letter << " " << "translate to ..-." << endl; } else if ( letter=='G'||letter=='g') {cout<<"The letter" << " "<< letter << " " << "translates to --." << endl; } else if (letter == 'H'|| letter =='h') {cout<< "The letter" << " "<< letter << " " << "translates to ...." << endl; } else if (letter=='I'|| letter=='i') { cout<< "the letter" << " "<< letter << " " << "translates to .." << endl;} else if (letter=='J'||letter=='j'){ cout<< "The letter" << " "<< letter << " " << "translates to .---" << endl; } else if (letter=='K'||letter=='k'){ cout<< "The letter" << " "<< letter << " " << "translates to -.-" << endl; } else if (letter=='L'||letter=='l'){ cout<< "The letter" << " "<< letter << " " << "translates to .-.." << endl; } else if (letter=='M'||letter=='m') { cout<< "The letter" << " "<< letter << " " << "translates to --" << endl; } else if (letter=='N'||letter=='n') { cout<< "The letter" << " "<< letter << " " << "translates to -." << endl; } else if (letter=='O'||letter=='o') { cout<< "The letter" <<" "<< letter << " " << "translates to ---" << endl; } else if (letter=='P'||letter=='p') { cout<< "The letter" << " "<< letter << " " << "translates to .--." << endl; } else if (letter=='Q'||letter=='q') { cout<< "The letter" << " "<< letter << " " << "translates to --.-" << endl; } else if (letter=='R'||letter=='r') { cout<< "The letter" << " "<< letter << " " << "translates to .-." << endl; } else if (letter=='S'||letter=='s'){ cout<< "The letter" << " "<< letter << " " << "translates to ..." << endl; } else if (letter=='T'||letter=='t'){ cout<<"The letter" << " "<< letter << " " << "translates to -"<< endl; } else if (letter=='U'||letter=='u'){ cout<<"The letter" << " " << letter << " " << "translates to ..-" << endl; } else if (letter=='V'||letter=='v'){ cout<< "The letter" << " "<< letter << " " << "translates to ...-" << endl; } else if (letter=='W'||letter=='w') { cout<<"The letter" << " "<< letter << " " << "translates to .--" << endl; } else if (letter=='X'||letter=='x') { cout<<"The letter" << " "<< letter << " " << "translates to -..-" << endl; } else if (letter=='Y'||letter=='y') { cout<< "The letter" << " "<< letter << " " << "translates to -.--" << endl; } else if (letter=='Z'||letter=='z') { cout<< "The letter" << " "<< letter << " " << "translates to --.."< } break; default: cout<<"Error!" << " " << choice << " " << "is not a valid choice." << endl; break; } return 0; } |