Question
Book ISBN Processing In this assignment, you have to use C++ loops, functions, arrays, vectors. Write a program that prompts the user to enter the
Book ISBN Processing
In this assignment, you have to use C++ loops, functions, arrays, vectors.
Write a program that prompts the user to enter the first 9 digits of an ISBN code and displays the complete 10- digit ISBN code including all 0.
The book ISBN code
The International Standard Book Number (ISBN) is a unique numeric commercial book identifier based upon the 9-digit Standard Book Numbering (SBN) code created by Gordon Foster, Emeritus Professor of Statistics at Trinity College, Dublin for the booksellers and stationers W. H. Smith and others in 1965.
A 10-digit ISBN book number consists of 10 digits
D0D1D2D3D4D5D6D7D8D9
The last digit D9 is a checksum which is calculated from the first 9 digits using the formula:
D9 = (D0 x 1 + D1 x 2 + D2 x 3 + D3 x 4 + D4 x 5 + D5 x 6 +
D6 x 7 + D7 x 8 + D8 x 9) modulus 11
If the checksum is 10, the last character D9 is set to the letter X because we can not store 10 as a single digit. The modulus operation is the remainder operation.
Requirements:
Test your code and compare with the posted results.
Do the following:
1- Create a new C++ project
2- Define a C++ function prototype to validate the user input EXACTLY as below:
bool validateInput(char isbn[ ]) ;
The parameter isbn is a null-terminated character array (C string).
Function does not display anything.
This function returns true if the input is valid and returns false if it is not valid. Things that need to be checked in this order:
- Input length must be exactly 9
- Each character must be a digit
If the first check fails, there is no need to check the second one.
This function is called from main()
3- Define a C++ function prototype to calculate the checksum EXACTLY as followed.
char getCheckSum(char isbn[ ]) ;
This function must contain a loop to go through each digit of the ISBN code. The function must return a character result ('0' through '9', or an 'X'). This function must be able to return an 'X' if necessary.
The parameter isbn is a null-terminated character array (C string) with length 9.
This function is called from main(). Function does not display anything.
Create function prototypes and put them at the top of the program before main() as mentioned in the slides of chapter 6. Put all complete function definition code AFTER main().
4- Note that if a character c contains the character 5, then the ASCII code of it is 53. If you use c directly in calculation, the value 53 is used, not value 5. See http://www.asciitable.com/. To get the digit value 5 from character '5', calculate the difference of character c from character '0'.
5- Here is a simple main() function that you can use to test a single ISBN input:
int main()
{
const int SIZE = 30;
char isbn[SIZE];
cout
"This program calculates the checksum of a 9-digit ISBN code and display the 10-digit ISBN."
cout
cin.getline(isbn, SIZE);
bool isValid = validateInput(isbn);
if (!isValid) {
cout
} else {
char checksum = getCheckSum(isbn);
string isbn9Str(isbn); // convert char array to string
cout
cout
}
}
6- After your code works correctly with one single input, do the following:
- Change the main() code to add a Sentinel loop to accept and process multiple user inputs in a single run. To stop the user input loop, user will hit Return with no input. When users enter an invalid ISBN code, the program should also continue loop to let user enter another one and do not stop.
- Write an additional function with prototype EXACTLY as below:
string formatWithHyphen(string isbnStr, char checkSum);
It takes the 9-digit ISBN string with a checksum code and returns an ISBN string with checksum of length 13 with 3 embedded - after the first digit, after the fourth digit and the ninth digit position. For example, this function will take 2 parameters containing 030640615 and checksum 2 and returns a string 0-306-40615-2
This function returns a string and does NOT display any output. You can see the following statement in main() that calls this function to display the ISBN code with the extra hyphens in addition to the original 10-digit ISBN.
cout
Hint: There is no need to use any loop for this function. C++ string has the insert() function that is very convenient.
7- Add two C++ vectors:
- one vector of string type to store the valid input ISBN string (9-character string) and
- one vector of char type to store the calculated checksum characters.
In the loop of main(), add the valid 9-digit ISBN string to first vecto and the checksum character to second vector. When user hits the Enter key to exit the program, use a loop to display a summary report containing all valid input ISBN codes with their corresponding calculated checksums from these 2 vectors.
Sample output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started