0% found this document useful (0 votes)
74 views8 pages

Chapter 13: Data Types and Structures: Answers To Coursebook Questions and Tasks

Uploaded by

Indu Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views8 pages

Chapter 13: Data Types and Structures: Answers To Coursebook Questions and Tasks

Uploaded by

Indu Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter 13: Data types and structures:

Answers to coursebook questions


and tasks
Syllabus sections covered: 10
It is suggested that Chapters 12 and 13 are worked through in parallel with Chapter 14.

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

Identifier Explanation Data type


SecretNumber The number to be guessed INTEGER
NumberOfGuesses The number of guesses the player has made INTEGER
Guess The number the player has input as a guess INTEGER

Identifier Explanation Data type


RunningTotal Stores the sum of the numbers input so far INTEGER/REAL
Counter How many numbers have been input INTEGER
NextNumber The next number input INTEGER/REAL
Average The average of the numbers input REAL

Identifier Explanation Data type


NumberOfRows Stores the number of rows of the grid INTEGER
NumberOfColumns Stores the number of columns of the grid INTEGER
Symbol Stores the chosen character symbol CHAR
RowCounter Counts the number of rows INTEGER
ColumnCounter Counts the number of columns INTEGER

© Cambridge University Press 2019


Identifier Explanation Data type
Symbol The character symbol to form the pyramid CHAR
MaxNumberOfSymbols The number of symbols in the final row INTEGER
NumberOfSpaces The number of spaces to be output in the INTEGER
current row
NumberOfSymbols The number of symbols to be output in the INTEGER
current row

Task 13.02
1 TYPE BookType

Title : STRING

YearOfPublication : INTEGER

Price : REAL

ISBN : STRING

ENDTYPE
2 DECLARE Book : BookType

Book.Title  "Computer Science"

Book.YearOfPublication  2015

Book.Price  15.99

Book.ISBN  "9781107546738"

© Cambridge University Press 2019


Task 13.03
Arrays with friends’ names and ages similar to:

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]

© Cambridge University Press 2019


MyList[j] MyList[j + 1]
MyList[j + 1] Temp
NoMoreSwaps  FALSE
ENDIF
NEXT j
n  n – 1
UNTIL NoMoreSwaps = TRUE

Task 13.06
1 DECLARE Board : ARRAY[1..3, 1..3] OF CHAR

2 CONSTANT Space = ' '


DECLARE Row, Column : INTEGER
FOR Row  1 TO 3
FOR Column  1 TO 3
Board[Row, Column]  Space
NEXT Column
NEXT Row

3 Board[1, 1]  'A'

4 Board[2, 2]  'B'

Task 13.07
1 DECLARE BookArray : ARRAY[1..200] OF BookType

2 Book[1].Title  "Computer Science"

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"

2 OPENFILE "GameData.txt" FOR READ


FOR Row  1 TO 3

© Cambridge University Press 2019


FOR Column  1 TO 3
READFILE "GameData.txt", Board[Row, Column]
NEXT Column
NEXT Row
CLOSEFILE "GameData.txt"

Task 13.09
1

Task 13.10
1

© Cambridge University Press 2019


Task 13.11

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

© Cambridge University Press 2019


3 a
Identifier Data type Explanation

UserList ARRAY[0...20] OF STRING 1D array to store user IDs

PasswordList ARRAY[0...20] OF STRING 1D array to store passwords

MaxIndex INTEGER Number of elements in each array

MyUserID STRING User ID entered to login

MyPassword STRING Password entered to login

UserIdFound BOOLEAN FALSE if user ID not found in


UserList
TRUE if ID found in Userlist

LoginOK BOOLEAN FALSE if user ID not found, or


passwords don’t match
TRUE if password correctly
entered for existing user ID

Index INTEGER Pointer to current array element

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

© Cambridge University Press 2019


OUTPUT "Login successful"
ELSE
OUTPUT "User ID and/or password incorrect"
ENDIF

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)

© Cambridge University Press 2019

You might also like