Skeleton Program Flashcards
Explain why a FOR repetition structure was chosen instead of a WHILE repetition structure.
The code is to be repeated a known number of times
Give an example of instantiation from the Skeleton Program
TileQueue = QueueOfTiles(20)
Look at the Main function in the Skeleton Program.
Why has a named constant been used for MaxHandSize instead of the numeric value 20?
Makes the program code easier to understand;
Makes it easier to update the program;
Create a class definition for QueueOfTiles
QueueOfTiles = class Public Function IsEmpty Function Remove Procedure Add Procedure Show Private _Contents: Array _Rear: Integer _MaxSize: Integer
Give an example of an assignment statement from the Skeleton Program where a variable is assigned an empty string.
Choice = “”
State the name of an identifier for: a variable that has a stepper role
Count
for Count in range(self._MaxSize):
State two reasons why subroutines should, ideally, not use global variables
Easier reuse of routines in other programs;
Routine can be included in a library;
Helps to make the program code more understandable;
Ensures that the routine is self-contained // routine is independent of the rest of the program;
(Global variables use memory while a program is running) but local variables use memory for only part of the time a program is running;
reduces possibility of undesirable side effects;
Using global variables makes a program harder to debug
There is a variable called Count in the CreateTileDictionary subroutine.
There is also a variable called Count in the GetStartingHandsubroutine.
Explain why these two different variables can have the same identifier .
Because the scope; of the two variables is different; //
Because they are both local variables; in different subroutines;
A local variable (excluding parameters) within the HaveTurn subroutine
NewTileChoice / ValidChoice / ValidWord / Choice
An attribute within QueueOfTiles
_Contents / _Rear / _MaxSize
Write one line of code from the skeleton program which calls a library subroutine
RandNo = random.randint(0, 25)
Look at the subroutine CreateTileDictionary. Describe the purpose of the following line:
TileDictionary[chr(65 + Count)] = 1
Adds (an entry) to the dictionary
Entry includes character with ASCII value of 65 + ‘count’
Entry includes integer value ‘1’
State and describe the data structure returned by the CreateTileDictionary subroutine.
Dictionary Contains unique keys Keys are letters of the alphabet Each key links to another value Other value is an integer / the score for that letter
Look at the subroutine CheckWordIsInTiles. Explain the role of the variable CopyOfTiles.
Creates a copy of the player’s tiles
Characters are eliminated from the copy
Prevents tiles being eliminated from player’s tiles (since word has not been played yet)
Describe the difference between a procedure and a function. State one example of each from the skeleton code.
A procedure performs a sequence of events but does not return a value, e.g DisplayMenu, DisplayTilesInHand
A function also performs a sequence of events but does return a value, e.g CheckWordIsInTiles