2.3. Programming
A subsection of Computer Science, 9608, through 2. Fundamental Problem-solving and Programming Skills
Listing 5 of 5 questions
Consider the following user-defined data type: TYPE LibraryBookRecord DECLARE ISBN : INTEGER DECLARE Title : STRING ENDTYPE Write a pseudocode statement to declare a variable, Book, of type LibraryBookRecord. Write a pseudocode statement that assigns ‘Dune’ to the Title of Book. The user-defined data type LibraryBookRecord needs to be modified by adding the following fields: • a field called Genre which can take two values, fiction or non-fiction • a field called NumberOfLoans which can be an integer value in the range 1 to 99 Write the updated version of LibraryBookRecord. A pointer is a variable that stores the address of a variable of a particular type. Consider the code on page 3, which uses the following identifiers: Identifier Data type Description IntPointer ^INTEGER pointer to an integer IntVar INTEGER an integer variable Temp1 INTEGER an integer variable Temp2 INTEGER an integer variable IntVar // assigns the value 57 to the integer // variable IntVar IntPointer @IntVar // assigns to IntPointer the address of the // integer variable IntVar Temp2 IntPointer^ // assigns to variable Temp2 the value at an // address pointed at by IntPointer IntPointer^ Temp1 // assigns the value in the variable Temp1 to // the memory location pointed at by IntPointer The four assignment statements are executed. The diagram shows the memory contents after execution. Variable Memory address Contents . . . IntVar . . . IntPointer . . . Temp1 Temp2 . . . Use the diagram to state the current values of the following expressions: @Temp2 IntPointer IntPointer^ IntPointer^ = Temp2 + 6 Write pseudocode statements that will achieve the following: Assign the value 22 to the variable Temp2. Place the address of Temp1 in IntPointer. Copy the value in Temp2 into the memory location currently pointed at by IntPointer.
9608_s17_qp_31
THEORY
2017
Paper 3, Variant 1
Consider the following pseudocode user-defined data type: TYPE MyContactDetail DECLARE Name : STRING DECLARE HouseNumber : INTEGER ENDTYPE Write a pseudocode statement to declare a variable, NewFriend, of type MyContactDetail. Write a pseudocode statement that assigns 129 to the HouseNumber of NewFriend. The user-defined data type MyContactDetail needs to be modified by: • adding a field called Area which can take three values, uptown, downtown or midtown • amending the field HouseNumber so that house numbers can only be in the range 1 to 499. Write the updated version of MyContactDetail. A pointer is a variable that stores the address of a variable of a particular type. Consider the pseudocode on page 3, which uses the following identifiers: Identifier Data type Description IPointer ^INTEGER pointer to an integer Sum INTEGER an integer variable MyInt1 INTEGER an integer variable MyInt2 INTEGER an integer variable Sum // assigns the value 91 to the integer variable Sum IPointer @Sum // assigns to IPointer the address of the // integer variable Sum MyInt1 IPointer^ // assigns to variable MyInt1 the value at an // address pointed at by IPointer IPointer^ MyInt2 // assigns the value in the variable MyInt2 to // the memory location pointed at by IPointer The four assignment statements are executed. The diagram shows the memory contents after execution. Variable Memory Address Contents . . . IPointer . . . Sum . . . MyInt1 MyInt2 . . . Use the diagram to state the current values of the following expressions: IPointer IPointer^ @MyInt1 IPointer^ = MyInt2 Write pseudocode statements that will achieve the following: Place the address of MyInt2 in IPointer. Assign the value 33 to the variable MyInt1. Copy the value in MyInt2 into the memory location currently pointed at by IPointer.
9608_s17_qp_32
THEORY
2017
Paper 3, Variant 2
Consider the following user-defined data type: TYPE LibraryBookRecord DECLARE ISBN : INTEGER DECLARE Title : STRING ENDTYPE Write a pseudocode statement to declare a variable, Book, of type LibraryBookRecord. Write a pseudocode statement that assigns ‘Dune’ to the Title of Book. The user-defined data type LibraryBookRecord needs to be modified by adding the following fields: • a field called Genre which can take two values, fiction or non-fiction • a field called NumberOfLoans which can be an integer value in the range 1 to 99 Write the updated version of LibraryBookRecord. A pointer is a variable that stores the address of a variable of a particular type. Consider the code on page 3, which uses the following identifiers: Identifier Data type Description IntPointer ^INTEGER pointer to an integer IntVar INTEGER an integer variable Temp1 INTEGER an integer variable Temp2 INTEGER an integer variable IntVar // assigns the value 57 to the integer // variable IntVar IntPointer @IntVar // assigns to IntPointer the address of the // integer variable IntVar Temp2 IntPointer^ // assigns to variable Temp2 the value at an // address pointed at by IntPointer IntPointer^ Temp1 // assigns the value in the variable Temp1 to // the memory location pointed at by IntPointer The four assignment statements are executed. The diagram shows the memory contents after execution. Variable Memory address Contents . . . IntVar . . . IntPointer . . . Temp1 Temp2 . . . Use the diagram to state the current values of the following expressions: @Temp2 IntPointer IntPointer^ IntPointer^ = Temp2 + 6 Write pseudocode statements that will achieve the following: Assign the value 22 to the variable Temp2. Place the address of Temp1 in IntPointer. Copy the value in Temp2 into the memory location currently pointed at by IntPointer.
9608_s17_qp_33
THEORY
2017
Paper 3, Variant 3
Questions Discovered
5