Create a program simulates the dial of a phone number


Assignment:

Q: Create a program that simulates the dial of a phone number. The program will input a phone number and it will acknowledge the call by either writing an error message or the 8 digit phone number to the console window. The phone number may have either digits, letters, or both.

Here are the letters associated with each digit.

0 5 J K L
1 6 M N O
2 A B C 7 P Q R S
3 D E F 8 T U V
4 G H I 9 W X Y Z

A phone number never begins with a 0 or 555, so the program should flag an error if such a number is entered. A phone number always has a hyphen (-) in the 4th position. If a hyphen is in any other position, it is considered an invalid digit. If the phone number is valid, write the converted number to the output file.

The program should process any number of phone numbers until the user enters a Q.

Sample Output from the Program:

Enter a phone number (Q to quit): 213-2121
Phone Number Dialed: 213-2121

Enter a phone number (Q to quit): asc-dfer
Phone Number Dialed: 272-3337

Enter a phone number (Q to quit): 555-resw
ERROR - Phone number cannot begin with 555

Enter a phone number (Q to quit): 098-8765
ERROR - Phone number cannot begin with 0

Enter a phone number (Q to quit): 12345678
ERROR - Hyphen is not in the correct position

Enter a phone number (Q to quit): @34-*uyt
ERROR - An invalid character was entered

Enter a phone number (Q to quit): Q
Press any key to continue . . .

Using the pseudo code below, write the C++ code that will meet the requirements:
Main Function
Declare the char variables for the 8 digits of the phone number
while true
Call the ReadDials function passing the 8 digits
by reference. ReadDials returns an error code by
value.
If the return value is -5, exit the do while loop
If the error code is -1, display the
error message "ERROR - An invalid character was entered".
If the error code is -2, display the
error message "ERROR - Phone number cannot begin with 0".
If the error code is -3, display the
error message "ERROR - Phone number cannot begin with 555".
If the error code is -4, display the
error message "ERROR - Hyphen is not in the correct position".
Otherwise, call the AcknowledgeCall function
End-While
ReadDials function
Input the first digit
If a Q was entered, return -5.
Input the rest of the phone number
Call the ToDigit function for each of the 7 digits
not for digit 4
If ToDigit returns -1, return -1
If digit 4 is not a hyphen, return -4.
If digit 1 is 0, return -2.
If digits 1 - 3 are 5, return -3
Otherwise, return 0
ToDigit function
Convert the digit to upper case
Use a switch statement to determine if the digit is valid
and convert the letters to digits
If the digit is invalid, return -1.
If the digit is valid, return 0.
AcknowledgeCall function
Display the Phone Number.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Create a program simulates the dial of a phone number
Reference No:- TGS01936905

Now Priced at $25 (50% Discount)

Recommended (93%)

Rated (4.5/5)