You are on page 1of 2

CSCI1510 Computer Principles and C Programming, Spring 2019

Department of Computer Science and Engineering, The Chinese University of Hong Kong

Assignment 2: ISSN
Due: 20:00, Wed 13 Feb 2019 Full marks: 100

Introduction
The objective of this assignment is to learn how to use variables, operators, expressions, and console
input/output. Name your source file name as issn.c.

The International Standard Serial Number (ISSN) is a number to uniquely identify a serial publication
like magazines, journals, comic books, etc. (ISSN is similar in concept to ISBN but the latter is
assigned to books instead.) ISSNs are 8-digit long, in which the rightmost digit is a check digit. It is
used for simple error detection, and to protect against accidental errors such as a mistyped digit or
the permutation of two successive digits. In this assignment, you will write a program to obtain a 7-
digit partial ISSN (without the check digit) and compute the corresponding check digit to complete
the ISSN.

Let an ISSN be in the format 𝑑1 𝑑2 𝑑3 𝑑4 𝑑5 𝑑6 𝑑7 𝑑8 , in which 𝑑1 … 𝑑7 is the 7-digit partial ISSN


obtained from the program user. The check digit 𝑑8 can be computed using the following method:

1. Compute the weighted sum 𝑆 = 8𝑑1 + 7𝑑2 + 6𝑑3 + 5𝑑4 + 4𝑑5 + 3𝑑6 + 2𝑑7 .
2. Find the remainder 𝑟 of 𝑆 when divided by 11, i.e., 𝑟 = 𝑆 mod 11.
3. Subtract the remainder 𝑟 from 11. The result is the check digit: 𝑑8 = 11 − 𝑟. However, if the
subtraction result is 11, then change 𝑑8 to 0. If the result is 10, then change 𝑑8 to X (Roman
numeral ten).

Example 1: partial ISSN is 0316406.

1. 𝑆 = 8 × 0 + 7 × 3 + 6 × 1 + 5 × 6 + 4 × 4 + 3 × 0 + 2 × 6 = 85
2. Remainder 𝑟 = 85 mod 11 = 8.
3. Finally, 𝑑8 = 11 − 𝑟 = 11 − 8 = 3. Thus the complete ISSN is 03164063.

Example 2: partial ISSN is 7534260.

1. 𝑆 = 8 × 7 + 7 × 5 + 6 × 3 + 5 × 4 + 4 × 2 + 3 × 6 + 2 × 0 = 155
2. Remainder 𝑟 = 155 mod 11 = 1.
3. Finally, 𝑑8 = 11 − 𝑟 = 11 − 1 = 10, and 10 has to be changed to X. Thus the complete ISSN is
7534260X.

Program Specification
The program should obtain a partial 7-digit ISSN as user input. You can assume that the user input is
always a 7-digit integer. (That is, you do not have to check whether the input is out of this
assumption.) Then apply the above method to compute the check digit of the input and display the
complete ISSN, which should be printed in two segments in the format NNNN-NNNN.

Copyright © 2019 CSE, CUHK Page 1 of 2


CSCI1510 Computer Principles and C Programming, Spring 2019
Department of Computer Science and Engineering, The Chinese University of Hong Kong

Sample Run
In the following sample runs, the blue text is user input and the other text is the program printout.
You can try the provided sample program for other input. Your program output should be exactly the
same as the sample program (same text, symbols, letter case, spacings, etc.). Note that there is a
space after the ‘:’ in the program printout.

Enter a 7-digit partial ISSN: 0316406↵


Complete ISSN is: 0316-4063

Enter a 7-digit partial ISSN: 7534260↵


Complete ISSN is: 7534-260X

Enter a 7-digit partial ISSN: 9927008↵


Complete ISSN is: 9927-0080

Submission and Marking


 Your program file name should be issn.c. Submit the file in Blackboard
(https://blackboard.cuhk.edu.hk/).
 Insert your name, student ID, and e-mail as comments at the beginning of your source file.
 You can submit your assignment multiple times. Only the latest submission counts.
 Your program should be free of compilation errors and warnings.
 Your program should include suitable comments as documentation.
 Do NOT plagiarize. Sending your work to others is subjected to the same penalty as the copier.

Copyright © 2019 CSE, CUHK Page 2 of 2

You might also like