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

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Validation[edit | edit source]

Error Checking

Example Question

Answer:

Example Answer

Ways to crash game

In VB, if you type 18 then 08. The game crashes - fix this.

Answer:


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[edit | edit source]

Variables

What is this function for? (code in answer)

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.


1-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)

Answer:

SampleGame = Ucase(SampleGame)


Give the name of the identifier of a Constant

Answer:

BoardDimension


Give the name of the identifier of a Fixed Value Variable

Answer:

SampleGame


Give the name of a Most Wanted Holder Variable

Answer:

GetMove


Give the name of the identifier of a Stepper Variable

Answer:

fileNo


Give the name of the identifier of a Temporary Variable

Answer:

Board


Give the name of the identifier of a Transformation Variable

Answer:

StartRank

Loops[edit | edit source]

Loops

What is the difference between a repeat until loop and a for loop

Answer:

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

Answer:

Example Answer


Example Question

Answer:

Example Answer

Sub Routines[edit | edit source]

Sub Routine

Give an example of a SubRoutine whose only role is to output

Answer:

DisplayWinner, displayWhoseTurnItIs

Extra Stuff[edit | edit source]

Extra Stuff

Why is System.Math imported?

Answer:

To allow the use of Abs() in the process of checking whether moves are legal.


Why is Abs used?

Answer:

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