Skeleton Program Flashcards

1
Q

Explain why a FOR repetition structure was chosen instead of a WHILE repetition structure.

A

The code is to be repeated a known number of times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give an example of instantiation from the Skeleton Program

A

TileQueue = QueueOfTiles(20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Look at the Main function in the Skeleton Program.

Why has a named constant been used for MaxHandSize instead of the numeric value 20?

A

Makes the program code easier to understand;

Makes it easier to update the program;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Create a class definition for QueueOfTiles

A
QueueOfTiles = class
       Public
                  Function IsEmpty  
                  Function Remove
                  Procedure Add
                  Procedure Show         
       Private
                  _Contents: Array
                  _Rear: Integer
                  _MaxSize: Integer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give an example of an assignment statement from the Skeleton Program where a variable is assigned an empty string.

A

Choice = “”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

State the name of an identifier for: a variable that has a stepper role

A

Count

for Count in range(self._MaxSize):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

State two reasons why subroutines should, ideally, not use global variables

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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 .

A

Because the scope; of the two variables is different; //

Because they are both local variables; in different subroutines;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A local variable (excluding parameters) within the HaveTurn subroutine

A

NewTileChoice / ValidChoice / ValidWord / Choice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An attribute within QueueOfTiles

A

_Contents / _Rear / _MaxSize

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write one line of code from the skeleton program which calls a library subroutine

A

RandNo = random.randint(0, 25)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Look at the subroutine CreateTileDictionary. Describe the purpose of the following line:
TileDictionary[chr(65 + Count)] = 1

A

Adds (an entry) to the dictionary
Entry includes character with ASCII value of 65 + ‘count’
Entry includes integer value ‘1’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

State and describe the data structure returned by the CreateTileDictionary subroutine.

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Look at the subroutine CheckWordIsInTiles. Explain the role of the variable CopyOfTiles.

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the difference between a procedure and a function. State one example of each from the skeleton code.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe what would happen if, during a call to LoadAllowedWords, the ‘aqawords.txt’ file was not found.

A

An exception would be thrown
Execution would pass to the ‘except’ block
The code to populate the AllowedWords list would not be executed
The ‘except’ block contains no code/instructions
An empty list would be returned

17
Q

Describe the actions performed in the following lines of the LoadAllowedWords subroutine:
for Word in WordsFile:
AllowedWords.append(Word.strip().upper())

A

Goes through the file one line at a time
Assigning the contents of each line to the variable Word
The Word/line is stripped of any trailing spaces and end of line characters/newlines
The Word/variable is converted to upper case
And appended to the list AllowedWords (or list of allowed words)

18
Q

Describe what is meant by the term ‘constructor’

A
A constructor is a method called by creating a variable using the class name e.g. variable = Class()
Creates a new object based on the class in which it resides
Constructor method is called \_\_init\_\_
Ensures that a new object in the class is initialised correctly
19
Q

Describe in detail the purpose of the subroutine UpdateScoreWithPenalty. Describe any parameters and/or return values in your answer.

A

Player’s current score, tiles in the player’s hand, TileDictionary that links tiles to points
Player’s updated score
Purpose of function is to subtract value of player’s tiles/hand from their score
Loop is established to iterate through each tile/character in the player’s hand
Value of each tile is determined by looking up in a dictionary
Value is subtracted from player’s score

20
Q

State the name of an identifier for a variable that has a most wanted holder role.

A

A variable that keeps track of the lowest or highest value in a set of inputs
Count

21
Q

Explain the difference between a protected attribute and a private attribute

A
A protected attribute can be accessed (within its class and) by derived class instances /
subclasses;
A private attribute can only be accessed within its class;