Symbol Puzzle Theory Flashcards
T/F Does the program use indefinite iteration?
True
T/F Does the program use definite iteration?
False
T/F Does the program use local variables?
True
T/F Does the program use global variables?
False
T/F Does the program use constants
False
T/F Does the program use nested selection?
False
The Main subroutine could be altered to use constants. Suggest one way in which they could be used, and how this would be beneficial.
Using a constant to represent/for the (default) board size;
This would improve readability // Changing this would then only require editing one location;
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.
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;
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.
So that all Cells/Cell objects/types of Cell in Grid have an UpdateCell method, (regardless of the type of cell);
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.
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 ;
State the name of an identifier for a user-defined method within the Puzzle class that uses string concatenation.
AttemptPuzzle // CheckForMatchWithPattern // CreateHorizontalLine // DisplayPuzzle;
State the identifier and purpose of a subroutine that takes two integer parameters within the Puzzle class.
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;
Explain why the value of -1 is used in the GetCell method in the Puzzle class.
Because the arrays are 0 indexed;
Explain the difference between an attribute that has a public specifier and an attribute that has a protected specifier.
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;
In object-oriented programming, what is meant by overriding?
When a derived class / subclass has a different implementation for a method / function / subroutine to the class it inherits from / from the base class;
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”.
- Explain why an iterative method may have been used instead of a Regular Expression.
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;
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.
DefaultGridSize;
A. GridSize
A. any suitable identifier that makes it clear that the constant represents the grid size/width.
Explain why the CheckForMatchWithPattern subroutine in the Puzzle class could have been a private subroutine.
CheckForMatchWithPattern is only ever called from within the AttemptPuzzle subroutine, which is also within Puzzle;
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 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;
In object-oriented programming, what is meant by polymorphism?
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;
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.
- Describe another event that could cause a runtime error when executing the LoadGame subroutine.
- State the identifier of another subroutine that uses exception handling.
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
The Cell class contains both protected and private attributes. Explain the difference between protected and private attributes.
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;