Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pad 01:42 cs.iit.edu empty expression tails.) expr pri ary expr-all primary ( ex

ID: 3728870 • Letter: P

Question

Pad 01:42 cs.iit.edu empty expression tails.) expr pri ary expr-all primary ( expr ) | |d | const expr-tail op expr (** is for exponentiation) 8. [12 points] (Modified Problem 4.10, pp.211 - 212.) Use the grammar below and attach attributes to say whether a Credit Card Number is valid, the check sum for a sequence of Digits, and whether the leftmost digit of a sequence is in an even or odd position. Assume a digit has a value attribute. Use % as a modulus operator. Feel free to define a helper function to do a calculation (pseudocode is fine) Ds digit Ds -digit Ds CS 440: Programming Languages and Translators © James Sasaki, 2018

Explanation / Answer

Algorithm To Check Validity of Credit Card Number :-

Best algorithm for this is The Luhn Check Digit Algorithm . The Luhn algorithm is primarily used for the validation of credit card numbers. Not only does this provide a catcher for data-entry errors, it also doubles as a weak security tool. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from collections of random digits.

Step 1: Double the value of alternate digits of the primary account number beginning with the second digit from the right (the first right--hand digit is the check digit.)

      for example :-

Step 2: Add the individual digits comprising the products obtained in Step 1 to each of the unaffected digits in the original number.

       e.g- 4 +(1+8)+ 9 + (4) + 7 + (6) + 9 +(1+6) + 7 + (2) + 6

Step 3: The total obtained in Step 2 must be a number ending in zero (30, 40, 50, etc.) for the account number to be validated.

      e.g. Sum = 70 : Card number is validated , Card is valid because the 70/10 yields no remainder.

IMPORTANT TIPS :-