1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//prototypes
int readials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);
int todigit (char &d);
void acknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
int main()
{
char d1, d2, d3, d4, d5, d6, d7, d8;
int return_value = 0;
do
{
return_value = readials(d1, d2, d3, d4, d5, d6, d7, d8);
if(return_value == -5) break;
switch(return_value)
{
case -1: cout << "ERROR - An invalid character was entered"; break;
case -2: cout << "ERROR - Phone number cannot begin with 0"; break;
case -3: cout << "ERROR - Phone number cannont begin with 555"; break;
case -4: cout << "Error - Hyphen is not int the correct postion"; break;
default: acknowledgeCall(d1,d2,d3,d4,d5,d6,d7,d8);
}
}
while (true);
return 0;
}
int readials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)
{
int return_value;
cout << "Input the first digit";
cin >> d1;
if (d1 == 'Q' || d1 == 'q')
return -5;
cout << "Please continue";
cin >> d2, d3, d4, d5, d6, d7, d8;
return_value = todigit(d1);
if (return_value != -1)
return return_value;
return_value = todigit(d2);
if (return_value != -1)
return return_value;
return_value = todigit(d3);
if (return_value != -1)
return return_value;
return_value = todigit(d4);
if (return_value != '-')
return -4;
return_value = todigit(d5);
if (return_value != -1)
return return_value;
return_value = todigit(d7);
if (return_value != -1)
return return_value;
return_value = todigit(d8);
if (return_value != -1)
return return_value;
if (d1 == '0')
return -2;
if (d1 == '5' && d2 == '5' && d3 == '5')
return -3;
return 0;
}
int todigit(char &d)
{
d = toupper(d);
switch(d)
{
case '0': break;
case '1': break;
case '2': break;
case '3': break;
case '4': break;
case '5': break;
case '6': break;
case '7': break;
case '8': break;
case '9': break;
case 'A': case 'B': case 'C':
d = '2'; break;
case 'D': case 'F': case 'E':
d = '3'; break;
case 'H': case 'I': case 'G':
d = '4'; break;
case 'K': case 'L': case 'J':
d = '5'; break;
case 'N': case 'O': case 'M':
d = '6'; break;
case 'Q': case 'R': case 'P': 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;
}
return 0;
}
void acknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)
{
cout << " The number that you dialed was" << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl;
}
|