tutorial02.pptx - CSCI 1120 Introduction to Computing Using...

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI 1120 Introduction to Computing Using C++ Tutorial 2 LI, Le SHB 1013 [email protected] 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Outline Assignment 1 Brief introduction Hints & submission Formatting output 2
Image of page 2
Assignment 1: Check Digit Computation 3 Deadline of Assignment 1 20:00, 27 Sep 2016 (Tue)
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Check Digit Computation Every credit card number contains a check digit at its rig htmost, which is used for simple error detection. It can b e used to protect against accidental errors such as a mis typed digit or the permutation of two successive digits. In this assignment, you will write a program that compute s the check digit of a partial credit card number.
Image of page 4
5 Check Digit Computation Luhn Algorithm: Double the odd-positioned digits ? 1 , ? 3 , ? 5 , ? 7 , ? 9 , ? 11 , ? 13 , and ? 15 . If a doubled digit is greater than 9, replace it by its s um of digits . (E.g., 16 is replaced by 1 + 6 = 7.) Sum the even-positioned digits ? 2 , ? 4 , ? 6 , ? 8 , ? 10 , ? 12 , and ? 14 with the modifed odd-positioned digits ? 1 , ? 3 , ? 5 , ? 7 , ? 9 , ? 11 , ? 13 , and ? 15 . Multiply the sum by 9 . Then the units digit ( 個位數 , the rightmost digit) of the multiplication is the che ck digit ? 16 . http://en.wikipedia.org/wiki/Luhn_algorithm
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
7 6 3 5 4 5 8 4 1 9 2 7 5 0 6 6 Example—763545841927506 Double Odd Digits If > 9, sum digits 14_6_8_16_2_4_10_12 5_6_8_7_2_4_1_3 Sum digits x9 72 64 8 Therefore, the full card number is: 763545841927506 8 .
Image of page 6
Program Specifcation The user input is always either a 15-digit number o r a negative integer. If the input is a 15-digit number: compute the check digit with Luhn Algorithm display the full card number as four pieces of 4-digit seg ments in the format XXXX-XXXX-XXXX-XXXX. If the input is a negative integer: program terminates. 7
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Program Specifcation Use long long type to declare the variable: int ( [-2147483648 2147483647] )is not long enough to store a 16-digits number. Array is not allowed! The output should be the 100% same with sampl e output (both results and formats ). 8
Image of page 8
Sample Output Program output should be exactly the same as the sample program (i. e., same text, same symbols, same letter case, same number of spaces , etc.). 9
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Real-time Demonstration 10
Image of page 10
Program hints How to implement and mod in the C++? For , just let z = (int)(x), and if x, y are all integers, to cal culate z=,z = x / y can work. E.g. 19/10=1. For mod, use operator %. E.g. 19%10=9. How to extract each digits of a 15-digit partial card number?
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern