WENTWORTH INSTITUTE OF HIGHER EDUCATION
FINAL EXAMINATION
BIM114: Programming Fundamentals
Semester 3, 2020/21
Examination Duration: 180 minutes
Total Marks: 40
EXAMINATION RULES
Exam Conditions: 1. Do not detach any
portion of the
This is a THEORY examination examination paper.
This is a CLOSED BOOK examination 2. Listen for all
instructions from
venue supervisors.
Materials Required in The Exam:
3. Do not begin writing
Laptop computer with internet access, working webcam and until reading time has
ended.
microphone
4. Ensure that you print
Internet, camera, and microphone MUST be switched ON at all your name and student
times. number on all exam
papers, answer
booklets and multiple
Not permitted in the exam: choice sheets.
Mobile phones
Permitted in the exam: None
Instructions To Students:
Answer ALL questions.
DO NOT REMOVE ANY PART OF THIS PAPER FROM THE EXAM ROOM.
EXAM COMMENCES NEXT PAGE
Section-01: Procedural Programming (10 Marks)
a. Python has three different types of functions: built-in functions, library functions, and user
defined functions. Explain them with minimum of two examples each. (4 Marks)
Built-in functions:
print(‘hello world’)
abs(a)
dir(file)
library functions:
import tkinter as tk
tk.TK()
from tkinter import *
root = TK()
import math
math.sqrt(x)
user defined functions:
def hello():
a = ‘helloworld’
def add2(x):
return x+2
b. Fill in the blanks in the following code. Line Numbers: 14,17,18,21,22, and 27 must be
completed. (6X1 = 6 Marks)
14
inputNumber = int(input(‘Input a number:’))
17
If inputNumber > largest
18
largest = inputNumber
21
if inputNumber < smallest
22
smallest = inputNumber
27
average = total/10
Figure 1: Fill in the blanks.py
Section-02: Logic (10 Marks)
a. Explain Definite Loops and indefinite loops in python. Give one example each. (5 Marks)
Definite loops have clear defined loop boundaries in their declaration, so that the number of runs they
loop through are specified explicitly, for example:
for t in range(0,5):
where the loop’s boundary is from 0 to 5, unexclusively
Indefinite loops do not explicitly specify the number of times it will execute, rather taking some
condition that needs to be fulfilled as a stop sign, for example:
while a==b:
however, as indefinite it is, we can also write something like this:
while True:
b. Write pseudocode and program structure for the problem given below; (5 Marks)
Problem: A program is required to open a file “students.txt” in read mode. Read data from the file line
by line and print it on the screen. Once all the data is printed the file must be closed.
Note: You do not have to write the program. Only pseudocode and program structure needed.
Pseudocode:
1. Define a file pointer
2. Open the file to Read in reading mode
3. For a line in the file:
a. Read the line
b. print each line
4. Close file pointer
Program Structure:
# open students file for reading
# definite loop loop through all lines
# read the file a line at a time
# print each line
# close file
Section-03: Event-Driven Programming (10 Marks)
a. What Is a widget. Explain Checkbox and radio box widgets. (4 Marks)
Checkbox supports multiple selects. With checkboxes users can select on/off for each one and have
multiple of them.
Radio boxes are also on/off selects but users can only make one choice from different options.
b. Write a program using TKInter widgets. When run the output window should look like the tkWindow
shown below. (6 Marks)
Figure 2: tkWindow Output
from tkinter import *
root = Tk()
Label(root, text="Entry your name").grid(row=0)
e1 = Entry(root)
e1.insert(0, 'Name please')
e1.grid(row=0, column=1)
save = IntVar()
check = Checkbutton(root, text="I am a current student", var=save)
check.grid(row=1, column = 0)
subopt = IntVar()
its3 = Radiobutton(text='ITS113', var = subopt, value = 1)
its4 = Radiobutton(text='ITS114', var = subopt, value = 2)
its5 = Radiobutton(text='ITS115', var = subopt, value = 3)
its3.grid(row=2, column=0)
its4.grid(row=2, column=1)
its5.grid(row=2, column=2)
okButton = Button(text='OK')
okButton.grid(row=3, column=1)
if __name__ == '__main__':
root.mainloop()
Section-04: Object Oriented Programming (10 Marks)
a. Explain 3 principles: Encapsulation, Inheritance, and Polymorphism, of OOP (3 Marks)
The encapsulation hides the implementation details of a class from other objects.
The inheritance is a way to form new classes using classes that have already been defined.
The polymorphism is the process of using an operator or function in different ways for different data
input.
b. A class named Books has been created as shown in the next page.
Using that class
i. Create an instance “S1” with ISBN: 0001, Title: introduction to Python, Author: Your name.
S1 = Book(‘0001’,’introduction to Python’,’Your name’)
ii. Create another instance “S2” ISBN:0002, Title: Introduction to MySQL, Author: my name. S2
= Book(‘0002’,’introduction to MySQL’,’my name’)
iii. Display both the instances.
S1.displayBook()
S2.displayBook()
iv. Change instance ‘S1’ Author to ‘Rossum’.
S1.setAuthor(‘Rossum’)
v. Change instance ‘S2’ ISBN to ‘1234567890’
S2.setIsbn(‘1234567890’)
vi. Change instance ‘S2’ Author to ‘Yue Zhang’.
S2.setAuthor(‘Yue Zhang’)
vii. Change instance ‘S2’ title to ‘An introduction to python and computer programming’.
S2.setTitle(‘An introduction to python and computer programming’)
(7 Marks)
Figure 3:Class Book Definition
End of the paper