Symbol Puzzle Theory Flashcards

1
Q

T/F Does the program use indefinite iteration?

A

True

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

T/F Does the program use definite iteration?

A

False

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

T/F Does the program use local variables?

A

True

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

T/F Does the program use global variables?

A

False

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

T/F Does the program use constants

A

False

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

T/F Does the program use nested selection?

A

False

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

The Main subroutine could be altered to use constants. Suggest one way in which they could be used, and how this would be beneficial.

A

Using a constant to represent/for the (default) board size;
This would improve readability // Changing this would then only require editing one location;

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

The Skeleton Program uses overriding. When a derived class overrides a method
from the base class, the base class method could be either a virtual method or an
abstract method.
Describe two differences between a virtual method and an abstract method.

A

Virtual methods can be overridden by the derived class //
virtual methods do not have to be overridden //
abstract methods must be overridden by the derived class;

Virtual methods have an implementation/body //
virtual methods contain code (with functionality) (in the base class) //
abstract methods do not contain an implementation/body //
abstract methods contain no code (with functionality) (in the base class) //
abstract methods only contain a declaration (in the base class);

Abstract methods can only be declared in abstract classes //
virtual methods can be declared in abstract and non-abstract classes;

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

The cell class contains a virtual method UpdateCell, which contains no code. Explain why this function may need to exist, even if it never contains code.

A

So that all Cells/Cell objects/types of Cell in Grid have an UpdateCell method, (regardless of the type of cell);

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

Figure 6 shows a pseudo-code representation part of the MatchPattern method.
Figure 6
PatternToCheck[i] == Symbol AND Pattern[i] != Symbol
Rewrite the code in Figure 6 so that it has the same functionality, but uses OR and NOT Boolean operations only, instead of the AND Boolean operation.

A

NOT ( PatternToCheck[i] != Symbol OR Pattern[i] == Symbol );
A. Any suitable alternative to NOT.
A. NOT ( PatternToCheck[i] == Symbol ) instead of ‘PatternToCheck[i] != Symbol’
If 2 marks not awarded, one mark for PatternToCheck[i] != Symbol // Pattern[i] == Symbol ;

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

State the name of an identifier for a user-defined method within the Puzzle class that uses string concatenation.

A

AttemptPuzzle // CheckForMatchWithPattern // CreateHorizontalLine // DisplayPuzzle;

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

State the identifier and purpose of a subroutine that takes two integer parameters within the Puzzle class.

A

GenRandPuzzle: Creates a puzzle with randomly placed blocked cells (of a set size) //
GetCell: Returns a Cell (at the given Row & Column) //
CheckForMatchWithPattern: Returns the score for a given move;

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

Explain why the value of -1 is used in the GetCell method in the Puzzle class.

A

Because the arrays are 0 indexed;

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

Explain the difference between an attribute that has a public specifier and an attribute that has a protected specifier.

A

Public means it can be accessed / seen outside of the class it is in;

Protected means it can be accessed / seen in the class it is in and in any subclasses // protected means it can be accessed / seen in the class it is in and in any classes derived / inheriting from it;

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

In object-oriented programming, what is meant by overriding?

A

When a derived class / subclass has a different implementation for a method / function / subroutine to the class it inherits from / from the base class;

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

A Regular Expression could have been used instead of a for loop in MatchesPattern.
1. Write the regular expression that would match the pattern “QQ..Q..QQ”.

  1. Explain why an iterative method may have been used instead of a Regular Expression.
A

QQ..Q..QQ // Q{2}.{2}Q.{2}Q{2} ;

For simple patterns, for loops are generally more efficient //
The programmer may not understand Regular Expressions //
The code will be easier to debug/modify later;

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

The value 8 is used twice in the subroutine GenRandPuzzle. It would be better to use a named constant with an identifier that describes the purpose of the constant.

Suggest a suitable identifier for the named constant.

A

DefaultGridSize;
A. GridSize
A. any suitable identifier that makes it clear that the constant represents the grid size/width.

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

Explain why the CheckForMatchWithPattern subroutine in the Puzzle class could have been a private subroutine.

A

CheckForMatchWithPattern is only ever called from within the AttemptPuzzle subroutine, which is also within Puzzle;

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

Describe the modifications that would need to be made to the AttemptPuzzle subroutine so that the user’s turn is always a valid move.

A

A loop/method/default behaviour must be implemented to handle a player’s wrong Row and Column inputs;
A loop/method/default behaviour must be implemented to handle a player playing on a blocked cell;

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

In object-oriented programming, what is meant by polymorphism?

A

A method shared (up and down the inheritance hierarchy chain) but with each class / method implementing it differently
//
A single interface is provided to entities/objects of different classes / types
//
Objects of different classes / types respond differently to the use of a common interface / the same usage
//
Allowing different classes to be used with the same interface
//
The ability to process objects differently depending on their class / type;

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

The LoadGame subroutine uses exception handling to prevent potential runtime errors. An example of an event that could cause a runtime error when executing the LoadGame subroutine would be trying to open a file that does not exist.

  1. Describe another event that could cause a runtime error when executing the LoadGame subroutine.
  2. State the identifier of another subroutine that uses exception handling.
A

Any incorrectly formatted text files, EG the wrong number of symbols after NoOfSymbols is read, or the file beginning with a character rather than a number;

CheckForMatchWithPattern

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

The Cell class contains both protected and private attributes. Explain the difference between protected and private attributes.

A

Private attributes can only be accessed by the class/object they belong to whereas protected attributes can also be accessed by any classes that inherit from the class they belong to;

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

Aggregation, composition and inheritance are three different types of relationship that can exist between classes. Which of these three types of relationship is not in the Skeleton Program?

A

Aggregation

24
Q

The method MatchesPattern returns false if the Pattern supplied has the wrong letter where the Symbol letter should be. What else causes the MatchesPattern subroutine to return false?

A

The symbol placed does not match the pattern’s symbol.
NE. SymbolPlaced != Symbol

25
Q

The Skeleton Program loads the game data from a text file. State two reasons why a text file might have been chosen for use with the Skeleton Program instead of a binary file.

A

A text file is more easily read by a person;
So it is easier to modify/create;

26
Q

The AttemptPuzzle subroutine passes a row and column number into the subroutine GetCell. Explain what it means if a value of -1 is passed into GetCell for the value of Column.

A

The user did not enter a number when asked for the column number

27
Q

What is the time complexity of the CheckSymbolAllowed subroutine?

A

O(n), where n is the length of SymbolsNotAllowed.

28
Q

Explain the steps involved in identifying all possible patterns which the user may have completed by placing a symbol.

A

Mark for AO2
Iterate through every 3x3 which contains the Cell chosen by the user;

Marks for AO1
Starting with the cell two rows above, and two columns to the left, create the pattern string for the 3x3 with this cell in the top-left corner;

If this 3x3 is a completed pattern, (add the symbol to the list of blocked symbols for each cell in the 3x3, then) return 10, indicating that the pattern has been matched;

If any cell’s row is above or below the grid boundaries, this 3x3 is not checked (skipped by the try-catch)

Continue this process, reducing row number and increasing column number, until you check the initially indicated cell. If no pattern has matched, return 0, indicating the pattern has failed to match;

29
Q

There is an error in the code for the Skeleton Program when the user places a symbol near the left or right of the grid. Under what circumstances will CheckForMatchWithPattern incorrectly identify a successful match?

A

CheckForMatchWithPattern detects patterns which go to the right of column 8, or to the left of column 0 //
CheckForMatchWithPattern detects patterns which wrap around the left & right grid boundaries;

30
Q

State the name of an identifier for a user-defined subroutine in the Skeleton Program that uses exception handling.

A

LoadPuzzle // CheckForMatchWithPattern ;

31
Q

Explain the difference between a local variable and a global variable.

A

Local variables have more limited scope;
Global variables exist throughout the entire program;
Local variables only exist in a part/block/subroutine of the program;
Local variables can only be accessed in a part/block/subroutine of the program;
Global variables can be accessed from any part of the program;

32
Q

State one reason why it is considered to be good practice to use local variables.

A

Modularisation of a program;
Allows reuse of subroutines;
Less chance of side-effects;

33
Q

State the name of an identifier for a built-in function used in the Skeleton Program that has a string parameter and returns an integer value.

A

Convert.ToInt32

34
Q

State the name of an identifier for a local variable in a method in the Cell class.

A

Item

35
Q

The Puzzle class implements a List of Cell. An array could have been used instead.
Explain why an array is often a better choice of data structure than a list.

A

Arrays are fixed in size and require elements of the same data type;

leading to improved/reduced memory allocation //
leading to improved/faster computational performance;

36
Q

Describe the changes that would need to be made to the Skeleton Program so that patterns are worth 1 fewer points for every pattern of that type already scored. You should not change the Skeleton Program when answering this question.

A

Solution 1
Store a dictionary/array/list/hash table of points per pattern within the Puzzle/Program class;
initialising each pattern with 10 points in LoadGame and GenRandomPuzzle;
Reduce the points per pattern every time that pattern is detected;
Return the correct number of points (rather than the 10 that is currently coded.);

Solution 2
Modify the Pattern class to store the points it is worth.
Create a subroutine within the Pattern class which reduces its points by one;
and return the points for scoring the pattern;
Alter the CheckForMatchWithPattern subroutine to return the Pattern’s points, (rather than the 10 that is currently coded);

37
Q

State the name of an identifier for a subclass in the Skeleton Program.

A

BlockedCell

38
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;

39
Q

In the Puzzle class there is an attribute Grid and a method GetCell.
Explain the need for the GetCell method rather than array indexing, and explain why this approach is favoured in object-oriented programming.

A

1 mark for AO2 (analyse)
Grid (is a private attribute and) is not accessible outside of the Puzzle class;

1 mark for AO1 (understanding)
Means the way GetCell is represented can be modified without having to change any other objects that interact with Grid. NE. without having to change other code // makes it easier to reuse/inherit from Puzzle class);
It indicates to the programmer that individual cells in Grid should be accessed, but not modified;

40
Q

Part of the class definition for Cell has been represented in Figure 12.
Figure 12
Cell = Class
Private:
Symbol: string
Protected:
SymbolsNotAllowed: List(string)
Public:
Procedure Cell()
Function GetSymbol(): string
Function IsEmpty(): bool
Procedure ChangeSymbolInCell(NewSymbol : string)
Function CheckSymbolAllowed(SymbolToCheck : [1]) : bool
Procedure [2] (SymbolToAdd : string)
Procedure UpdateCell()
End Class

What should be written to replace [1]?

What should be written to replace [2]?

A

string

AddToNotAllowedSymbols

41
Q

A new type of cell is to be introduced to the game. This cell is the ShiftyCell, which changes its symbol whenever UpdateCell is called, until it is used to complete a pattern. The class ShiftyCell is to be a subclass of the Cell class.

A ShiftyCell has the following additional attributes:
PossibleSymbols: stores a list of possible symbols to change to.
IsShifting: stores a value that represents whether or not the symbol will continue to change when UpdateCell is called.
A ShiftyCell has the following additional methods:
IsShifting(): returns True if the cell is still changing every type UpdateCell is called.
BeenScored(): returns True if the cell has been used to score a pattern.

Write the class definition for ShiftyCell, using similar notation to that used in Figure 12. You are not expected to make any changes to the Skeleton Program.

A

Shifty Cell = Class : Cell
Private:
PossibleSymbols: List(string)
IsShifting: bool
Public:
Function IsShifting(): bool
Function BeenScored(): bool
Procedure UpdateCell()

42
Q

local booleans (2)

A

-finished
-valid

43
Q

local strings (2)

A

-PatternString
-Line

44
Q

local integers (2)

A

-NoOfSymbols
-NoOfPatterns

45
Q

subroutines that return booleans (4)

A

-MatchesPattern
-IsEmpty
-CheckSymbolAllowed
-CheckSymbolAllowed

46
Q

string attributes (2)

A

-Symbol
-PatternSequence

47
Q

subroutines that return strings (4)

A

-GetSymbol
-GetPatternSequence
-GetSymbolFromUser
-CreateHorizontalLine

48
Q

integer attributes (3)

A

-Score
-SymbolsLeft
-GridSize

49
Q

subroutines that return integers (2)

A

-CheckForMatchWithPattern
-AttemptPuzzle

50
Q

list attributes (4)

A

-Grid
-AllowedPatterns
-AllowedSymbols
-SymbolsNotAllowed

51
Q

subroutines that return cell objects (1)

A

-GetCell

52
Q

classes that inherit from other classes (1)

A

-BlockedCell

53
Q

classes that inherit from other classes (1)

A

-BlockedCell

54
Q

global variables (1)

A

-Rng

55
Q

constructors (5)

A

-Cell()
-BlockedCell()
-Puzzle(string Filename)
-Puzzle(int Size, int StartSymbols)
-Pattern(string SymbolToUse, string PatternString)

56
Q

relations between classes (3)

A

-Cell has a composite relationship with puzzle
-Pattern has a composite relationship with puzzle
-BlockedCell inherits from Cell