Please whoever answers this try to make it sim[le and easy I am very new at this.
this is the question:
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.
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 toupperfunction 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.
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 . . .
| ||||||||||||||||||||
Step 2: Processing Logic | ||||||||||||||||||||
Using the pseudo code below, write the code that will meet the requirements: Main Function while true If the return value is -5, exit the do while loop If the error code is -1, display the ReadDials function Input the first digit Call the ToDigit function for each of the 7 digits ToDigit function If the digit is invalid, return -1. AcknowledgeCall function |
This is what I have so far :
# include <iostream>
# include <string>
# include <cctype>
# include <iomanip>
using namespace std;
// prototypes
int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5,char &d6, char &d7, char &d8);
char Todigit(char &d);
void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
// function main
int main()
{
char d1, d2, d3, d4, d5, d6, d7, d8;
int returnValue = 0;
while (returnValue != -5)
{
returnValue = ReadDial (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 begin with 0" << endl; break;
case -3: cout << "Error- Phone number cannot begin with 555" << endl; break;
case -4: cout << "Error- Hyphen is not in the correct position" << endl; break;
default: AcknowledgeCall (d1, d2, d3, d4, d5, d6, d7, d8);
}
}
return 0;
}
// function ReadDial
int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)
{
int returnValue;
cout << "Enter a phone number (Q to quit): ";
cin >> d1;
if(d1 == 'Q') return -5;
cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
returnValue = Todigit(d1);
if (returnValue == -1)
return returnValue;
returnValue = Todigit(d2);
if (returnValue == -1)
return returnValue;
returnValue = Todigit(d3);
if (returnValue == -1)
return returnValue;
if (d4 != '-')
return -4;
returnValue = Todigit(d5);
if (returnValue == -1)
return returnValue;
returnValue = Todigit(d6);
if (returnValue == -1)
return returnValue;
returnValue = Todigit(d7);
if (returnValue == -1)
return returnValue;
returnValue = Todigit(d8);
if (returnValue == -1)
return returnValue;
if (d1 == '0')
return -2;
if (d1 == '5' && d2 == '5' && d3 == '5')
return -3;
return 0;
}
//function ToDigit
char Todigit(char &d)
{
d = toupper(d);
switch(d)
{
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break;
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;
default: return -1;
}
}
// function AcknowledgeCall
void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)
{
cout << "Phone Number Dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl << endl;
}
I dont know what else to do and it is do today. Thanks