Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++ PLEASE ANSWER ALL PARTS OF THE QUESTION i answeed them but i cant run the code please help read to the end please write
c++ PLEASE ANSWER ALL PARTS OF THE QUESTION i answeed them but i cant run the code please help read to the end please write a code that i can run
a) Create an enumerated data type called CrdCard
The types of Credit Cards to create are American Express, Visa, MasterCard, Discover, ALL
The ALL just means could be any of the 4 specified.
b) Create a function that takes in the enumerated type and returns a valid credit card number using the
Luhn Algorithm. Note: Length, etc... are dependent on credit card type.
genCC(CrdCard,char []), or
char *genCC(CrdCard)
c) Create a function that randomly flips only 1 digit.
void flipDig(char []);
d) Create a function that determines if the result is a valid Credit Card
bool validCC(char[]);
e) Loop 10,000 times and record how many valid vs. invalid Credit Cards are detected
Note: You are going to have to test out your generate credit card function extensively. The length is not always fixed even for a given credit card.
Answers
A)Create an enumerated data type called CrdCard
enum CrdCards{
American_Express,
Visa,
MasterCard,
Discover,
ALL
}
B)Create a function that takes in the enumerated type and returns a valid credit card number
#include
#include
char *genCC(CrdCard)
{
char ccNo[16];
switch(crdcard){
case American_Express:
for(int x = 0; x < 16 ; x++) {
if(x == 0 || x == 1){ // American Express start with 34
ccNo[0] = '3';
ccNo[1] = '4'
x = 2;
continue;
}
ccNo[x] = rand()%10 + '0';
}
ccNo[16] = '\0';
break;
case Visa:
for(int x = 0; x < 16 ; x++) {
if(x == 0 ){ // Visa start with 4
ccNo[0] = '4';
x = 1;
continue;
}
ccNo[x] = rand()%10 + '0';
}
ccNo[16] = '\0';
break;
case MasterCard:
for(int x = 0; x < 16 ; x++) {
if(x == 0 ){ // Master card start with 51, 52, 53, 54, 55
int max = 5;
ccNo[0] = '5';
ccNo[1] = random(max)%10 + '0';
x = 2;
continue;
}
ccNo[x] = rand()%10 + '0';
}
ccNo[16] = '\0';
break;
case Discover:
for(int x = 0; x < 16 ; x++) {
if(x == 0 ){ // Discover start with 6
ccNo[0] = '6';
x = 1;
continue;
}
ccNo[x] = rand()%10 + '0';
}
ccNo[16] = '\0'
break;
case ALL:
for(int x = 0; x < 16 ; x++) {
ccNo[x] = rand()%10 + '0';
}
ccNo[16] = '\0'
break;
} // switch case ends
return ccNo;
} // end of function
C ) Create a function that randomly flips only 1 digit.
#include
void flipDig(char[] ccno){
int max = 16;
bitset<16> ccno(ccno);
ccno.flip(rand(max)); //rnadomly flip only one digit from ccno
}
D) Create a function that determines if the result is a valid Credit Card
bool validCC(char[] ccno){
bool result = false;
int len = ccno.size();
if(len >16) {
return result;;
}
if( (ccno[i]=='3' && ccno[i+1]=='4') ||
(ccno[i]=='4') ||
(ccno[i]=='5') ||
(ccno[i]=='6') )
result = true;
}
return result;
}
D) Loop 10,000 times and record how many valid vs. invalid Credit Cards are detected.
bool valid = false;
for(int i=0;i<10000;i++)
{
valid = validCC(ccno[i]);
if(valid) {
cout << ccno[i] << "is Valid Credit Card"<
}
else
{
cout << ccno[i] << "is not Valid Credit Card"<
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started