Chapter 13: Data Types and Structures: Answers To Coursebook Questions and Tasks
Chapter 13: Data Types and Structures: Answers To Coursebook Questions and Tasks
Task 13.01
Identifier Explanation Data type
BiggestSoFar Stores the biggest number input so far INTEGER/REAL
NextNumber The next number to be input INTEGER/REAL
Stores how many numbers have been
Counter INTEGER
input so far
Task 13.02
1 TYPE BookType
Title : STRING
YearOfPublication : INTEGER
Price : REAL
ISBN : STRING
ENDTYPE
2 DECLARE Book : BookType
Book.YearOfPublication 2015
Book.Price 15.99
Book.ISBN "9781107546738"
Task 13.04
MaxIndex 19
INPUT SearchValue
Found FALSE
Index −1
REPEAT
Index Index + 1
IF Name[Index] = SearchValue
THEN
Found TRUE
ENDIF
UNTIL FOUND = TRUE OR Index >= MaxIndex
IF Found = TRUE
THEN
OUTPUT "Age:", Age[Index]
ELSE
OUTPUT "Name not found"
ENDIF
Task 13.05
n MaxIndex – 1
REPEAT
NoMoreSwaps TRUE
FOR j 0 TO n
IF MyList[j] < MyList[j + 1]
THEN
Temp MyList[j]
Task 13.06
1 DECLARE Board : ARRAY[1..3, 1..3] OF CHAR
3 Board[1, 1] 'A'
4 Board[2, 2] 'B'
Task 13.07
1 DECLARE BookArray : ARRAY[1..200] OF BookType
Book[1].YearOfPublication 2015
Book[1].Price 15.99
Book[1].ISBN "9781107546738"
Task 13.08
1 OPENFILE "GameData.txt" FOR WRITE
FOR Row 1 TO 3
FOR Column 1 TO 3
WRITEFILE "GameData.txt", Board[Row, Column]
NEXT Column
NEXT Row
CLOSEFILE "GameData.txt"
Task 13.09
1
Task 13.10
1
Exam-style Questions
1
Variable Example value Data type
ColourCode “034AB45” STRING
ProductionDate 2018/03/31 DATE
Weight 67.45 REAL
NumberInStock 98 INTEGER
SizeCode ‘X’ CHAR
Completed FALSE BOOLEAN
Marking guidance:
1 mark for each 2 correct entries in the data type column
2
Marking guidance:
1 mark for each correct column
Marking guidance:
1 mark for each 2 correct data types
1 mark for correct identifier PasswordList
1 mark for each correct cell completed in Explanation column
b MaxIndex ← 20
INPUT MyUserID
INPUT MyPassword
UserIdFound ← FALSE
LoginOK ← FALSE
Index ← −1
REPEAT
Index ← Index + 1
IF UserList[Index] = MyUserID
THEN
UserIdFound ← TRUE
ENDIF
UNTIL UserIdFound = TRUE OR Index = MaxIndex
IF UserIdFound = TRUE
THEN
IF PasswordList[Index] = MyPassword
THEN
LoginOK ← TRUE
ENDIF
ENDIF
IF LoginOK = TRUE
THEN
Marking guidance:
1 mark for each correctly completed gap (shown by dotted lines)
c i TYPE UserRecord
UserID : STRING
Password : STRING
ENDTYPE
Marking guidance:
1 mark for correct TYPE statement structure
1 mark for 2 fields correctly declared
ii DECLARE User : ARRAY[0..20] OF UserRecord
Marking guidance:
1 mark for correct array declaration structure (i.e. DECLARE User : ARRAY[0..20])
1 mark for correct giving data type (i.e. OF UserRecord)