Page 1 of 1

C++ The International Standard Book Number (ISBN) is a unique, numerical commercial book identifier. The ISBN is 13 digi

Posted: Thu Jul 14, 2022 2:17 pm
by answerhappygod
C++
The International Standard Book Number (ISBN) is a unique,numerical commercial book identifier. The ISBN is 13 digits long ifassigned after January 1, 2007. The last digit of thethirteen-digit ISBN is called check digit, which is used to verifyif an ISBN is a valid ISBN.
The following describes the way to calculate the check digit.The calculation of an ISBN-13 check digit begins with the first 12digits of the 13-digit ISBN (thus excluding the check digititself):
For example, the ISBN-13 check digit of 978-0-306-40615-? iscalculated as follows:
s=9*1+7*3+8*1+0*3+3*1+0*3+6*1+4*3+0*1+6*3+1*1+5*3 =9 +21+8+0+3+0+6+12+0 +18+ 1 +15
= 93
93 mod 10 = 3 10 - 3 = 7
Thus, the check digit is 7, and the complete sequence is ISBN978-0-306-40615-7. Therefore, given a thirteen-digit ISBN, we cancalculate the check digit using the above approach and compare itwith the last digit in the given ISBN to decide if it is valid ornot.
Write a program that reads one ISBN number from screen andchecks if it is a valid ISBN number. Assume that there is no space,dash or other symbols within an ISBN number.
You are required to declare and define thefollowing two value returning functions:
This function returns (explicitly) thetheoretic check digit.
The isbn.dat file
978026202649997803214807989780596514552978059651455697805965292609781596510510
Here is the skeleton program you may copy/paste to getstarted.
#include <iostream> #include <string> #include <fstream> #include <cassert> using namespace std;
// Function Prototypes//Provide function prototypes for CheckDigit and IsValidISBN
int main( ) { string isbn; //ISBN number to be processed bool isValid; //indicates if the isbn is valid ifstream myIn;
myIn.open("isbn.dat"); assert(myIn);
while ( myIn >> isbn) //read a ISBN number fromdata file { // Add statement that makes a call to the functionIsValidISBN to find out the value of variable isValid. if ( isValid ) cout << isbn << " is a valid ISBNnumber" << endl; else cout << isbn << " is not a validISBN number" << endl; }
myIn.close(); return 0; }
// Define the IsValidISBN function here. The IsValidISBNfunction will call function "CheckDigit" to compute the checkdigit
// Define the IsValidISBN function here. The IsValidISBNfunction will call function "CheckDigit" to compute the checkdigit
// Define CheckDigit function here.
Here is an example output of the program: