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

  1. Write an explanation of how makePlayerMove() works below

5 marks

2. Within the final else statement in makePlayerMove(), the player is told “Hit at” position if they have hit an enemy ship. Modify the code within this else statement so that it also outputs the name of the ship that they have hit.

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 marks

3. The board stores the first character from the ship name to represent which ship is stored in a square. Create a new function called outputHit. It must return a String and take two parameters, a character called square and an array of Ship called ships. It must loop through each item in the array until it finds the name of the ship that matches the square character and then return the name of that ship. You will need to modify the output code in makePlayerMove() so that it passes in the pointer to the ships array and the board[row][column] value and outputs the string that is returned by the function.

Insert a screenshot of your outputHit() code below

8 marks

Insert a screenshot of your code where you call this function within makePlayerMove() below

2 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 marks