answer.
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]
2 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]2 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
John downloaded the manual for his TV, called manual-of-tv.pdf, from the manufacturer's website. After he clicked twice on the d
wariber [46]

Jhon must download third party pdf viewer softwares to open the .pdf file.

For example

Adobe Acrobat Reader

Must click thanks and mark brainliest

4 0
1 year ago
A cyber criminal sends a series of maliciously formatted packets to the database server. The server cannot parse the packets and
telo118 [61]

Answer:

DoS attack

Explanation:

A Denial of Service attack involves the sending of maliciously formatted data packets to a server. The packet can be larger than the allowed IP size such that when it arrives at the server, the server cannot identify the headers in the data packet for it to process and extract data. The server can either freeze or crash, denying allowed users access to its resources and making it unavailable.

7 0
1 year ago
CodeHS Python Rainforest Exercise 5.4.7: Categories
nalin [4]

Answer:

List=[['Computers','IT','Programming'],['Maths', 'Algebra', 'Geometry']]

i=0

k=0

for i in range(0,2):

   print("Category:"+List[i][0])

   for k in range(1,3):

       print("\t"+List[i][k])

   

Explanation:

The required program is as above. We have used here a multidimensional list. The 0 of each row has the category,and rest are sub categories. The program above has limitations but is good enough to explain the fundamentals required.

7 0
1 year ago
Given the security levels TOP SECRET, SECRET, CONFIDENTIAL, and UNCLASSIFIED (ordered from highest to lowest), and the categorie
inessss [21]

Answer:

1 – Paul will be able to READ the document classified (SECRET, {B,C}) (No read up, no write down!)

2 – Anna will not be able to access the document since she is not in the category-set

3 – Jesse will be able to READ the document classified (CONFIDENTIAL, {C}) (No read up, no write down!)

4 – Sammi will be able to READ the document classified (confidential, {A}) (No read up, no write down!)

5 – Robin will be able to WRITE do this document, but not read it (No read up, no write down!)

Explanation:

1 – Paul will be able to READ the document classified (SECRET, {B,C}) (No read up, no write down!)

2 – Anna will not be able to access the document since she is not in the category-set

3 – Jesse will be able to READ the document classified (CONFIDENTIAL, {C}) (No read up, no write down!)

4 – Sammi will be able to READ the document classified (confidential, {A}) (No read up, no write down!)

5 – Robin will be able to WRITE do this document, but not read it (No read up, no write down!)

8 0
2 years ago
For the (pseudo) assembly code below, replace X, Y, P, and Q with the smallest set of instructions to save/restore values on the
Dimas [21]

Answer:

Explanation:

Let us first consider the procedure procA; the caller in the example given.

  Some results: $s0,$s1,$s2, $t0,$t1 and $t2 are being stored by procA. Out of these registers, few registers are accessing by procA after a call to procB. But, procB might over-write these registers.

       Thus, procA need to save some registers into stack first before calling procB, .

      only $s1,$t0 and $t1 are being used after return from procB in the given example,

       Caller saves and restores only values in $t0-$t9, according to MIPS guidelines for caller-saved and callee-saved registers, .

       Thus, procA needs to save only $t0 and $t1.

    jal instruction overwrites the register $ra by writing the address, to which the control should jump back, after completing the instructions of procB, when procB is called,.

       Therefore, procA also need to save $ra into stack.

 ProcA is writing new values into $a0,$a2, procA must save $a0 and $a1 first before calling procB, .

     In the given example, after return from procB, only $a0 is being used. It is therefore enough to save $a0.

   Also, procA needs to save frame pointer, which points the start of the stack space for each procedure.

       Generally, as soon as the procedure begins, frame pointer is set to the current value of the stack pointer,.

Let us consider the procedure procB; the callee in the given example.

 The callee is responsible for saving values in $s0-$s7 and restoring them before returning to caller, this is according to MIPS guidelines for caller-saved and callee-saved registers,

   procB is expected to over-write the registers $s2 and $t0. Nonetheless, in the first two lines, procB might over-write the registers $s0 and $s1.

   Thus, procB is responsible for saving and restoring $s0,$s1 and $s2.

X:

We need to create space for 5 values on the stack since procA needs to save $a0,$ra,$t0,$t1 and $fp(frame pointer), . Each value(word) takes 4 bytes.

$sp = $sp – 20 # on the stack, create space for 5 values

sw $a0, 16($sp) # store the result in $a0 into the memory address

               # indicated by $sp+20

sw $ra, 12($sp) # save the second value on stack

sw $t0, 8($sp) # save the third value on stack

sw $t1, 4($sp) # save the fourth value on stack

sw $fp, 0($sp) #  To the stack pointer, save the frame pointer

$fp = $sp      #  To the stack pointer, set the frame pointer

Y:

lw $fp, 0($sp) #  from stack, start restoring values

lw $t1, 4($sp)

lw $t0, 8($sp)

lw $ra, 12($sp)

lw $a0, 16($sp)

$sp = $sp + 20 # decrease the size of the stack

P:

$sp = $sp – 12 #  for three values, create space on the stack

sw $s0, 0($sp) # save the value in $s0

sw $s1, 0($sp) # save the value in $s1

sw $s2, 0($sp) # save the value in $s2

Q:

lw $s0, 0($sp) #  from the stack, restore the value of $s0

lw $s1, 0($sp) #  from the stack, restore the value of $s1

lw $s2, 0($sp) #  from the stack, restore the value of $s2

$sp = $sp + 12 # decrease the stack size

8 0
1 year ago
Other questions:
  • Theresa is a certified teacher. She just had a baby and would like to stay home, but still wants to teach. Which career would be
    11·2 answers
  • Manny is a personal trainer. He gives his client an endurance test each week. He would like to illustrate how much the client ha
    7·2 answers
  • Write a fragment of code that reads in strings from standard input, until end-of-file and prints to standard output the largest
    10·1 answer
  • A common fallacy is to use MIPS (millions of instructions per second) to compare the performance of two different processors, an
    15·1 answer
  • The attack in which the attacker sends a forged packet with the same source IP address and destination IP address in which the v
    10·1 answer
  • When this program is compiled and executed on an x86-64 Linux system, it prints the string 0x48\n and terminates normally, even
    14·1 answer
  • You are modeling a small part of an online flight reservation system, according to the following description. A flight is a sing
    11·1 answer
  • (Displaying a Sentence with Its Words Reversed) Write an application that inputs a line of text, tokenizes the line with String
    6·1 answer
  • 1. What should you do if your computer is shared by your entire family and you install a plugin that saves user names and passwo
    5·2 answers
  • The height of a small rocket y can be calculated as a function of time after blastoff with the following piecewise function: y 5
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!