Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4) (25 marks) Your task in this question is to write a C program named F.c according to the specifications below. You will submit the

4) (25 marks) Your task in this question is to write a C program named F.c according to the specifications below. You will submit the program using SVN in the pathname CSID/a5/F.c where CSID is your CSID and the name of your main SVN directory for the course. You will also need to submit the program as a part of the Practicum 3. The Practicum 3 link will be made available at the course web site.

Problem description: The program will check something calle Luhns checksum. It is a checksum invented and patented by Hans Peter Luhn, a researcher at IBM, in 1954. It is a basic integrity check that can usually detect accidental errors in numbers such as credit cards, or identification numbers. For example, most credit card and bank card numbers use this checksum, and many national identification numbers, including Canadian SIN numbers use it.

The checksum works as follows: If a sequence of decimal digits is given, let us say dkdk1 . . . d2d1, if we index digits from right to left, then we calculate the Luhns checksum as follows:

1. Starting at the right we transform each second digit d2, d4, etc., by multiplying it by 2. If this product is a two-number, i.e., if it is greater than 9, then we add those two digits and replace the results with this sum.

2. We add all digits of the number, the odd-positioned digits, and the transformed even-positioned digits. If the result is divisible by 10, the number passes the checksum test, otherwise not.

We can consider an example: 1234567890123411

After transformations in the step 1, we get digits: 2264165890226421 and when we add them up, we get 60, so the number passes the test.

Your program needs to test a sequence of such numbers.

Input: The first line of input contains a single integer T (1 T 100), the number of test cases. Each of the following T lines contains a single test case consisting of a number given as a string of base-10 digits (09). The length of each string is between 2 and 50, inclusive, and numbers may have leading (leftmost) zeros.

Output: For each test case, output a single line containing PASS if the number passes the Luhn checksum test, or FAIL if the number fails the Luhn checksum test.

For example, for sample input:

3 00554

3

999 1234567890123411 

the output should be:

PASS FAIL PASS 

a) [15 marks] Functionality: To satisfy this requirement, your program must satisfy the program requirements as specified and pass the practicum testing.

b) [10 marks] Implementation: To receive these marks, the program must be implemented in the following way, and it will be marked by a marker. Since you know that the test numbers are not longer than 50 digits, you should read them as strings of up to 50 digits. This can be done using scanf("%50s", specification and a character array of appropriate length.

Since the digits read in this way are ASCII digits, you will copy them to an int array in which each digit is transformed to it actual value. For example, this can be done with expression ch - 0 where ch is the char value of the digit. The array of integers created in this way, should be passed to a function with prototype: int luhn_checksum(int len, int a[]); where len is length of array a of digits that needs to be checked. If the checksum passes, the function should return 1, otherwise it should return 0.

You are required to write a head comment that includes your name, date of the program, the course and assignment number, and a short description of the program. The program should follow the organization presented in the class.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions