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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
#ifndef H_creditCardType
#define H_creditCardType
#include<iostream>
#include<string>
using namespace std;
class creditCardType
{
public:
creditCardType(); //Constructor
creditCardType(string name, string cardNum, cardType, cardExp); //Constructor with parameters
void setName(const string name); //Function to set the customer's name
string getName() const; //Function to return customer's name
void setCardNum(const string cardNum); //Function to set the credit card numer
string getCardNum() const; //Function to return credit card number
void setCardType(const string cardType); //Function to set the credit card type
string getCardType() const; //Function to return credit card type
void setCardExp(const string cardExp); //Function to set the credit card expiration date
string getCardExp() const; //Function to return credit card expiration date
bool operator==(const creditCardType&) const; //Overload the operator ==
const creditCardType& operator=(const creditCardType&); //Overload the operator =
creditCardType cardInfo(); //Returns name, credit card number, card type, and card expiration
private:
string fullName; //Variable to store customer's first and last name
string cCardNum; //Variable to store credit card number
string cCardType; //Variable to store credit card type
string cCardExp; //Variable to store credit card expiration
};
creditCardType::creditCardType()
{
setName("");
setCardNum(0000000000000000);
setCardType("");
setCardExp(0000);
}
creditCardType::creditCardType(string name, string cardNum, cardType, cardExp)
{
setName(name);
setCardNum(cardNum);
setCardType(cardType);
setCardExp(cardExp);
}
void creditCardType::setName(const string name)
{
name = fullName;
}
string creditCardType::getName()
{
return fullName;
}
void creditCardType::setCardNum(const string cardNum)
{
cardNum = cCardNum;
}
string creditCardType::getCardNum()
{
return cCardNum;
}
void creditCardType::setCardType(const string cardType)
{
if(cardType = 1)
cardType = "Visa";
else if(cardType = 2)
cardType = "MasterCard";
else if(cardType = 3)
cardType = "Discover";
else(cardType = 4)
cardType = "American Express";
cardType = cCardType;
}
string creditCardType::getCardType()
{
return cCardType;
}
void creditCardType::setCardExp(const string cardExp)
{
cardExp = cCardExp;
}
string creditCardType::getCardExp()
{
return cCardExp;
}
creditCardType::cardInfo()
{
string infoName; //Variable to hold full name
string infoNum; //Variable to hold credit card number
string infoType; //Variable to hold credit card type
string infoExp; //Variable to hold credit card expiration date
creditCardType info; //Object
bool finished = false; //Used for while loop until full name information is successful
bool finished1 = false; //Used for while loop until credit card number information is successful
bool finished2 = false; //Used for while loop untnil credit card type information is successful
bool finished3 = false; //Used for while loop until credit card expiration date is successful
string error = "Invalid format. Please re-enter your name."; //Input error for full name
string error1 = "Invalid card number length. Please re-enter your card number."; //Input error for credit card number
string error2 = "Invalid card type. Please re-enter your card type."; //Input error for credit card type
string error3 = "Invalid expiration date. Please re-enter the expiration date on your card."; //Input error for credit card expiration date
cout << "We will now need your credit card information." << endl << endl;
//Prompts for the full name and checks validation
do
{
try
{
cout << "Please enter your full name: ";
cin.getline(infoName, '\n');
if (infoName.find_first_of("0123456789") != string npos);
throw error;
finished = true;
info.setName(infoName);
}
catch(string error)
{
cout << error << endl;
cin.clear();
}
}
while(!finished)
//Prompts for the credit card number and checks validation
do
{
try
{
cout << "Please enter your 16-digit credit card number: ";
cin >> infoNum;
if (infoNum.length() > 16 || infoNum.length() < 16)
throw error1;
finished1 = true;
info.setCardNum(infoNum);
}
catch(string error1);
{
cout << error1 << endl;
cin.clear();
}
}
while (!finished1);
//Prompts for the credit card type and checks validation
do
{
try
{
cout << "Please enter your credit card type(1, 2, 3, or 4)." << endl;
cout << "We only accept (1)Visa, (2)MasterCard, (3)Discover, and (4)American Express: ";
cin >> infoCard
if (infoCard != 1 || 2 || 3 || 4)
throw error2;
finished2 = true;
info.setCardType(infoCard);
}
catch(string error2)
{
cout << error2 << endl;
cin.clear();
}
}
while(!finished2)
//Prompts for the credit card expiration date and checks validation
do
{
try
{
cout << "Please enter the expiration date on your credit card (format 0216 = Feb 2016): ";
cin >> infoExp;
if (infoExp.length() > 4 || infoExp.length() < 4 || infoExp <= 0514)
throw error3;
finished3 = true;
info.setCardExp(infoExp)
}
catch(string error3)
{
cout << error3 << endl;
cin.clear();
}
}
while(!finished3)
creditCardType infoGathered(info.getName(), info.getCardNum(), info.getCardType, info.getCardExp());
return infoGathered;
}
#endif H_creditCardType
|