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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply