2014 Old Spec

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

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 
OUTPUT "Please enter next digit of ISBN: "
INPUT ISBN[Count]
ENDFOR
CalculatedDigit = 0
Count = 1
WHILE Count < 13 DO
CalculatedDigit = CalculatedDigit + ISBN[Count]
Count = Count + 1
CalculatedDigit = CalculatedDigit + ISBN[Count] * 3
Count = Count + 1
ENDWHILE
WHILE CalculatedDigit >= 10 DO
CalculatedDigit = CalculatedDigit – 10
ENDWHILE
CalculatedDigit = 10 – CalculatedDigit
IF CalculatedDigit = 10
THEN CalculatedDigit = 0
ENDIF
IF CalculatedDigit = ISBN[13]
THEN OUTPUT "Valid ISBN"
ELSE OUTPUT "Invalid ISBN"
ENDIF

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

  1. Write a program for the algorithm in Figure 5.
  2. 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).
  3. 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).
  4. Save the program in your new Question4 folder/directory.