Question Constellation Sign up for free

AQA · GCSE · Computer Science · Higher

Checking consecutive tile values in C#

Q12.6 4 marks
Table 4
SubroutinePurpose
getTile(row, column)Returns the number of the tile on the board in position (row, column).

The blank space on a board is represented by 0. Figure 18 and Figure 19 show example boards.

Figure 18
row \ column012
0520 (blank)
1134
2678
Figure 19
row \ column012
0234
1510 (blank)
2786

For the board in Figure 18, the program would display No. For the board in Figure 19, the program would display Yes.

Write a C# program to check that, in the first row, the second tile number is one more than the first and the third tile number is one more than the second. Display Yes when both conditions are met and No otherwise. You must use getTile. Use meaningful variable name(s) and C# syntax.

Write your answer first. You can study the marking guidance whenever you need it.

Study the marking See what earns credit and compare it with a full-mark answer.

Marking points

  1. 1 Uses suitable selection for the combined requirement.
  2. 2 Checks three values for consecutive increments of exactly one.
  3. 3 Uses first-row coordinates (0,0), (0,1) and (0,2).
  4. 4 Outputs exactly one of Yes or No on every route.

Full-mark answer

if ((getTile(0, 1) - getTile(0, 0) == 1) && (getTile(0, 2) - getTile(0, 1) == 1)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }

Why this answer loses marks

I checked only that each later tile was larger and used separate unconditional statements for both messages.

The values must increase consecutively, and exactly one outcome should be displayed for each board.