411 REFERENCE · Wikibooks
A-level Computing 2009/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2015 Exam/Section C
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Validation
Error Checking
Example Question
Example Answer
Ways to crash game
In VB, if you type 18 then 08. The game crashes - fix this.
Function CheckMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer, ByVal WhoseTurn As Char) As Boolean
Dim PieceType As Char
Dim PieceColour As Char
If FinishFile = StartFile And FinishRank = StartRank Then
Return False
End If
PieceType = Board(StartRank, StartFile)(1)
PieceColour = Board(StartRank, StartFile)(0)
If FinishRank = 0 Or FinishFile = 0 Then 'This is the required if statement
Return False
End If
Variables
Variables
What is this function for? (code in answer)
If Asc(SampleGame) >= 97 And Asc(SampleGame) <= 122 Then
SampleGame = Chr(Asc(SampleGame) - 32)
End If
This converts lowercase to uppercase by using ASCII values.
{{CPTQuestion|What simple function can replace this code with? If Asc(SampleGame) >= 97 And Asc(SampleGame) <= 122 Then
SampleGame = Chr(Asc(SampleGame) - 32) End If
(Answer in Code)
SampleGame = Ucase(SampleGame)
Give the name of the identifier of a Constant
BoardDimension
Give the name of the identifier of a Fixed Value Variable
SampleGame
Give the name of a Most Wanted Holder Variable
GetMove
Give the name of the identifier of a Stepper Variable
fileNo
Give the name of the identifier of a Temporary Variable
Board
Give the name of the identifier of a Transformation Variable
StartRank
Loops
Loops
What is the difference between a repeat until loop and a for loop
The 'for' loop will run a set number of times and finish when the count is complete. A repeat until loop will run until a condition has been met, the condition is checked at the end of the loop so it is possible for the loop to run once
Example Question
Example Answer
Example Question
Example Answer
Sub Routines
Sub Routine
Give an example of a SubRoutine whose only role is to output
DisplayWinner, displayWhoseTurnItIs
Extra Stuff
Extra Stuff
Why is System.Math imported?
To allow the use of Abs() in the process of checking whether moves are legal.
Why is Abs used?
To return the absolute value. This is needed because the result of
(FinishFile - StartFile) or (FinishRank - StartRank) may be a negative number, whilst the move is still legal.
The Abs function returns the positive alternative, which prevents the program from crashing