2014 Old Spec
Question 4
Create a folder/directory Question4 for your new program. The algorithm, represented using pseudo-code in Figure 5, and the variable table, Table 3, describe the process of using a check digit to check if a value entered by the user is a valid 13 digit International Standard Book Number (ISBN).
Figure 5
FOR Count 1 TO 13 DO <br> OUTPUT "Please enter next digit of ISBN: "<br> INPUT ISBN[Count]<br> ENDFOR<br> CalculatedDigit = 0<br> Count = 1<br> WHILE Count < 13 DO<br> CalculatedDigit = CalculatedDigit + ISBN[Count]<br> Count = Count + 1<br> CalculatedDigit = CalculatedDigit + ISBN[Count] * 3<br> Count = Count + 1<br> ENDWHILE<br> WHILE CalculatedDigit >= 10 DO<br> CalculatedDigit = CalculatedDigit – 10<br> ENDWHILE<br> CalculatedDigit = 10 – CalculatedDigit<br> IF CalculatedDigit = 10<br> THEN CalculatedDigit = 0<br> ENDIF<br> IF CalculatedDigit = ISBN[13]<br> THEN OUTPUT "Valid ISBN"<br> ELSE OUTPUT "Invalid ISBN"<br> ENDIF<br>
Table 3
Identifier | Data Type | Purpose |
---|---|---|
ISBN | Array[1..13] Of Integer | Stores the 13 digit ISBN entered by the user – one digit is stored in each element of the array. |
Count | Integer | Used to select a specific digit in the ISBN. |
CalculatedDigit | Integer | Used to store the digit calculated from the first 12 digits of the ISBN. It is also used to store the intermediate results of the calculation. |
What you need to do
- Write a program for the algorithm in Figure 5.
- Test the program by showing the result of entering the digits 9, 7, 8, 0, 0,
9, 9, 4, 1, 0, 6, 7, 6 (in that order).
- Test the program by showing the result of entering the digits 9, 7, 8, 1, 8,
5, 7, 0, 2, 8, 8, 9, 4 (in that order).
- Save the program in your new Question4 folder/directory.