Programming Tutorials - First Test
Programming Tutorials - First Test
FIRST TEST
Instructions: Answer All Questions Duration: 2 Hours
6. Modify the following program so it prints two blank lines between each line of text. Be sure to
correct the syntax errors as well. [3 Marks]
$include <iostream.h>
using name spacestd;
int main
{
cout << ‘Two mandolins like creatures in the’;
cout << "dark";
cout << "Creating the agony of ecstasy.";
cout << " - George Barker";
reverse 0;
}
7. Why is variable initialization important? [1 Mark]
QUESTION 2 (20 MARKS)
8. Evaluate the following [2 Marks]
i. y = (7/3 + 10%5)
ii. y = (20 >= 7 + 7 && 5 == 6 || 6 != 4)
9. Show what the following expressions evaluate to when you assume
x = 6 and y = 2. [4 Marks]
i. ! (x > 2)
ii. x > y) && (y > 0)
iii. (x < y) && (y > 0)
iv. (x < y) || (y > 0)
10. Convert the following into C++ expressions. [4 Marks]
𝐴+2𝑘 4
i. 𝑏= 𝑚3
ii. 𝑣 = √ 𝑢2 + 2𝑎𝑑
√ 𝑏 2 +𝑐 2
iii. 𝑥= 2𝑚
𝑦2 +3
iv. 𝑏= 𝑏3
11. Let z = 10, x = 15 and y = 15. Evaluate the following expressions. [3 Marks]
i. 13 % 6 > 14 % 6 && !(14 - 4) == z || x % y == x
ii. !(y == x) || (z > 100)
iii. x != y && z >= y || x == y && y > x