I don\'t want the exact answer but a nice place to start would be nice..... here
ID: 3627701 • Letter: I
Question
I don't want the exact answer but a nice place to start would be nice.....
here is the problem itself:
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 digits, letters, or both.
Define a method named ReadDials( ) that reads each digit/letter dialed into eight 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 method 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 fourth position. Make ReadDials( ) return –4 if it doesn't have a hyphen in the fourth 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( ) method to write the converted number to the output file.
All the logic of the program should be put in methods that are called from Main(): ReadDials( ), and AcknowledgeCall( ). The ToDigits() method is called from the ReadDials( ) method 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() method use the Char.ToUpper method 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 methods.
You will set up the eight char variables to hold the digits of the phone number in Main ( ) and pass the variables to the methods by reference.
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
Explanation / Answer
#include
#include
#include
#include
char readDial( int & d);
int toDigit(int & d);
int acknowledgeCall();
int phoneNumber;
using namespace std;
//prototypes
int main()
{
char readDial(int & d);
int returnValue = 0;
while (returnValue != -5)
{
switch(returnValue)
{
case -1: cout << "ERROR - An invalid character was entered" << endl; break;
case -2: cout << "ERROR - Phone number cannont begin with 0" << endl; break;
case -3: cout << "ERROR - Phone number cannont begin with 555" << endl; break;
case -4: cout << "ERROR - Hyphen is not in the correct position" << endl; break;
}
}
}
int toDigit(int & d)
{
toupper(d);
switch(d)
{
case 'A': case 'B': case 'C':
d = '2'; break;
case 'D': case 'E': case 'F':
d = '3'; break;
case 'G': case 'H': case 'I':
d = '4'; break;
case 'J': case 'K': case 'L':
d = '5'; break;
case 'M': case 'N': case 'O':
d = '6'; break;
case 'P': case 'Q': case 'R': case 'S':
d = '7'; break;
case 'T': case 'U': case 'V':
d = '8'; break;
case 'W': case 'X': case 'Y': case 'Z':
d = '9'; break;
}
}
char readDial(int & d)
{
cout << "Please enter a phone number: " << endl;
getline(cin, phoneNumber);
if (phoneNumber == 'Q' || phoneNumber == 'q')
{
return -5;
}
phoneNumber = toDigit(int & d);
}
int acknowledgeCall()
{
cout << "Phone number dialed: " << phoneNumber << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.