Difference between revisions of "2014 Old Spec"
(Created page with "=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...") |
(→Figure 5) |
||
Line 8: | Line 8: | ||
==Figure 5== | ==Figure 5== | ||
− | |||
− | |||
FOR Count 1 TO 13 DO <br> | FOR Count 1 TO 13 DO <br> | ||
OUTPUT "Please enter next digit of ISBN: "<br> | OUTPUT "Please enter next digit of ISBN: "<br> | ||
Line 33: | Line 31: | ||
ELSE OUTPUT "Invalid ISBN"<br> | ELSE OUTPUT "Invalid ISBN"<br> | ||
ENDIF<br> | ENDIF<br> | ||
− | |||
− | |||
==Table 3== | ==Table 3== |
Revision as of 23:05, 28 November 2016
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
- 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.