Symbol Puzzle Flashcards
What is the purpose of this selection statement? [4]
if (Filename.Length > 0)
{
MyPuzzle = new Puzzle(Filename + “.txt”);
}
else
{
MyPuzzle = new Puzzle(8, Convert.ToInt32(8 * 8 * 0.6));
}
-Calls the Puzzle constructor with one parameter (filename) if it is longer than 0
-This will initialise the Puzzle using the text file
-If not longer than 0 then random puzzle is generated of size 8
-This has second parameter (max pieces) set to 60% of available grid spaces
-Blocks will be randomly generated
What is the OOP technique that allows methods of the same name but different signatures to be defined in the same class? [1]
Overloading
Why would constants be more appropriate than hard-coded numbers? [2]
-Code is easier to follow and understand
-Only have to be updated in one place
Discuss two advantages of OOP over structured approach. [4]
-OOP can encapsulate behaviour and attributes, by hiding the implementation
-OOP classes allows programmers to work together, as classes can be tested and developed separately
How is a successful match determined? [2]
-A string of symbols on the grid are generated using the same pattern as the pattern match for a character
-If all symbols match then MatchPattern returns true indicating a successful match
How is an unsuccessful match determined? [1]
When the string on the grid is compared to the pattern match, if one symbol doesn’t match, then it’s unsuccessful
How are players prevented from playing any more matched symbols in the 3x3? [1]
When a pattern has been matched, each cell in the 3x3 is updated to have the current symbol added to its SymbolsNotAllowed list
What is the regex for the Q pattern? [1]
QQ..Q..QQ
Define the term ‘inherits’? [2]
-Inherits means that the child class gains all of the non private methods of the parent
-And all the attributes of the parent
Describe two advantages of BlockedCell inheriting from Cell rather than being hard-coded? [4]
-A BlockedCell is treated as a Cell
-Through Polymorphism
-BlockedCell declutters Cell by having all features of it encapsulated [2] OR
-CheckSymbolAllowed can be overridden to make sure it always returns false for BlockedCell [2]
Define the term ‘override’ in the context of OOP. [2]
-Override is when you have a method in a child class with the same name as a method in the parent class
-In a different implementation
Describe what the purpose of this code is [4]
bool Valid = false;
int Row = -1;
while (!Valid)
{
Console.Write(“Enter row number: “);
try
{
Row = Convert.ToInt32(Console.ReadLine());
Valid = true;
}
catch
{
}
}
-The iterative statement keeps looping until an integer is entered
-This is done by having a Boolean loop condition set to false until an integer is entered
-The try/catch means that if anything else is entered a Runtime exception is raised
-The execution is interrupted so that valid will be set to false and catch will run instead
Describe the effect of raising an exception. [2]
-Raising an error will cause the current execution to stop
-And will terminate the program with a Runtime error
-Unless exception is handled
Identify one use of polymorphism of Cell and BlockedCell classes. [1]
Overriding the CheckSymbolAllowed method
Define the term ‘polymorphism’ [3]
-The ability for an object to be treated as one of its parents
-Allowing it to be grouped with other objects that have a common parent
-But for methods that are called to actually be resolved on the real class of the object instead of the parent method