Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a c++ program using the steps mentioned below:- Some credit card companies use Luhn algorithm to detect invalid credit card numbers. The

Make a c++ program using the steps mentioned below:-

 

 

Some credit card companies use Luhn algorithm to detect invalid credit card numbers.
The key thing in this algorithm is to find a check digit, which should be the rightmost
digit in any credit card number.
In this task, you have to implement a version of Luhn algorithm using the instructions
given below.
Step1: Read in credit card number as a series of digits into an array
Ask the user to enter series of one digit positive numbers into a one dimensional array,
the number -1 is used to indicate the end of series, no need to read in -1 into the array.
The maximum size of the array is set to 20.
Step2: Find sum1 (main should call a function passing array and size)
Ignoring the last check digit (right most digit) of the credit card number, and moving
left, double the value of every second digit and find the sum of these doubled numbers.
If the result of the doubling operation is a two digit number, you should add the digits of
the doubled number before finding the sum. You must printout the numbers for sum1,
these should be in the order (from left to right) as it appears on credit card.
Step 3: find sum2 (main should call a function passing array and size)
Find the sum of all other numbers (last digit is not included in this sum as well). You
must printout the numbers for sum2, these should be in the order (from left to right) as it
appears on credit card.
Step 4: Calculate check sum
Compute the total of sum1 and sum2 and multiply the result by 9, checksum is found
by extracting the rightmost digit.

Program should display if the credit is valid or not valid at the end.


image

The output should be like this:-

So if the credit card number is 5424180123456789 then for calculating sum 1 it should take numbers like 5 2 1 0 leaving the middle number and for sum 2 it should be like this 4 4 8 1 leaving the middle numbers and if the check sum and the last digit is same then the credit card is valid otherwise invalid and all the steps are mentioned above for how to find sum1, sum2, checksum...

 

image

4 4+4-8 Image courtesy: https://www.nab.com.au/business/business-cards/nab-rewards- business-signature-card 3 3 3 4335 8712 3456 7890 VALID 11/19 UNTIL 10/23 SMALL BUSINESS FROM END MS N REWARDS NAB REWARDS BUSINESS 3+3=6 80x9 = 720 6 8 6 8+8-16 1+6=7 7 1 7 1+1=2 2 3 2 VISA Signature 3+3=6 4 5 4 O is the check sum digit. 5+5=10 1+0=1 6 6 7 7+7-14 1+4=5 8 9 8 9+9-18 1+8=9 0 sum1-8+6+7+2+6+1+5+9 = 44 sum2= 3+6+7+2+4+6+8 - 36 Total=44+36 - 80

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The program is cpp include iostream include vector Function to find sum1 Step 2 int findSum1const stdvector int cardNumber int size int sum1 0 for int ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Algorithms questions