1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
satela [25.4K]
3 years ago
12

python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. T

he last digit, d10, is a checksum, which is calculated from the other nine digits using the following formula: (d1 * 1 d2 * 2 d3 * 3 d4 * 4 d5 * 5 d6 * 6 d7 * 7 d8 * 8 d9 * 9) % 11 If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write a program that prompts the user to enter the first 9 digits and displays the 10-digit ISBN (including leading zeros). Sample Run 1 Enter the first 9 digits of an ISBN as a string: 3601267 Incorrect input. It must have exact 9 digits Sample Run 2 Enter the first 9 digits of an ISBN as a string: 013601267 The ISBN-10 number is 0136012671 Sample Run 3 Enter the first 9 digits of an ISBN as a string: 013031997 The ISBN-10 number is 013031997X
Computers and Technology
1 answer:
iogann1982 [59]3 years ago
5 0

Answer:

<em>The programming language is not stated;</em>

<em>However, I'll answer this question using C++ programming language</em>

<em>The program uses few comments; See explanation section for more detail</em>

<em>Also, the program assumes that all input will always be an integer</em>

#include<iostream>

#include<sstream>

#include<string>

using namespace std;

int main()

{

string input;

cout<<"Enter the first 9 digits of an ISBN as a string: ";

cin>>input;

//Check length

if(input.length() != 9)

{

 cout<<"Invalid input\nLength must be exact 9";

}

else

{

 int num = 0;

//Calculate sum of products

for(int i=0;i<9;i++)

{

 num += (input[i]-'0') * (i+1);    

}

//Determine checksum

if(num%11==10)

{

 input += "X";

 cout<<"The ISBN-10 number is "<<input;

}

else

{

 ostringstream ss;

 ss<<num%11;

 string dig = ss.str();

 cout<<"The ISBN-10 number is "<<input+dig;

}

}  

 return 0;

}

Explanation:

string input;  -> This line declares user input as string

cout<<"Enter the first 9 digits of an ISBN as a string: ";  -> This line prompts the user for input

cin>>input;  -> The user input is stored here

if(input.length() != 9)  { cout<<"Invalid input\nLength must be exact 9";  }  -> Here, the length of input string is checked; If it's not equal to then, a message will be displayed to the screen

If otherwise, the following code segment is executed

else  {

int num = 0; -> The sum of products  of individual digit is initialized to 0

The sum of products  of individual digit is calculated as follows

for(int i=0;i<9;i++)

{

num += (input[i]-'0') * (i+1);

}

The next lines of code checks if the remainder of the above calculations divided by 11 is 10;

If Yes, X is added as a suffix to the user input

Otherwise, the remainder number is added as a suffix to the user input

if(num%11==10)  {  input += "X";  cout<<"The ISBN-10 number is "<<input; }

else

{

ostringstream ss;

ss<<num%11;

string dig = ss.str();

cout<<"The ISBN-10 number is "<<input+dig;

}

}  

You might be interested in
In computer science how can you define "copyright, designs and patents act 1988"?​
Natali5045456 [20]

Answer:

:)

Explanation:

Copyright Designs and Patents Act

The Copyright Designs and Patents Act (1988) gives creators of digital media the rights to control how their work is used and distributed. ...

Anything which you design or code is automatically copyrighted and may not be copied without your permission, as the digital creator.

5 0
2 years ago
To specify your preferred colors, fonts, and effects for a document, which of the following should be done?
Irina-Kira [14]

Answer: crest custom theme

Explanation:

8 0
2 years ago
Read 2 more answers
What doe the &amp; operator do in python programming software
ArbitrLikvidat [17]
Hardware software is the answer
5 0
3 years ago
P2p networks are most commonly used in home networks. <br> a. True <br> b. False
postnew [5]
<span>The statement that P2P networks are most commonly used in home networks is true. 
</span>P2P stands for peer-to-peer communication network. It is an example of local administration. <span> Two or more PCs share files and access to devices such as printers without requiring a separate server computer or server software with P2P type of network.</span>
6 0
3 years ago
How a student can use computer to improve academic performance?
nikdorinn [45]

Answer:

k Nishant

Explanation:

he can learn many things internet by using computer he change his self by learning about many things

3 0
3 years ago
Read 2 more answers
Other questions:
  • 3. Discuss the disadvantages of file-based systems.
    13·1 answer
  • Which statement is true? Group of answer choices Variables cannot be assigned and declared in the same statement Variable names
    5·1 answer
  • A car with a 20-gallon gas tank averages 23.5 miles per gallon when driven in town and 28.9 miles per gallon when driven on the
    9·1 answer
  • Write a Python program to do the following:
    12·1 answer
  • How is a recession determined?
    10·1 answer
  • 2.2-2 Consider sorting numbers stored in array by first finding the smallest element n A of and exchanging it with the element i
    11·1 answer
  • In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectang
    14·1 answer
  • 2) What are two reasons we analyze algorithms?
    7·2 answers
  • Choose the true statement below. (html)
    5·1 answer
  • Which example illustrates the idea of "collecting data"?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!