Symbol Puzzle Flashcards

1
Q

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));
}

A

-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

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

What is the OOP technique that allows methods of the same name but different signatures to be defined in the same class? [1]

A

Overloading

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

Why would constants be more appropriate than hard-coded numbers? [2]

A

-Code is easier to follow and understand
-Only have to be updated in one place

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

Discuss two advantages of OOP over structured approach. [4]

A

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

How is a successful match determined? [2]

A

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

How is an unsuccessful match determined? [1]

A

When the string on the grid is compared to the pattern match, if one symbol doesn’t match, then it’s unsuccessful

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

How are players prevented from playing any more matched symbols in the 3x3? [1]

A

When a pattern has been matched, each cell in the 3x3 is updated to have the current symbol added to its SymbolsNotAllowed list

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

What is the regex for the Q pattern? [1]

A

QQ..Q..QQ

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

Define the term ‘inherits’? [2]

A

-Inherits means that the child class gains all of the non private methods of the parent
-And all the attributes of the parent

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

Describe two advantages of BlockedCell inheriting from Cell rather than being hard-coded? [4]

A

-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]

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

Define the term ‘override’ in the context of OOP. [2]

A

-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

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

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
{
}
}

A

-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

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

Describe the effect of raising an exception. [2]

A

-Raising an error will cause the current execution to stop
-And will terminate the program with a Runtime error
-Unless exception is handled

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

Identify one use of polymorphism of Cell and BlockedCell classes. [1]

A

Overriding the CheckSymbolAllowed method

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

Define the term ‘polymorphism’ [3]

A

-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

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

Describe how the code for GetCell demonstrates encapsulation. [3]

A

-GetCell has an interface that require a row and column
-Which suggests that the data structure will be two-dimensional
-When in fact the implementation uses a one-dimensional array

17
Q

Describe the effect of GetCell being called with the arguments Row=2 and Column=10
using the standard Grid size of 8. [2]

A

-The 57th element
-of Grid will be returned

18
Q

Empty cells contain the empty string “” yet are displayed on screen as “-”.
Describe the route of execution of code that achieves this, starting with a call to GetSymbol. [3]

A

-GetSymbol calls the method IsEmpty() to check if the Cell is empty
-And then returns the symbol - ,if it is
-IsEmpty returns true if the length of symbol is 0 otherwise false

19
Q

Explain the difference between a protected attribute and a private attribute. [2]

A

-A private attrubute can only be used with the current class
-A protected attribute can also be used in any classes that inherit from the current class

20
Q

Describe one difference between a list and an array. [1]

A

A list is a dynamic data structure whereas an array is a static

21
Q

Discuss using a two-dimensional array with using a list of Cell references to store Grid.[4]

A

-A list is a dynamic data structure so it will be stored in one block of memory
-Making it more time efficient
-It will be more intuitive because its how the structure is displayed to the user
-Whereas the one-dimensional list needs a conversion from the row and column to get cell

21
Q

[] 1 2 3 4 5
5 X X X
4 X X
3 X O X
2 X X
1 X X X

Describe the logic that only allows 10 points for placing the X in position marked O. [2]

A

-All possible 3x3 sections around the square which the player has placed a symbol are checked
-If a match is found the method returns 10 which stops any further matches from being detected

22
Q

[] 1 2 3 4 5
5 X X X
4 X X
3 X
2 X X
1 X

State a list of four moves in order, each placing an X to result in a score of 40. [2]

A

(3,3) (3,5) (1,1) (1,5) OR
(3,3) (3,5) (1,5) (1,1) OR
(3,3) (1,1) (3,5) (1,5)

23
Q

Define what a tractable problem is. [2]

A

-A tractable problem has a solution
-In polynomial time or better

24
Q

Explain the purpose of the keyword base() [1]

A

Is used to call the constructor in the base class

25
Q

Describe the meaning of a public attribute [1]

A

A public attribute can be accessed by anything

26
Q

Explain why the use of private and protected attributes provides better encapsulation than public attributes [3]

A

-Private and protected mean the accessor methods have to be used
-This controls access to the attributes
-Allows validation to be put in place