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
|
// ---------------------------------------------------------------
// Programming Assignment: LAB04
// Developer: Jocko Davis
// Date Written: 04/02/2014
// Purpose: Phone Program
// ---------------------------------------------------------------
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
char readDial(char&, char&, char&, char&, char&, char&, char&, char&);
char toDigit(char, char, char, char, char, char, char, char);
void acknowledgeCall(int, int, int, int, int, int, int, int);
int main()
{
// Declare variables
string num;
char one, two, three, four, five, six, seven, eight;
char returnValue = 0;
while(returnValue != -5)
{
returnValue = readDial(one, two, three, four, five, six, seven, eight);
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;
case -5: cout << "Goob-bye" << endl; break;
default:
return acknowledgeCall(one, two, three, four, five, six, seven, eight);
}
}
return 0;
}
//ReadDials function
char readDial(char& one, char& two, char& three, char& four, char& five, char& six, char& seven, char& eight)
{
char Q = 0;
cout << "Enter 8 digit telephone number (***-****) or Q to quit: ";
cin >> one;
if(one == Q)
return -5;
cin >> two >> three >> four >> five >> six >> seven >> eight;
int result = toDigit(one, two, three, four, five, six, seven, eight);
if (result == -1)
return -1;
if (four != '-')
return -4;
if (one == 0)
return -2;
if (one, two, three == 5)
return -2;
return 0;
}
//ToDigit function
char toDigit(char& n)
{
toupper(n);
switch(n)
{
case 'A': case 'B': case 'C':
case 'a': case 'b': case 'c':
n = '2'; break;
case 'D': case 'E': case 'F':
case 'd': case 'e': case 'f':
n = '3'; break;
case 'G': case 'H': case 'I':
case 'g': case 'h': case 'i':
n = '4'; break;
case 'J': case 'K': case 'L':
case 'j': case 'k': case 'l':
n = '5'; break;
case 'M': case 'N': case 'O':
case 'm': case 'n': case 'o':
n = '6'; break;
case 'P': case 'Q': case 'R': case 'S':
case 'p': case 'q': case 'r': case 's':
n = '7'; break;
case 'T': case 'U': case 'V':
case 't': case 'u': case 'v':
n = '8'; break;
case 'W': case 'X': case 'Y': case 'Z':
case 'w': case 'x': case 'y': case 'z':
n = '9'; break;
default:
return -1;
break;
}
return 0;
}
//AcknowledgeCall function
void acknowledgeCall(char& one, char& two, char& three, char& four, char& five, char& six, char& seven, char& eight)
{
string phoneNumber ;
phoneNumber = toDigit(one, two, three, four, five, six, seven, eight);
cout << " Number Dialed: " << phoneNumber << endl;
}
|