0

I have been tearing my hair out over this, and I have written and rewritten the code over and over again. If I can get some kind of direction or where to start, it would be awesome! I put something down there that I have tried for one of the sections, but I haven't been able to get any of my program to work so I could not test it out. I can't show exactly what I have because I am in the middle of rewriting the entire program again. Here is the program:

Write a program that simulates the dial of a phone number. The program will input a phone number and the program 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.

Define a function named ReadDials() that reads each digit/letter dialed into 8 separate char variables (DO NOT USE ARRAYS). All digits are sent back through parameters by reference. Then, for each digit, the program will use a function named ToDigit(), which receives a single char argument (pass by reference) that may be a number or a letter of one of the digits dialed. If it is a number, return 0 by value indicating it is a valid digit. If the digit is a letter, the number corresponding to the letter is returned by reference and return 0 by value indicating it is a valid digit. 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

If the digit entered is not one of the valid digits or valid letters, return –1 by value indicating that you have an invalid digit.

A phone number never begins with a 0, so the program should flag an error if such a number is entered. Make ReadDials() return –2 in this case. Also a phone number never begins with 555, so the program should flag an error if such a number is entered. Make ReadDials() return –3 in this case. A phone number always has a hyphen (-) in the 4th position. Make ReadDials() return –4 if it doesn't have 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, main calls the AcknowledgeCall function to write the converted number to the output file.

All the logic of the program should be put in functions that are called from Main(): ReadDials(), and AcknowledgeCall(). The ToDigits() function is called from the ReadDials() function and is used to convert each letter entered individually to a digit and to verify the user has entered a valid phone number. Have the program work for any number of phone numbers. Continue processing until the user enters a Q.

In the ToDigits() function use the toupper function to convert any letters entered to uppercase. All error messages are to be written to the output file from main() based on the return value from the functions.

You will set up the 8 char variables to hold the digits of the phone number in main() and pass the variables to the functions by reference.

I have to write a code to meet:
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......."
if the error code is -2, display the error message "Error......"
if the error code is -3, display.....
If the error code is -4, display......
Otherwise, call the AcknowledgeCall function
End-while

For the section above, I have:

while (returnValue != -5)
{
    returnValue = d1, d2, d3, d4, d5, d6, d7, d8;
    switch (returnValue)
    {
    case -1: cout << "ERROR - An invalid character was entered." << endl; break;
    case -2: cout << "ERROR - Phone number cannot being with 0." << endl; break;
    case -3: cout << "ERROR - Phone number cannot being with 555." << endl; break;
    case -4: cout << "ERROR - Hyphen is not in the correct position." << endl; break;
    case -5: cout << "Phone number is:  " << endl; break;
    default: AcknowledgeCall (d1, d2, d3, d4, d5, d6, d7, d8);
    }


}
return 0;
}

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

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by arkoenig
1

Two suggestions:

1) Learn how to use code tags; without them, your code is very hard to read.

2) Pick one function from the collection of functions described in your assignment and implement that. Post your implementation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.