ISBN Validator Every book is identified by a ten-character International Standard Book Number (ISBN), which is usually printed on the back cover of the book. The first nine characters are digits and the last character is either a digit or the letter X (which stands for ten). Three examples of ISBNs are 0-13-030657-6, 0-32-108599-X, and 0-471-58719-2. The hyphens separate the characters into four blocks. The first block usually consists of a single digit and identifies the language (0 for English, 2 for French, 3 for German, etc.). The second block identifies the publisher (for example, 13 for Prentice Hall, 32 for Addison- Wesley-Longman, and 471 for Wiley). The third block is the number the publisher has chosen for the book. The fourth block, which always consists of a single character called the check digit, is used to test for errors. Let’s refer to the ten characters of the ISBN as d1, d2, d3, d4, d5, d6, d7, d8, d9, and d10. The check digit is chosen so that the sum
10⋅d1 + 9⋅d2 + 8⋅d3 + 7⋅d4 + 6⋅d5 + 5⋅d6 + 4⋅d7 + 3⋅d8 + 2⋅d9 + 1⋅d10 + (*) is a multiple of 11. (Note: A number is a multiple of 11 if it is exactly divisible by 11.) If the last character of the ISBN is an X, then in the sum (*), d10 is replaced with 10. For example, with the ISBN 0-32-108599-X, the sum would be
10 ⋅ 0 + 9 ⋅ 3 + 8 ⋅ 2 + 7 ⋅ 1 + 6 ⋅ 0 + 5 ⋅ 8 + 4 ⋅ 5 + 3 ⋅ 9 + 2 ⋅ 9 + 1 ⋅ 10 = 165
Since 165/11 is 15, the sum is a multiple of 11. This checking scheme will detect every single-digit and transposition-of-adjacent-digits error. That is, if while copying an IBSN number you miscopy a single character or transpose two adjacent characters, then the sum (*) will no longer be a multiple of 11.
Write a program to accept an ISBN type number (including the hyphens) as input, calculate the sum (*), and tell if it is a valid ISBN. See Fig. 7.71. (Hint: The number n is divisible by 11 if n Mod 11 is 0.) Before calculating the sum, the program should check that each of the first nine characters is a digit and that the last character is either a digit or an X.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.