Final Exam 2018
Final Exam 2018
Instructions to Candidate:
[6 marks]
e) Given the following code, what is the final value of i? Explain Your answer.
int i, j;
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{
if(i==2)
break; }
}
[4 marks]
Question 2
b) Write a C++ program that reads in 5 scores into an array and finds the product of
each score with the minimum score. [14 marks]
Page 2 of 5
Question 3
b) What will the following program segment do? Explain your answer. [4 marks]
c) Write a program that sums even numbers between 2 and 20. [8 marks]
Question 4
a) List and explain any two ways to pass arguments to parameters in a function.
[4 marks]
b) What is the output of the following code fragments? Explain your answer.
[3 marks]
int trial (int a, int b)
{
if (b > a)
{
a=b;
return –a;}
else
{
return 0;}
}
Page 3 of 5
Question 5
a) Using an example, explain how the bool data type is used in C++ to manipulate
Boolean expressions. [3 marks]
b) Explain the difference between the (= =) operator and the (=) Operator as used in
C++ programming language. [4 marks]
c) What is the output of the following C++ code? Explain your answer. [5 marks]
int x = 55;
int y = 5;
switch (x % 7)
{
case 0:
case 1:
y++;
case 2:
case 3:
y = y + 2;
case 4:
break;
case 5:
case 6:
y = y – 3;
}
cout << y << endl;
d) Write a C++ program that outputs amount of income tax due, computed as
follows:
1. No tax on income up to P15,000
2. 5% on income between P15,001 to P25,000
3. 10% on income over P25,000 [8 marks]
Page 4 of 5
Question 6
a) State and explain any THREE access modifiers that define visibility of class
members (data members and member functions). [6 marks]
b) Write a C++ program for the Class diagram depicted in figure 1. [14 marks]
Page 5 of 5