0% found this document useful (0 votes)
25 views5 pages

Final Exam 2018

final exam

Uploaded by

aaschlysebakiso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

Final Exam 2018

final exam

Uploaded by

aaschlysebakiso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIVERSITY OF BOTSWANA

FACULTY OF ENGINEERING AND TECHNOLOGY


DEPARTMENT OF ELECTRICAL & ELECTRONIC ENGINEERING

Title of Examination Computer Programming

Programme Bachelor of Engineering

Course Code EEB315

Maximum Marks 100

Time Allowed 2 Hours

Date December 2018

Instructions to Candidate:

1. Answer ANY FIVE (5) of the SIX questions.


2. Each question carries a maximum of 20 marks.
3. Write your I.D. number on all sheets used and insert them into the answer
book.

This examination paper contains 5 pages, including this Cover page.


Question 1

a) Explain the two different ways to comment a program in C++? [4 marks]


b) Suppose that sum and num are int variables and sum = 5 and num = 10. What will
be the value in sum after the statement sum += num executes? [2 marks]
c) Explain why the use of functions is important in programming [4 marks]
d) Write a C++ program that calculates the Future Value (FV), given the formula as
shown below

[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

a) List and explain any three types of program errors [6 marks]

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

a) Explain the following terms used in C++ programming [8 marks]


i. Compilation
ii. Variable Declaration
iii. Scope resolution operator
iv. Debugging

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;}
}

float x=0, y=10, z;


z=trial(y,x);
cout << z << endl;

c) Define a function hypotenuse that calculates the hypotenuse of a right triangle


when the other two sides are given. The function should take two double
arguments and return the hypotenuse as a double. Use this function in a program
to determine the hypotenuse of a triangle. [13 marks]

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]

Figure 1 Circle Class Diagram

End of Examination Paper

Page 5 of 5

You might also like