First page of the May/Jun 2016 COS1511 paperSee a real past paper — freeMay/Jun 2016 · 75 marks · the scan, as written

How often Code tracing and variable diagrams is asked

8 of 8

papers asked it
avg 14 marks · last Supp 2025

Worth 1–8 marks when it appears as a written question, plus 14 multiple-choice items.

Where it was asked

The questions

  1. May/Jun 2018, Q1.42 marks · multiple choice

    Consider the following C++ code segment. What value will newval have after this code has been executed? int var1 = 5; int var2 = 10; int newval; if (var1 * 2 >= var2) newval = 5 + 2 * var2; else if (var2 < var1) newval = var2 - var1 * 2; else newval = var1;

  2. May/Jun 2018, Q1.52 marks · multiple choice

    Suppose the input value for a is 5. What is the value of a after the following C++ code has been executed? int a; cin >> a; switch (a) { case 1: a += 3; case 3: a = a * 3; break; case 5: a = ++a + 10; case 6: a /= 2; default: a = a + 1; }

  3. May/Jun 2018, Q1.62 marks · multiple choice

    Consider the following C++ code segment: int findValue(int numberP) { int count = 0; int value = 20; while (count < numberP) { value += count; count++; } return value; } What will be the output of the following statement when executed in the main function? cout << findValue(3);

  4. May/Jun 2018, Q1.92 marks · multiple choice

    The GoodHope high school will pay for a learner's rugby tour under the following conditions: either the learner's parents' total income is less than R48 000 per year and the learner is not their only child, or the learner has an average of 80% or more and plays in the A team. A float variable income represents the income of the parents. A bool variable only has the value true if the learner is an only child, and false otherwise. A float variable average represents the learner's average, and the bool variable team has the value true if the learner plays for the A team, and false otherwise. The boolean variable pay should receive the value true if the above conditions are met. Which of the following options will assign the correct value to pay?

  5. May/Jun 2018, Q2(a)2 marks

    Questions 2(a) and 2(b) each require a written explanation, in words, of what a given segment of code is meant to achieve. Before answering, consider the following example: given the declarations int a, b, c; followed by the statements cin >> a >> b >> c; and cout << c + b + a;, the purpose of this code segment is to input three integer values and display their sum. Assuming that s and n have been declared as integers, explain in words what the purpose is of the following segment of code: int s = 0, int n = 0, then a while loop that repeats while (n <= 5), inside which s = s + n is executed followed by n++.

The full Spot Map and the marks by year.