lOMoAR cPSD| 48680473
Downloaded by Vincent kyalo ()
, lOMoAR cPSD| 48680473
Downloaded by Vincent kyalo ()
, lOMoAR cPSD| 48680473
Oct/Nov 2021
75 Marks
This examination question paper consists of 9 pages.
INSTRUCTIONS:
Use word Document to answer the
questions Convert to PDF before
submitting
Marks are awarded for part of an answer, so do whatever you are
able to in each question. This exam is IRIS invigilated. Please
make sure you use IRIS.
ALL THE BEST!
Downloaded by Vincent kyalo ()
, lOMoAR cPSD| 48680473
2 COS1511
Oct/Nov 2021
[TURN OVER]
QUESTION 1
6 MARKS
1.1 Consider the C++ code segment below. What value will
newvalhave after this code has been executed?
(2)
int var1 = 4; int var2 =
10; int newval = 0; if
(var1 * 2 >= var2)
newval = 5 + 2 * var2;
else if (var1 < var2) newval
= var2 - var1 * 2;
else newval =
var1;
1.2 Suppose the input value for a is 5. What is the value of a after
the following C++ code has been executed?
(2)
int a; cin
>> a;
switch
(a)
[TURN OVER]
Downloaded by Vincent kyalo ()
Downloaded by Vincent kyalo ()
, lOMoAR cPSD| 48680473
Downloaded by Vincent kyalo ()
, lOMoAR cPSD| 48680473
Oct/Nov 2021
75 Marks
This examination question paper consists of 9 pages.
INSTRUCTIONS:
Use word Document to answer the
questions Convert to PDF before
submitting
Marks are awarded for part of an answer, so do whatever you are
able to in each question. This exam is IRIS invigilated. Please
make sure you use IRIS.
ALL THE BEST!
Downloaded by Vincent kyalo ()
, lOMoAR cPSD| 48680473
2 COS1511
Oct/Nov 2021
[TURN OVER]
QUESTION 1
6 MARKS
1.1 Consider the C++ code segment below. What value will
newvalhave after this code has been executed?
(2)
int var1 = 4; int var2 =
10; int newval = 0; if
(var1 * 2 >= var2)
newval = 5 + 2 * var2;
else if (var1 < var2) newval
= var2 - var1 * 2;
else newval =
var1;
1.2 Suppose the input value for a is 5. What is the value of a after
the following C++ code has been executed?
(2)
int a; cin
>> a;
switch
(a)
[TURN OVER]
Downloaded by Vincent kyalo ()