The loop test true true enter the while loop
Where model answers are given in note form, that is just for guidance over points made. You are expected to write full explanations not just give bullet point answers.
However good or bad your programming skill is now, keep writing programs whether small or large as the more you practice any skill the better you can become.
See the General Exam and Test Advice and Feedback document on the QM+ site for general issues that appear to apply every year in every exam and test for at least some students and applied here too. For written programs for many it was that they just could not program well enough to make a good attempt at these questions. The best showed strong computational thinking skills.
Question 1 Feedback
a) [6 marks]Feedback:
This was largely answered moderately well with only a few gaining full marks. Some seemed to just answer a similar but different question that was on a previous paper so showing a lack of understanding. Others answered in OOP not procedural programming terms in ways that suggested they had just googled it and paraphrased definitions that only partly applied (again showing a lack of understanding of this context). This question was not simply about global and local variables and ALL the variables in the example are local to the method. While that is to some extent relevant it is not what the question is really about. Most lost marks because they did not realise there are variables that are local just to blocks as in the example and talked about only being local to a method. Each variable declaration in the example gave an opportunity to explain something different about scope. Only a few took advantage of these hints from the example.
So for example in the given code the variable round is declared in the method highLow at its top level (as defined by the outer curly brackets. It therefore exists from the point it is defined to the final (outer curly bracket). This means also inside the inner while loop and if statement branches inside that .
Similarly score can be assigned to and accessed in the while loop and if statement but NOT outside the while loop.
The use of declarations and scope also gives the compiler more information about your intentions so it can spot errors whenever you are inconsistent - eg trying to print the score outside the loop would raise an error. You said you were not going to do that. This prevents errors making it into running programs.
b)[Total 9 marks]
Marking notes:
Answers must include all of the dry run table, correct answer and clear justification for full marks. There are no marks for just the resulting answer - both dry run and explanation must also be given for pass marks. However if answer and dry run is correct any explanation that shows the
semantics were understood is sufficient for full marks.on iii) many used the slot in the table for indices to put the values. No marks were lost for this though not having the indices written makes mistakes more likely. The most common mistake was to miss the last step of the loop condition being shown to be false. Explanations were sometimes far too sketchy and general not giving detail of which index positions for this array led to the if statement being true for example.
b i) [2 marks]
b ii) [3 marks]
Model answer
1 | ||
5 | ||
5 | ||
|
||
9 | ||
9 | ||
|
||
b iii) [4 marks]
Model answer
What is printed
7-10: Logically correct program. It does the right thing.
Greater marks for doing it elegantly/defensively…style good: comments, efficient algorithm, elegant use of methods and arguments, avoids repeating code that could be a method, error checking etc.
Generally good style especially for higher mark, but may be some issues.
Basic structure of algorithms are correct but may not deal with subtleties.
0-3: Fragmentary code answer - eg rote-learnt / copied bits of code / only partial answers to sub problems.
No clear evidence can write a program to solve a problem.
Higher marks can write declarations, if statements.One common problem from weaker answers was that they just did the wrong thing (usually something simpler) eg printed a fixed number of rows out (eg copying only the example) or printed out all numbers out then printed a new grid underneath with stars. Such answers got some marks for showing they could use constructs such as loops but the program had to do the right thing for high marks.
Model answer
One good answer
/* Print tables of numbers with times tables starred out
Author: anon
12 July 2021
*/
import java.util.Scanner;// Print a table with given times tables starred out
//
public static void printTable
(int rowtotal, int timestable1, int timestable2, String BLANK_STRING) {
for(int row = 0; row < rowtotal; row = row + 1)
{
printRow(row, timestable1, timestable2, BLANK_STRING);
print("\n");
}return;
}// Is a given number in a given timestable?
//
public static Boolean inTimesTable(int n, int timestable)
{
return (n % timestable == 0);
}String textinput;
int result;System.out.println(message);
textinput = keyboard.nextLine();
result = Integer.parseInt(textinput);
} |
---|
public static void printRow(int row, int timestable1, int timestable2, String BLANK_STRING) {
Iinal int LENGTH_OF_ROW = 10;
int start = (row * LENGTH_OF_ROW) + 1;for(int n = start; n < start + LENGTH_OF_ROW; n++)
{
if (inTimesTable(n,timestable1) | inTimesTable(n,timestable2)) {
print(BLANK_STRING);
}
else if (row == 0)
{
print(n + " ");
}
else
{
print(""+n);
}
print(" ");
}
semantic differences (what they do differently) not just syntactic differences (spelling, punctuation,
etc), to show deep understanding. 1-2 marks possible for each compare or contrast point
Feedback:
Many answered the question really well giving a whole series of point by point comparison and contrast points. A key problem was some students compared and contrasted what the given code does NOT the if/while constructs as the question asked. Others just explained the two constructs separately NOT pointing out similarities and differences one after the other.This suggests that those students had neither read/understood the question nor read previous guidance and past paper feedback where both these mistakes were clearly highlighted.
count = count + 1;
are executed.
Marking notes:
1- 2 marks for each explanation point depending on how clear and detailed but must refer to given example for marks. Any working recursive variation of binary search is fine. 2-3 of the marks are for the explanation of unsorted data.Feedback
i) The algorithm first goes to the middle point (or as near as it can go) and compares that with the key being searched for. Here, assuming we go to the lower of the two possible positions we check if 47 we are looking for is equal to the 19 at that point. It isn’t so we instead use it as a sign post to rule out either the top or the bottom half of data. As the data is sorted, 47 must be to the right of 19. We can throw away everything to the left (19 included).
We now have a similar but smaller problem of searching {23,29,31,37,41,43,47,53}
d) [10 marks]
Marking notes:
The following table gives an indicative idea of what marks an answer deserves. The main point is logical correctness. Thereafter the more readable the code is by a human (as indicated by structural and style points below) the higher the mark.Style good: indentation, comments,
Can correctly use variables, if, loops, arrays, methods and pass arrays to methods. Possibly partial attempt at abstract data type.Small errors errors could be offset with good use of advanced aspects such as ADTs.
4 : More major errors but evidence that can write a program using appropriate constructs if put in front of a compiler - though it may take time.
More than simple slips in algorithm code.At least some good style
See the general feedback about writing programs for comments that apply in general to writing code as it all applies here.
Many didn’t attempt this question at all even though there were easy marks to pick up just by solving small parts of it.
Model answer:
The following is one good answer
System.exit(0);
}// Run simulations until the user wants to stop
//
public static void RunSimulations(int SIMULATION_ROUNDS, int SPREAD_TO) {
String quit = "no";quit = inputString("Do you wish to Quit? (yes or no)");
}return;
}for(int i = 0; i < population.length; i++)
{
if (isDead(population[i])) countDead++;
}
System.out.println(countDead + " died and " + (population.length - countDead) + " survived.");return;
}// create the Array of records and update the records to the right number are // vaccinated and infected.
//
public static SimulatedPerson[] createPopulation (int howManyPeople, int howManyInfected, int percentageVaccinated)
{
SimulatedPerson[] population = new SimulatedPerson[howManyPeople];public static void clearPopulation (SimulatedPerson[] population)
{
for(int i = 0; i < population.length; i++)
{
population[i] = createSimulatedPerson();
}return;
}return;
}// All people who are infected die (they previously infected others)
//
public static void killAllInfected (SimulatedPerson[] population)
{
for(int person = 0; person < population.length; person++)
{
if (hasVirus(population[person]))
population[person] = dies(population[person]);
}
// General purpose method to input a String
// printing a given message as prompt.//
public static String inputString(String message)
{
Scanner keyboard = new Scanner(System.in);
String textinput;
} |
---|
// Create a PeakReading data structure with the maximum size as given //
public static SimulatedPerson createSimulatedPerson()
{
SimulatedPerson sp = new SimulatedPerson ();sp.isvaccinated = false;
sp.hasvirus = false;
sp.isdead = false;
// does this person have the virus?
//
public static boolean hasVirus(SimulatedPerson sp)
{
return sp.hasvirus;
}}
// Data type to hold the data of a single simulated person
//
class SimulatedPerson
{
boolean isvaccinated;
boolean hasvirus;
boolean isdead;
}return;
}