EDN Admin
Well-known member
Please whoever answers this try to make it sim[le and easy I am very new at this.
this is the question:
<table border="1" cellspacing="0" cellpadding="0" width="673" height="2121" style="border-collapse:collapse; border:medium none
<tbody>
<tr style="height:30.1pt
<td width="673" valign="top" style="width:504.9pt; border:1pt solid windowtext; padding:0in 5.4pt; height:30.1pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" Write a program that simulates the dial of a phone number.<span>
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.<span>
The phone number may have either digits, letters, or both.<span>
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" Define a function named ReadDials() that reads each digit/letter dialed into 8 separate char variables (DO NOT USE ARRAYS).<span>
All digits are sent back through parameters by reference.<span>
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.<span>
If it is a number, return 0 by value indicating it is a valid digit.<span>
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.<span>
Here are the letters associated with each digit.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<table border="1" cellspacing="0" cellpadding="0" style="
<tbody>
<tr>
<td width="72" valign="top" style="width:0.75in; border:1pt solid windowtext; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 0
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif"
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 5
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" J<span>
K<span> L
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 1
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif"
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 6
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" M<span>
N<span> O
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 2
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" A<span>
B<span> C
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 7
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" P<span>
Q<span> R<span> S
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 3
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" D<span>
E<span> F
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 8
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" T<span>
U<span> V
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 4
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" G<span>
H<span> I
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 9
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" W<span>
X<span> Y<span> Z
</td>
</tr>
</tbody>
</table>
<span style="font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" 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.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" A phone number never begins with a 0, so the program should flag an error if such a number is entered.<span>
Make ReadDials() return â2 in this case.<span> Also a phone number never begins with 555, so the program should flag an error if such a number is entered.<span>
Make ReadDials() return â3 in this case.<span> A phone number always has a hyphen (-) in the 4th position.<span>
Make ReadDials() return â4 if it doesnt have a hyphen in the 4th position.<span>
If a hyphen is in any other position, it is considered an invalid digit.<span>
If the phone number is valid, main calls the AcknowledgeCall function to write the converted number to the output file.
<span style="font-size:11pt; font-family:"Arial","sans-serif" <span>
<span style="font-size:11pt; font-family:"Arial","sans-serif" All the logic of the program should be put in functions that are called from Main():<span>
ReadDials(), and AcknowledgeCall().<span> 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.<span>
Have the program work for any number of phone numbers.<span>
Continue processing until the user enters a Q.
<span style="font-size:11pt; font-family:"Arial","sans-serif" <span>
<span style="font-size:11pt; font-family:"Arial","sans-serif" In the ToDigits() function use the toupper <span>
function to convert any letters entered to uppercase.<span>
All error messages are to be written to the output file from main() based on the return value from the functions.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" 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.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Sample Output from the Program:
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 213-2121
<span style="font-family:"Arial","sans-serif" Phone Number Dialed: 213-2121
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): asc-dfer
<span style="font-family:"Arial","sans-serif" Phone Number Dialed: 272-3337
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 555-resw
<span style="font-family:"Arial","sans-serif" ERROR - Phone number cannot begin with 555
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 098-8765
<span style="font-family:"Arial","sans-serif" ERROR - Phone number cannot begin with 0
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 12345678
<span style="font-family:"Arial","sans-serif" ERROR - Hyphen is not in the correct position
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): @34-*uyt
<span style="font-family:"Arial","sans-serif" ERROR - An invalid character was entered
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): Q
<span style="font-family:"Arial","sans-serif" Press any key to continue . . .
<span style="font-family:"Arial","sans-serif"
</td>
</tr>
<tr>
<td width="673" valign="top" style="width:504.9pt; background:none repeat scroll 0% 0% #b7e4ff; padding:0in 5.4pt
<span style="font-family:"Arial","sans-serif" Step 2: <span style="font-family:"Arial","sans-serif" Processing Logic
</td>
</tr>
<tr style="height:30.1pt
<td width="673" valign="top" style="width:504.9pt; padding:0in 5.4pt; height:30.1pt
<span style="font-family:"Arial","sans-serif" Using the pseudo code below, write the code that will meet the requirements:
<span style="font-size:11pt; font-family:"Arial","sans-serif" Main Function<br/>
Declare the char variables for the 8 digits of the phone number
<span style="font-size:11pt; font-family:"Arial","sans-serif" while true<br/>
Call the ReadDials function passing the 8 digits<br/>
by reference. ReadDials returns an error code by<br/>
value.
<span style="font-size:11pt; font-family:"Arial","sans-serif" If the return value is -5, exit the do while loop
<span style="font-size:11pt; font-family:"Arial","sans-serif" If the error code is -1, display the<br/>
<span> error message "ERROR - An invalid character was entered".<br/>
If the error code is -2, display the<br/>
<span> error message "ERROR - Phone number cannot begin with 0".<br/>
If the error code is -3, display the<br/>
<span> error message "ERROR - Phone number cannot begin with 555".<br/>
If the error code is -4, display the<br/>
<span> error message "ERROR - Hyphen is not in the correct position".<br/>
Otherwise, call the AcknowledgeCall function
<span style="font-size:11pt; font-family:"Arial","sans-serif" <br/>
<span> End-While
<span style="font-size:11pt; font-family:"Arial","sans-serif" ReadDials function
<span style="font-size:11pt; font-family:"Arial","sans-serif" Input the first digit<br/>
If a Q was entered, return -5.<br/>
Input the rest of the phone number
<span style="font-size:11pt; font-family:"Arial","sans-serif" Call the ToDigit function for each of the 7 digits<br/>
<span> not for digit 4<br/>
If ToDigit returns -1, return -1<br/>
If digit 4 is not a hyphen, return -4.<br/>
If digit 1 is 0, return -2.<br/>
If digits 1 - 3 are 5, return -3<br/>
Otherwise, return 0
<span style="font-size:11pt; font-family:"Arial","sans-serif" ToDigit function<br/>
Convert the digit to upper case<br/>
Use a switch statement to determine if the digit is valid<br/>
<span> and convert the letters to digits
<span style="font-size:11pt; font-family:"Arial","sans-serif" If the digit is invalid, return -1.<br/>
If the digit is valid, return 0.
<span style="font-size:11pt; font-family:"Arial","sans-serif" AcknowledgeCall function<br/>
<span> Display the Phone Number.
</td>
</tr>
</tbody>
</table>
This is what I have so far :
# include <iostream><br/>
<br/>
# include <string><br/>
<br/>
# include <cctype><br/>
<br/>
# include <iomanip><br/>
<br/>
using namespace std;<br/>
<br/>
// prototypes<br/>
<br/>
int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5,char &d6, char &d7, char &d8);<br/>
<br/>
char Todigit(char &d);<br/>
<br/>
void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);<br/>
<br/>
<br/>
<br/>
// function main<br/>
<br/>
int main()<br/>
<br/>
{<br/>
<br/>
char d1, d2, d3, d4, d5, d6, d7, d8;<br/>
<br/>
int returnValue = 0;<br/>
<br/>
while (returnValue != -5)<br/>
<br/>
{<br/>
<br/>
returnValue = ReadDial (d1, d2, d3, d4, d5, d6, d7, d8);<br/>
<br/>
switch (returnValue)<br/>
<br/>
{<br/>
<br/>
case -1: cout << "Error- An invalid character was entered" << endl; break;<br/>
<br/>
case -2: cout << "Error- Phone number cannot begin with 0" << endl; break;<br/>
<br/>
case -3: cout << "Error- Phone number cannot begin with 555" << endl; break;<br/>
<br/>
case -4: cout << "Error- Hyphen is not in the correct position" << endl; break;<br/>
<br/>
default: AcknowledgeCall (d1, d2, d3, d4, d5, d6, d7, d8);<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
return 0;<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
// function ReadDial<br/>
<br/>
int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)<br/>
<br/>
{<br/>
<br/>
int returnValue;<br/>
<br/>
cout << "Enter a phone number (Q to quit): ";<br/>
<br/>
cin >> d1;<br/>
<br/>
if(d1 == Q) return -5;<br/>
<br/>
cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;<br/>
<br/>
returnValue = Todigit(d1);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d2);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d3);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
if (d4 != -)<br/>
<br/>
return -4;<br/>
<br/>
returnValue = Todigit(d5);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d6);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d7);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d8);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
if (d1 == 0)<br/>
<br/>
return -2;<br/>
<br/>
if (d1 == 5 && d2 == 5 && d3 == 5)<br/>
<br/>
return -3;<br/>
<br/>
return 0;<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
//function ToDigit<br/>
<br/>
<br/>
<br/>
char Todigit(char &d)<br/>
<br/>
{<br/>
<br/>
d = toupper(d);<br/>
<br/>
switch(d)<br/>
<br/>
{<br/>
<br/>
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: break;<br/>
<br/>
case A: case B: case C: d = 2; break;<br/>
<br/>
case D: case E: case F: d = 3; break;<br/>
<br/>
case G: case H: case I: d = 4; break;<br/>
<br/>
case J: case K: case L: d = 5; break;<br/>
<br/>
case M: case N: case O: d = 6; break;<br/>
<br/>
case P: case Q: case R: case S: d = 7; break;<br/>
<br/>
case T: case U: case V: d = 8; break;<br/>
<br/>
case W: case X: case Y: case Z: d = 9; break;<br/>
<br/>
default: return -1;<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
// function AcknowledgeCall<br/>
<br/>
void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)<br/>
<br/>
{<br/>
<br/>
<br/>
<br/>
<br/>
cout << "Phone Number Dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl << endl;<br/>
<br/>
}
I dont know what else to do and it is do today. Thanks
View the full article
this is the question:
<table border="1" cellspacing="0" cellpadding="0" width="673" height="2121" style="border-collapse:collapse; border:medium none
<tbody>
<tr style="height:30.1pt
<td width="673" valign="top" style="width:504.9pt; border:1pt solid windowtext; padding:0in 5.4pt; height:30.1pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" Write a program that simulates the dial of a phone number.<span>
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.<span>
The phone number may have either digits, letters, or both.<span>
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" Define a function named ReadDials() that reads each digit/letter dialed into 8 separate char variables (DO NOT USE ARRAYS).<span>
All digits are sent back through parameters by reference.<span>
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.<span>
If it is a number, return 0 by value indicating it is a valid digit.<span>
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.<span>
Here are the letters associated with each digit.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<table border="1" cellspacing="0" cellpadding="0" style="
<tbody>
<tr>
<td width="72" valign="top" style="width:0.75in; border:1pt solid windowtext; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 0
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif"
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 5
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" J<span>
K<span> L
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 1
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif"
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 6
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" M<span>
N<span> O
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 2
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" A<span>
B<span> C
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 7
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" P<span>
Q<span> R<span> S
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 3
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" D<span>
E<span> F
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 8
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" T<span>
U<span> V
</td>
</tr>
<tr>
<td width="72" valign="top" style="width:0.75in; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 4
</td>
<td width="175" valign="top" style="width:131.4pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" G<span>
H<span> I
</td>
<td width="71" valign="top" style="width:53.1pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" 9
</td>
<td width="156" valign="top" style="width:117pt; padding:0in 5.4pt
<span style="font-size:11pt; font-family:"Arial","sans-serif" W<span>
X<span> Y<span> Z
</td>
</tr>
</tbody>
</table>
<span style="font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" 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.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" A phone number never begins with a 0, so the program should flag an error if such a number is entered.<span>
Make ReadDials() return â2 in this case.<span> Also a phone number never begins with 555, so the program should flag an error if such a number is entered.<span>
Make ReadDials() return â3 in this case.<span> A phone number always has a hyphen (-) in the 4th position.<span>
Make ReadDials() return â4 if it doesnt have a hyphen in the 4th position.<span>
If a hyphen is in any other position, it is considered an invalid digit.<span>
If the phone number is valid, main calls the AcknowledgeCall function to write the converted number to the output file.
<span style="font-size:11pt; font-family:"Arial","sans-serif" <span>
<span style="font-size:11pt; font-family:"Arial","sans-serif" All the logic of the program should be put in functions that are called from Main():<span>
ReadDials(), and AcknowledgeCall().<span> 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.<span>
Have the program work for any number of phone numbers.<span>
Continue processing until the user enters a Q.
<span style="font-size:11pt; font-family:"Arial","sans-serif" <span>
<span style="font-size:11pt; font-family:"Arial","sans-serif" In the ToDigits() function use the toupper <span>
function to convert any letters entered to uppercase.<span>
All error messages are to be written to the output file from main() based on the return value from the functions.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-size:11pt; font-family:"Arial","sans-serif" 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.
<span style="font-size:11pt; font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Sample Output from the Program:
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 213-2121
<span style="font-family:"Arial","sans-serif" Phone Number Dialed: 213-2121
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): asc-dfer
<span style="font-family:"Arial","sans-serif" Phone Number Dialed: 272-3337
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 555-resw
<span style="font-family:"Arial","sans-serif" ERROR - Phone number cannot begin with 555
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 098-8765
<span style="font-family:"Arial","sans-serif" ERROR - Phone number cannot begin with 0
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): 12345678
<span style="font-family:"Arial","sans-serif" ERROR - Hyphen is not in the correct position
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): @34-*uyt
<span style="font-family:"Arial","sans-serif" ERROR - An invalid character was entered
<span style="font-family:"Arial","sans-serif"
<span style="font-family:"Arial","sans-serif" Enter a phone number (Q to quit): Q
<span style="font-family:"Arial","sans-serif" Press any key to continue . . .
<span style="font-family:"Arial","sans-serif"
</td>
</tr>
<tr>
<td width="673" valign="top" style="width:504.9pt; background:none repeat scroll 0% 0% #b7e4ff; padding:0in 5.4pt
<span style="font-family:"Arial","sans-serif" Step 2: <span style="font-family:"Arial","sans-serif" Processing Logic
</td>
</tr>
<tr style="height:30.1pt
<td width="673" valign="top" style="width:504.9pt; padding:0in 5.4pt; height:30.1pt
<span style="font-family:"Arial","sans-serif" Using the pseudo code below, write the code that will meet the requirements:
<span style="font-size:11pt; font-family:"Arial","sans-serif" Main Function<br/>
Declare the char variables for the 8 digits of the phone number
<span style="font-size:11pt; font-family:"Arial","sans-serif" while true<br/>
Call the ReadDials function passing the 8 digits<br/>
by reference. ReadDials returns an error code by<br/>
value.
<span style="font-size:11pt; font-family:"Arial","sans-serif" If the return value is -5, exit the do while loop
<span style="font-size:11pt; font-family:"Arial","sans-serif" If the error code is -1, display the<br/>
<span> error message "ERROR - An invalid character was entered".<br/>
If the error code is -2, display the<br/>
<span> error message "ERROR - Phone number cannot begin with 0".<br/>
If the error code is -3, display the<br/>
<span> error message "ERROR - Phone number cannot begin with 555".<br/>
If the error code is -4, display the<br/>
<span> error message "ERROR - Hyphen is not in the correct position".<br/>
Otherwise, call the AcknowledgeCall function
<span style="font-size:11pt; font-family:"Arial","sans-serif" <br/>
<span> End-While
<span style="font-size:11pt; font-family:"Arial","sans-serif" ReadDials function
<span style="font-size:11pt; font-family:"Arial","sans-serif" Input the first digit<br/>
If a Q was entered, return -5.<br/>
Input the rest of the phone number
<span style="font-size:11pt; font-family:"Arial","sans-serif" Call the ToDigit function for each of the 7 digits<br/>
<span> not for digit 4<br/>
If ToDigit returns -1, return -1<br/>
If digit 4 is not a hyphen, return -4.<br/>
If digit 1 is 0, return -2.<br/>
If digits 1 - 3 are 5, return -3<br/>
Otherwise, return 0
<span style="font-size:11pt; font-family:"Arial","sans-serif" ToDigit function<br/>
Convert the digit to upper case<br/>
Use a switch statement to determine if the digit is valid<br/>
<span> and convert the letters to digits
<span style="font-size:11pt; font-family:"Arial","sans-serif" If the digit is invalid, return -1.<br/>
If the digit is valid, return 0.
<span style="font-size:11pt; font-family:"Arial","sans-serif" AcknowledgeCall function<br/>
<span> Display the Phone Number.
</td>
</tr>
</tbody>
</table>
This is what I have so far :
# include <iostream><br/>
<br/>
# include <string><br/>
<br/>
# include <cctype><br/>
<br/>
# include <iomanip><br/>
<br/>
using namespace std;<br/>
<br/>
// prototypes<br/>
<br/>
int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5,char &d6, char &d7, char &d8);<br/>
<br/>
char Todigit(char &d);<br/>
<br/>
void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);<br/>
<br/>
<br/>
<br/>
// function main<br/>
<br/>
int main()<br/>
<br/>
{<br/>
<br/>
char d1, d2, d3, d4, d5, d6, d7, d8;<br/>
<br/>
int returnValue = 0;<br/>
<br/>
while (returnValue != -5)<br/>
<br/>
{<br/>
<br/>
returnValue = ReadDial (d1, d2, d3, d4, d5, d6, d7, d8);<br/>
<br/>
switch (returnValue)<br/>
<br/>
{<br/>
<br/>
case -1: cout << "Error- An invalid character was entered" << endl; break;<br/>
<br/>
case -2: cout << "Error- Phone number cannot begin with 0" << endl; break;<br/>
<br/>
case -3: cout << "Error- Phone number cannot begin with 555" << endl; break;<br/>
<br/>
case -4: cout << "Error- Hyphen is not in the correct position" << endl; break;<br/>
<br/>
default: AcknowledgeCall (d1, d2, d3, d4, d5, d6, d7, d8);<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
return 0;<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
// function ReadDial<br/>
<br/>
int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)<br/>
<br/>
{<br/>
<br/>
int returnValue;<br/>
<br/>
cout << "Enter a phone number (Q to quit): ";<br/>
<br/>
cin >> d1;<br/>
<br/>
if(d1 == Q) return -5;<br/>
<br/>
cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;<br/>
<br/>
returnValue = Todigit(d1);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d2);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d3);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
if (d4 != -)<br/>
<br/>
return -4;<br/>
<br/>
returnValue = Todigit(d5);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d6);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d7);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
returnValue = Todigit(d8);<br/>
<br/>
if (returnValue == -1)<br/>
<br/>
return returnValue;<br/>
<br/>
if (d1 == 0)<br/>
<br/>
return -2;<br/>
<br/>
if (d1 == 5 && d2 == 5 && d3 == 5)<br/>
<br/>
return -3;<br/>
<br/>
return 0;<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
//function ToDigit<br/>
<br/>
<br/>
<br/>
char Todigit(char &d)<br/>
<br/>
{<br/>
<br/>
d = toupper(d);<br/>
<br/>
switch(d)<br/>
<br/>
{<br/>
<br/>
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: break;<br/>
<br/>
case A: case B: case C: d = 2; break;<br/>
<br/>
case D: case E: case F: d = 3; break;<br/>
<br/>
case G: case H: case I: d = 4; break;<br/>
<br/>
case J: case K: case L: d = 5; break;<br/>
<br/>
case M: case N: case O: d = 6; break;<br/>
<br/>
case P: case Q: case R: case S: d = 7; break;<br/>
<br/>
case T: case U: case V: d = 8; break;<br/>
<br/>
case W: case X: case Y: case Z: d = 9; break;<br/>
<br/>
default: return -1;<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
// function AcknowledgeCall<br/>
<br/>
void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)<br/>
<br/>
{<br/>
<br/>
<br/>
<br/>
<br/>
cout << "Phone Number Dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl << endl;<br/>
<br/>
}
I dont know what else to do and it is do today. Thanks
View the full article