// Functions.h #ifndef FUNCTIONS_H #define FUNCTIONS_H # include using namespace std; void WriteHeader(); int GetDigit(int number); int SumOfOddPlace(string cardNumber); bool StartsWith(string cardNumber, string substr); bool IsValid(string cardNumber); int SumOfDoubleEvenPlace(string cardNumber); bool ValidateInput(string cardNumber); #endif //end of Functions.h // Functions.cpp #include "Functions.h" #include // Course header void WriteHeader() { cout<<"CREDIT CARD NUMBER VALIDATION"<-1;i=i-2) { int n=cardNumber[i] - '0'; // convert ith character to int sum = sum + GetDigit(2*n); } return sum; } // return the sum of odd place digit in the card number from right to left int SumOfOddPlace(string cardNumber) { int sum =0; // loop from last digit to start in steps of -2 for(int i=cardNumber.length()-1;i>-1;i=i-2) { int n = cardNumber[i] - '0'; // convert ith character to int sum = sum + n; } return sum; } // returns true if the card number was entered with a valid format bool ValidateInput(string cardNumber) { // if length is incorrect if(cardNumber.length()< 13 || cardNumber.length() > 16) return false; else { // loop to check that each character is a digit for(size_t i=0;i '9') return false; } return IsValid(cardNumber); // return the result of IsValid } } // function to check if the card number is valid bool IsValid(string cardNumber) { int sum=0; // if prefix is incorrect if(!StartsWith(cardNumber,"4") && !StartsWith(cardNumber, "5") && !StartsWith(cardNumber, "37") && !StartsWith(cardNumber, "6")) return false; // calculate sum of double of even places sum = SumOfDoubleEvenPlace(cardNumber); // calculate sum of odd places sum += SumOfOddPlace(cardNumber); if(sum%10 == 0) // total sum is divisible by 10, valid card number return true; else // invalid card number return false; } //end of Functions.cpp // Driver.cpp : C++ program to validate credit card numbers # include #include "Functions.h" using namespace std; int main() { string cardNumber ; char choice; WriteHeader(); // loop that continues till the user wants do{ // input the card number cout<<"Enter a credit card number(without any space or special character):"<>cardNumber; // display if the card number is valid or not if(ValidateInput(cardNumber)) cout<>choice; }while(choice == 'y' || choice == 'Y'); cout<<"Good-bye"<