You are on page 1of 4

UNIVERSITY OF ZIMBABWE

2018 November/December Examinations

Faculty : Engineering
Department : Electrical Engineering
Paper Code and Title : EE103, Computer Science For Engineers
Duration : 3 Hrs
Examiner : Dr. T. Marisa

Authorized Materials : Scientific Calculator (Non-programmable),


pen, pencil, rule, Mathematical instruments

Instructions :
1. This paper contains Seven (7) questions
2. Answer Five (5) questions
3. Start each question on a new page
4. This question paper comprises 4 printed pages
5. DO NOT TURN OVER THE QUESTION PAPER OR COMMENCE WRIT-
TING UNTIL INSTRUCTED.
Question 1

(a) Describe the concept of inheritance as applied to object oriented programing. [3]
(b) Solve the following bit wise operations [3]
(i) 10101 & 10001
(ii) 10101 | 00010
(ii) 10101 ˆ 01010
(c) What is the output of the following program [4]
✞ ☎
1 def printNext ( x ) :
2 print (( x + 1) % 3) ;
3
4 def printSequence ( y ) :
5 for i in range (0 ,y ,2) :
6 printNext ( i )
7

8 printSequence (8)
9
✝ ✆

(d) Write a program that will print the smallest of 3 numbers entered by the user, your [4]
program should be able to handle errors and allow the user to re-enter the record
when invalid numbers are entered.
(e) Write a function that takes two parameters, a list of integers and a single integer, [6]
and returns a list containing all the values in the parameter list that are exactly
divisible by the second integer parameter. The returned list must be sorted.
Total for Q.1: 20 marks

Question 2

(a) Using an example describe the concept of encapsulation as applied to object oriented [4]
programing.
(b) Using generators and recursive functions write a program which implements the [8]
Pascal’s triangle:
✞ ☎
1 1
2 1 1
3 1 2 1
4 1 3 3 1
5 1 4 6 4 1
6 1 5 10 10 5 1
7
✝ ✆

(c) Using list comprehensions, write a program to print each of the following:
i. x2 : x is a natural number less than 200 and x is a multiple of 3 and 4 [4]
ii. x: x is a whole number less than 100, x is even and also not divisible by 6 [4]

Page 1 of 3
Total for Q.2: 20 marks

Question 3

(a) What is the difference between list and tuples? [3]


(b) You are working for an engineering research and development company, you have
been tasked to develop a program that solves first order differential equations.
i. Your program must solve the differential equation of the form: [5]

dy
= e−2t − y, y(0) = 1.
dt
ii. Your program must use sympy to provide a symbolic solution of the equation [3]
and also a numerical solution.
iii. Plot the values of y vs t for the ranges of t=0 to t=1.0 and y=0.7 to y=1.05. [4]
iv. Your program must calculate the value y at any value of t entered by the user. [5]
Hint:Use sympy’s lambdify to find y at a particular value of y.
Total for Q.3: 20 marks

Question 4

(a) Define embedded computers and give two applications of embedded computers. [3]
(b) Using a recursive function, create a program which will convert a given integer to [7]
its binary equivalent. Your program should run continuously and not terminate
after converting a number. Your program must handle invalid inputs.
(c) Define a class called Time which has two integer data fields hour and minute, and [10]
a double data field, second. The class has one constructor with three appropriate
parameters, and also two methods, isNow and isAfter. Both methods should have
one parameter time of type Time. The method isNow should return True if a Time
object is equal to time and False otherwise. The method isAfter should return True
if a Time object is after time and False otherwise.
Total for Q.4: 20 marks

Question 5

(a) Give five types of errors that can be indicated by the Python interpreter and explain [5]
their meaning.
(b) Write a function that takes two arguments : an integer, and a list of integers, and [4]
returns a list containing all the values in the given list that are exactly divisible by
the first integer parameter. The returned list should not have any empty elements.
(c) Write a function that takes one argument : an integer, and returns the square root [11]
of the number. Your function must use the bisection method.

Page 2 of 3
Total for Q.5: 20 marks

Question 6

(a) You are working in a team developing a structural engineering application for local [8]
authority. The application makes extensive use of the Pythagorean Theorem which
says that if a and b are the lengths of two edges of a right triangle, then the length
of the hypotenuse c is given by:

c2 = b2 + a2

Write a Python application which gets the lengths of two edges of a right trian-
gle from the command prompt and then computes and prints the length of the
hypotenuse. Hint: Your program must handle invalid number entries.
(b) You are are working in a team whose goal is to improve weather predictions. Develop [12]
a program to process past temperature measurements. The measurements are in a
2 column, comma separated value file with the first row being column titles. Write
a program that reads in all the data in the file and then plots the data taking the
first column as the x-axis and the second column as the y-axis. Your program must
prompt the user for the file path and handle invalid file paths.
Total for Q.6: 20 marks

Question 7

(a) In an operating system, describe the kernel and give three operations done by the [4]
kernel.
(b) Rewrite the following while loop as the equivalent for loop. [4]
✞ ☎
1 i =1
2 while ( i <= 35) :
3 if (( i %10) ==0) :
4 print ( i )
5 i +=1
6
✝ ✆

(c) Write a python function avgOfSquares(n) that returns the average of the squares [6]
of the integers from 1 to n inclusive. You may assume that n is at least 1. For
example, the function call avgOfSquares(4) returns 7.5, as (1+22 +32 +42 )/4 = 7.5.
(d) Write a recursive Python function that returns the sum of the first n integers. [6]
Total for Q.7: 20 marks

End of Exam
Page 3 of 3

You might also like