A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2016 Exam/Sample Question Papers/June 2016 Practice Questions 3

From Wikibooks, open books for an open world
Jump to navigation Jump to search

1. Within the subroutine printBoard() there is a conditional statement which is extremely long and not dynamic. Explain in the box below why it is not dynamic and in what situations it may not work correctly. The statement is shown below:-

(board[row][column] == 'A' || board[row][column] == 'B' || board[row][column] == 'S' || board[row][column] == 'D' || board[row][column] == 'P')
 

2 marks

2. Rewrite the statement within printBoard() to make it work dynamically.

Insert a screenshot of your code below
 

4 marks

Test your code by loading the training map, then entering a column value of 8, then a row value of 1. Then make another attack and enter a column value of 7, then a row value of 6. Then make another attack and enter a column value of 3, then a row value of 1. Insert a screenshot(s) of the result below
 

3 mark

3. Within the subroutine checkWin() there is a conditional statement which is the same as the one within printBoard(). If you were to just copy your dynamic statement from printBoard() to replace this it would not work. Explain why below:-

 

2 marks

4. Rewrite the statement within checkWin() to make it work dynamically.

Insert a screenshot of your code below
 

4 mark

5. Add another ship with a size of 1 and the name “Row Boat” to the appropriate subroutine

Insert a screenshot of your code below
 

2 marks

6. In order to make use of your additional ship, there is another change you must make to the program code. Make that change.

Insert a screenshot of your code below
 

1 mark

7. In order to test your code, you need to be able to see the positions of the ships on the board. To do this, there is a change you must make to the line console.print(" "); within the subroutine printBoard(). Comment out this line of code (DO NOT DELETE IT) and add an alternate line below it that will display the actual character stored within the board array instead of an empty space.

Insert a screenshot of your code below
 

4 marks

Run the game and choose option 1 from the menu. Screenshot the program output below
 

2 marks

8. So that the game performs as it used to, comment out your additional line of code and remove the comments from the line console.print(" ");

Insert a screenshot of your code below
 

1 mark

Run the game and choose option 1 from the menu. Screenshot the program output below
 

1 mark