Question
Using c++

A ten diglt ISBN number uses a checksum as its last diglt to verlfy the first nine digits are valid. Before 2007, all ISBN numbers were composed like this, such as: e-20-5e8005-7 or 1-234-56789-X The first nine digits are assigned by a books publisher and the last digit is calculated by weighted sum (described below). The X stands for the checksum value of 10, in order to represent ten as a single digit. You must write a program that calculates and outputs this checksum value given the first nine digits of the ISBN number, utilizing the checksum algorithm below ecksum Algorlthm To compute the weighted sum we start from the left-most digit: Sum one times the first digit, plus two times the second digit, plus three times the third, etc. all the way to nine times the ninth digit. Note: Just becouse we describe the calculation as starting with the left-most digit does NOT an that that is the best order for the C+ algorithml Plan carefully for the simplest way of lating each digit from the whole number. Next we take this weighted sum, and calculate the remainder after it is divided by eleven. (i.e. weighted sum modulo eleven) Finally, the ISBN standard requires that we take this checksum digit and convert it if needed (i.e. 10 is replaced by X). We will omit this step and just output the value from 0 through 10 without any conversion. Your main function must prompt the user to enter the first 9 digits of an ISBN, and then read in that input as a single integer Your program must then calculate the corresponding checksum, and output it as shown in the example run below. Test Values (Single program execution per row) SBN (first 9-digits) 123456789 868880008 987654321 847147063 Checksum Value 16 Examples (1.1 + 2.2 + 3.3 + 4.4 + 5*5+ 6*6 + 7.7 + 8*8 + 9.9)%11-10 (1*0+ 2.0 + 3.0 + 4*0+ 5.0 + 6.0 + 7.0 + 8.0 + 9.0)%11-10 (1.9 + 2*8 + 3.7 + 4*6 + s*5+ 6.4 + 7.3 + 8.2 + 9.1)%11-0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The solution to the above question is given below with screenshot of output.

=====================================================

I kept the logic simple and i have tested all outputs.

If there is anything else do let me know in comments.

=====================================================

============ CODE TO COPY ===============================

#include<iostream>
using namespace std;

// Checking if number is valid of not
bool is_valid( long int isbn_no ){

  // if number if greater than 9 digits or negative it's invalid
  if ( isbn_no > 999999999 || isbn_no < 0  )
    return false;

  // number if ok
  return true;
}

int calculate_check( long int isbn_no ){

  int sum = 0;
  int digits = 0;

  long int temp = isbn_no;

  // count the number of digits in number
  while ( temp != 0 && ++digits )
    temp = temp/10;

  // multiply all number as per the given algo
  for ( int i = 9 ; i >= 10 - digits; i-- ){

      int rem  = isbn_no % 10;
      isbn_no = isbn_no / 10;
      sum += rem*i;
  }

  // return sum modulo 11 
  return sum % 11;
}

int main() {

  long int isbn_no = 0 ;
  int     checksum = 0 ;

  cout << "Please Enter First 9 Digits Of ISBN Number : ";
  cin  >> isbn_no;

  if ( is_valid( isbn_no ) == false )
  {
    cout << "Invalid Isbn number " << endl;
    return 0;
  }

  // here we are caclulating checksum
  checksum = calculate_check( isbn_no );
 
  cout << "Checksum is : " << checksum << endl;

  return 0;

}

=====================================================

Output

gcc version 4.6.3 Please Enter First 9 Digits of ISBN Number 123456789 Checksum is10

Add a comment
Know the answer?
Add Answer to:
Using c++ A ten diglt ISBN number uses a checksum as its last diglt to verlfy...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Introduction: Ten digit ISBN numbers are created so that the first nine digits are information digits...

    Introduction: Ten digit ISBN numbers are created so that the first nine digits are information digits and the last digit is a check digit. T his last number helps people notice and correct mistakes that might be made in recording the information digits. The same is true for thirteen digit ISBN numbers. Here is a ten digit ISBN number: 0-13-149498-8. The digit 0 indicates the book is written for English-speaking people. The number 13 and the number 149498 identify the...

  • Description: An ISBN-10 (International Standard Book Number) consists of 10 digits: didzdzdad5d6d7d8d9d1o. The last digit, dio,...

    Description: An ISBN-10 (International Standard Book Number) consists of 10 digits: didzdzdad5d6d7d8d9d1o. The last digit, dio, is a checksum, which is calculated from the other nine digits using the following formula: (d, x 1 + d2 x 2 +d3 x 3 + da x4 + ds x 5 + de x 6 + d7 x 7+ d3 x 8+dex 9) % 11 If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write...

  • Write a C++ program that will read in an ISBN-10 ID, and determines whether the tenth...

    Write a C++ program that will read in an ISBN-10 ID, and determines whether the tenth digit is the valid checksum of the first nine digits. The program reads in purported ID, and finishes execution once it has printed out what it's read in, plus either VALID or INVALID. Cannot use getline function. a) Processing stops after ten digits, even if there are more digits on the line of input. The

  • Write a program in Python that asks the user for the ISBN of the book in...

    Write a program in Python that asks the user for the ISBN of the book in the format xxx-x-xxx-xxxxx-x. To validate: Initialize a total to 0 Have the program remove the dashes so that only the 13 digits are left in the ISBN string for each index of the first 12 digits in the 13 digit ISBN string get the digit at the current index as an integer If the current index is an even number, add the digit to...

  • In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • IN PYTHON ''' Helper func 3: checksum_ISBN Input: a list with 9 single digit number in...

    IN PYTHON ''' Helper func 3: checksum_ISBN Input: a list with 9 single digit number in it (first 9 digit in ISBN) Output: print out: "The correct checksum digit is:__. Now we have a legit ISBN: _____" Hint: just loop through 0-9, test every one with helper func1 to find out the one checksum that forms a legit ISBN with the correct ISBN in lis (10 numbers), call helper func2 to format it correctly. Then print the final result. '''...

  • Please tell me whether my answers are correct or not. If not please tell me why...

    Please tell me whether my answers are correct or not. If not please tell me why and give me a guide to solving the problem correctly. Thanks! 3 Check Digits: ISBN In this problem, we'll look at a real-world applications of check-digits International Standard Book Numbers (ISBNS) are 10-digit codes (did2...dio) which are assigned by the publisher. These 10 digits contain information about the language, the publisher, and the number assigned to the book by the publisher. Additionally, the last...

  • Program Instructions: Write a C++ program that uses a random number generator to generate a two...

    Program Instructions: Write a C++ program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: Double the number. Reverse the digits of the number. Raise the number to the power of 2, 3, or 4. Sum the digits of the number. If the number is a two digit number, then raise the first digit to the power of the second digit. If the...

  • c++ pleased Assignment 6a (15 points] - Character and String related processing... Listed below are two...

    c++ pleased Assignment 6a (15 points] - Character and String related processing... Listed below are two interesting programming challenges that will require a bit of character and/or string related processing with functions. (Carefully read the specifications for each programming challenge and select ONE.) (1) Sum of Digits in a String Write a program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT