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
|
//--------------------------------------------------------------------------------
//Programming Assignment: LAB4
//Developer: Sierra McGivney
//Date Written: 03/26/2014
//Purpose: Simulates dialing of a phone number.
//--------------------------------------------------------------------------------
#include <iostream>
#include <cctype>
#include <iomanip>
#include <string>
using namespace std;
//Declarations: Functions
int readDials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8); //Function variables
int toDigits(char &d2, char &d3, char &d5, char &d6, char &d7, char &d8); //Function variables
int ackCall(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8); //Function variables
char d1, d2, d3, d4, d5, d6, d7, d8;
char d;
//Main Program
int main()
{
//Declarations
char d = ' ';
int rtrnValue = 0;
//Loop Begins
while (rtrnValue != -5)
{
char d1 = ' ', d2 = ' ', d3 = ' ', d4 = ' ', d5 = ' ', d6 = ' ', d7 = ' ', d8 = ' ';
readDials(d1, d2, d3, d4, d5, d6, d7, d8);
//Switch scenarios: Return Values
switch (rtrnValue)
{
case -1: cout << "Error: Invalid character entered." << endl; return -5;
case -2: cout << "Error: The number cannot start with a 1 or 0." << endl; return -5;
case -3: cout << "Error: The number cannot begin with 555." << endl; return -5;
case -4: cout << "Error: The fourth digit MUST be a hyphen (-)." << endl; return -5;
default: ackCall(d1, d2, d3, d4, d5, d6, d7, d8);
}
}
}
//Functions:
int readDials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)
{
cout << "Enter an eight digit phone number with the fourth digit being a hyphen (Press Q to quit): ";
cin >> d1;
int rtrnValue = 0;
//Switch scenarios: Quit
switch (d1)
{
case 'q': rtrnValue = -5; return rtrnValue;
case 'Q': rtrnValue = -5; return rtrnValue;
case '1': case '0': rtrnValue = -2;
default: rtrnValue = 0;
}
cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
toDigits(d2, d3, d5, d6, d7, d8); //call function: toDigits
if (d4 == 0x2d)
{
rtrnValue = -1;
}
if ((d1 == 5) && (d2 == 5) && (d3 == 5))
{
rtrnValue = -3;
}
//Switch Scenarios: Errors
switch (rtrnValue)
{
case -1: return rtrnValue;
case -2: return rtrnValue;
case -3: return rtrnValue;
case -4: return rtrnValue;
}
}
int toDigits(char &d2, char &d3, char &d5, char &d6, char &d7, char &d8)
{
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;
case '0': case '1':case '2': case '3': case '4': case '5': case '6': case '7': case '8': break;
default: return -1;
}
}
int ackCall(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8) //acknowledge call
{
cout << "You have dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl;
return -5;
}
|