Đang Thực Hiện

165068 C Programming

in C not C++

You are to write a C program that validates International Standard Book

Numbers (ISBNs).

Details

International Standard Book Numbers

ISBNs were introduced by publishing houses in the early 1970s to simplify computer

processing of orders, inventories, etc. Each ISBN has ten digits. The first nine identify the

publisher and the book, while the tenth is used to ensure that the number has been entered

correctly, and is called a check digit. A similar technique is followed for many other

important numbers, such as student numbers and bank account numbers.

Formats

The ISBN has ten digits. These are normally broken into smaller groups with hyphens or

spaces to make it easier to transcribe them. The break-up varies, because the publisher

definition can be done in several ways, depending on the size of the publisher.

Some examples of ISBN's are:

0-7897-0414-5

0-262-68053-X

0 201 54322 2

Notes:

1) There is no guarantee that there will always be four numeric groups, so you should

consider that the number of characters may be any value of ten or greater.

2) The check digit sometimes must have a value of 10, and this is indicated by putting an X

in the check-digit location.

Calculation

To check an ISBN, each digit is multiplied by a weight, the products are summed, and the

sum must be a multiple of 11. The weights and an example calculation using the first ISBN

above are shown in the following table.

Digit 0 7 8 9 7 0 4 1 4 5

Weight 10 9 8 7 6 5 4 3 2 1

Product 0 63 64 63 42 0 16 3 8 5

The sum is 264, which is 24 * 11, so the remainder is zero and the ISBN is correct.

It is not hard to show that this method will detect any single-digit error, or any transposition

of two adjacent digits. These are the most common data-entry errors. About 90% of more

complex errors will be detected, but not all: for instance, if one is added to both the fifth and

sixth digits, the effect is to add 11 to the sum of products, so this error would not be detected.

Obtaining Input

The user should be able to type the ISBN in the format shown on the book she is checking,

with dashes or spaces. The possible presence of spaces in the input means that scanf may

not process the input correctly. Instead, you should use the function fgets, which accepts a

whole line of input, including its newline character.

To use fgets, you should code as follows (replace fields in italics with your actual values):

fgets(array name, max_input_size, stdin);

An example of its use would be

char array[20];

fgets(array, 20, stdin);

For this project we will ignore fgets' return value, and signal end-of-input by entering

a line that is empty.

As part of this project, you may not use an array with fgets that is greater than 20 chars

in size. If the user enters more than 20 characters on the keyboard then the program must

clear any unread characters and then wait for a new ISBN to be entered.

Processing Digits

Your program will accept a line of input containing an ISBN with dashes or spaces, identify

the digits, and perform the above calculation. Note that the digits in the input string will be

characters, with their associated ASCII value. To convert a single digit character to its

corresponding internal integer value for calculation purposes, simply subtract the character

code for '0'. E.g.

char c = ‘9';

int num = c – ‘0';

Will put the value 9 into num.

Program Action

Your program should do the following:

1) Accept a line of text from standard input.

2) Check that the line has a valid ISBN format. If not the program should print an error

message and go to step 4). If the line entered is a null line then the program stops.

3) Otherwise, it should check the ISBN, print out a statement indicating whether it is correct

or not, then wait for the next ISBN.

4) Wait for the next ISBN to be entered.

Kỹ năng: Bất kì công việc gì, Lập trình C

Xem thêm: write programming code, used to write a book on, up programming, transcribe 6, the c programming, string programming, string processing in c, string in c programming, string c programming, step by step computer programming, standard programming, s programming, scanf c programming, programming technique, programming statement, programming process, programming number, programming method, programming keyboard, programming in go book, programming function, programming errors, programming error, programming definition, programming book

Về Bên Thuê:
( 42 nhận xét )

Mã Dự Án: #1911259

Đã trao cho:

ashekthegreateu

Dont worry, I did ACM programming for 4 years in C. Accept me, I will deliver it within 30 mins. Thanx.

$35 USD trong 0 ngày
(0 Đánh Giá)
0.0