COS1511 Oct/Nov 2023 exam paper — questions

🔒 Scan locked

The paper, as written

Every question, by topic

  1. Question 1.1 · Selection: if/else and switch statements · 2 marks

    Consider this C++ code segment and determine what value the variable newval will hold once the code has executed: int var1 = 4; int var2 = 10; int newval = 0; if (var1 * 2 >= var2) then newval = 5 + 2 * var2; else if (var1 < var2) then newval = var2 - var1 * 2; else newval = var1;Show the full question
  2. Question 1.2 · Selection: if/else and switch statements · 2 marks

    Given the input value 5 for the integer variable a, work out the value a will have after the following C++ code executes: 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; }Show the full question
  3. Question 1.3 · Selection: if/else and switch statements · 2 marks

    Consider the C++ function below: int findValue(int numberP) { int count = 0; int value = 20; while (count < numberP) { value += count; count ++; } return value; } Determine the output produced when the statement cout << findValue(3); is executed in the main function.Show the full question
  4. Question 2.1 · Code tracing and variable diagrams · 2 marks

    An example is given first: for the code `int a,b,c; cin >> a >> b >> c; cout << c + b + a;` the purpose is to input three integer values and display their sum. Using this example as a guide, state in words what each of the following code segments is designed to achieve. Given that s and n have been declared as integers, describe in words the purpose of this code segment: int s = 0; int n = 0; while (n <= 5) { s = s + n; n++; }Show the full question
  5. Question 2.2 · Code tracing and variable diagrams · 2 marks

    An example is given first: for the code `int a,b,c; cin >> a >> b >> c; cout << c + b + a;` the purpose is to input three integer values and display their sum. Using this example as a guide, state in words what each of the following code segments is designed to achieve. Describe in words the purpose of this code segment: int numbers[ ] = {11, 0, 15, 0, 16, 23}; int c = 0; for (int i = 0; i <= 5; i++) if (numbers[i] != 0) c += 1;Show the full question

The full Spot Map and the marks by year — and this paper’s scan.