Get premium membership and access revision papers, questions with answers as well as video lessons.
Got a question or eager to learn? Discover limitless learning on WhatsApp now - Start Now!

Bcom 270: Computer Programming Question Paper

Bcom 270: Computer Programming 

Course:Bachelor Of Commerce

Institution: Chuka University question papers

Exam Year:2013



Exam Year:2013
CHUKA
UNIVERSITY
UNIVERSITY EXAMINATIONS
SECOND YEAR EXAMINATION FOR THE
AWARD OF
DEGREE OF BACHELOR OF COMMERCE
BCOM 270: COMPUTER PROGRAMMING
STREAM: BCOM Y2S1 TIME: 2 HOURS
DAY/DATE: MONDAY 12/8/2013 2.30 P.M –
4.30 P.M.
INSTRUCTIONS:
i. Answer QUESTION 1 in section A and any
other TWO QUESTIONS from section
B.
ii. This is a CLOSED BOOK EXAM, No
reference materials allowed in
examination room. Make sure such materials
are not found anywhere near your
sitting.
iii. No use of mobile phones, no electronic
calculators, no memory watches.
iv. Do not write on this Question Paper; Use
your answer booklet for all
your works.
v. Write your answers legibly and use your
time wisely.
SECTION A: COMPULSORY
1. Consider the following code in Object
Oriented Programming. It defines
the start of a class to represent bank
accounts:
Class Bank Account(object):
interest rate = 0.3
def __init__(self, name, number, balance):
self.name = name
self. number = number
self. Balance = balance
return
(a) Name all the class variables and the
instance variables in the given
code. [10 marks]
(b) Add instance methods called deposit ()
and withdraw () which increase
and decrease the balance of the account.
Make sure the withdraw () method
doesn''t allow the account to go into
overdraft. Add a third method called
add interest () which adds interest to the
balance (the interest should be
the interest rate multiplied by the current
balance). [10 marks]
(c) Create a subclass of Bank Account called
Student Account. Every Student
Account should have an overdraft limit of
1000. Write a constructor for the
new class. Override the withdraw () method to
make sure that students can
withdraw money up to their overdraft limits.
[10 marks]
SECTION B: ANSWER ONLY TWO QUESTIONS
FROM THIS SECTION
QUESTION 2[MARKS 20MKS]
A palindromic word is one that reads the
same backwards as forwards. Hence
the words hello and peel are not palindromes,
but the words peep, deed and
dad are palindromes.
(a) Create a class called Palindrome. [2
marks]
(b) In your Palindrome class, create a method
called reverse () which takes
a string argument. Your method should return
the reverse of the argument as
a string. For example, if the argument is
_Foobar_ then your method should
return _rabooF_. [8 marks]
(c) Create a second method in Palindrome
called is Palindrome () which
takes a string argument. This method should
return true if the argument is
a palindrome and False otherwise. [10 marks]
HINT: Probably the easiest way to do this is
to use the result of your
reverse () method and compare the string
against its reverse.
(d) Write some code to test your new
Palindrome class and print out results
of your testing to the user. Give some
consideration to what sort of
strings you might want to use for your testing.
[10 marks]
QUESTION 3 [20MKS]
By use of control constructs, demonstrates
how the following would be
achieved.
(a) A program to sum the number of integers
from 1 to a given number n. [4
marks]
(b) A program which sums the contents of a
integer list or array. [4 marks]
(c) Translate the following for loop into a
while loop (which does the same
thing as the for loop):
for i in range(1,10):
print "i = ", I [8 marks]
(d) Translate the following while loop into a
for loop (which does the same
thing as the while loop):
i = 20
while (i > 0):
print "i = ", i
i =- 1 [4 marks]
QUESTION 4 [20 MARKS]
(a) What differentiates a function from a
procedure? Illustrate. [4 marks]
(b) Explain how a function or a procedure
simplifies the task of
programming. [6 marks]
(c) Write a program that uses a function to
calculate the area of a circle.
[10 marks]
QUESTION 5 [20 MARKS]
(a) What is a recursive function? [2 marks]
(b) The following iterative function returns the
sum of all elements in a
list. For example, given the list [1, 2, 3] the
function will return 1 + 2
+ 3 or 6. Re-write the function as a recursive
function.
def sum(arg):
result = 0
for i in arg:
result += i
return result [10 marks]
c) The following code implements a recursive
function in Python called
foobar. What does the foobar function do?
Write a line of code which calls
the foobar function with a suitable argument
and state what the return
value will be.
def foobar(arg):
if arg == []:
return arg
else:
return foobar(arg[1:]) + [ arg[0] ]
[8 marks]






More Question Papers


Popular Exams



Return to Question Papers