# A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2012 Exam/Section C

## Validation

 Error Checking List the Erroneous, Extreme and Typical Data for a user selecting a menu item: Answer: Typical = 3 Extreme = 9,4 or 1 Erroneous = 7 List the Erroneous, Extreme and Typical Data for direction input: Answer: Typical = N,S,E or W Extreme = N,S,E or W Erroneous = I

## Variables

 Variables Give the name of the identifier of a Constant Answer: NoOfTraps, NSDistance, WEDistance State one advantage of using named constants for constant values Answer: Improves readability of code // Easier to update the programming code if the value changes ( A. by implication) // reduce the likelihood of errors; Give the name of the identifier of a global variable Answer: NoOfTraps, NSDistance, WEDistance Give the identifier of a local variable Answer: Choice Note the identifier of an array: Answer: Cavern, TrapPositions Give the identifier of a user defined data type: Answer: GameData, CellReference State the name of an identifier used for a pre-defined function with a single parameter Answer: ResetCavern(ByRef Cavern(,) As Char); State the name of an identifier used for a two-dimensional array; Answer: Cavern(NSDistance, WEDistance); State the name of an identifier used for a cariblae that is used to control the iteration of a loop Answer: Count; Count1; Count2; State the name of a user-defined procedure/function that has exactly 7 parameters, and name them. Answer: ```SetUpGame; ``` Cavern(,), TrapPositions(), MonsterPosition, PlayerPosition, FlaskPosition, MonsterAwake, NewGame Give an example of an assignment statement: Answer: Const NoOfTraps = 2 Choice = GetMainMenuChoice() Give an example of a variable declaration: Answer: Dim MonsterAwake As Boolean (Pascal) Choice : Integer; FlaskPosition : TCellReference; MonsterAwake : Boolean; MonsterPosition : TCellReference; PlayerPosition : TCellReference; TrapPositions : TTrapPositions; Why might we not want to store an average score as an integer? Answer: The answer may be a decimal

## Loops

 Loops Give the name of a stepper variable used in a loop? Answer: Count1, Count2, Count Give the name of a fixed variable used in a loop? Answer: NSDistance, WEDistance Give the name of a follower used in a loop? Answer: Give the name of a most recent holder used in a loop? Answer: Choice MAY be an answer here. FlaskPosition may be a recent holder(?). See 'MoveFlask()' sub-routine. I think it is because the program holds the flask ("F") in the 'FlaskPosition' cell reference until the 'NewCellForFlask' variable can hold "F" (after which FlaskPosition changes to " "): ``` Sub MoveFlask(ByRef Cavern(,) As Char, ByVal NewCellForFlask As CellReference, ByRef FlaskPosition As CellReference) Cavern(NewCellForFlask.NoOfCellsSouth, NewCellForFlask.NoOfCellsEast) = "F" Cavern(FlaskPosition.NoOfCellsSouth, FlaskPosition.NoOfCellsEast) = " " FlaskPosition = NewCellForFlask End Sub ``` What is the purpose of nested loops? Answer: To check each element of the array by progressing firstly along the columns, then down to the next row and to continue until the end of the array is reached; Why have they used FOR loops in the subroutine ResetCavern? Answer: The loop end is known when the loop is created and therefore has a known number of steps; the loop does not depend upon an event where the occurrence of that event is unknown;