Wentworth Institute of Higher Education Final Examination BIM114: Programming Fundamentals
Wentworth Institute of Higher Education Final Examination BIM114: Programming Fundamentals
FINAL EXAMINATION
BIM114: Programming Fundamentals
Semester 3, 2020/21
Total Marks: 40
EXAMINATION RULES
Exam Conditions: 1. Do not detach any
portion of the
This is a THEORY examination examination paper.
Mobile phones
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)
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
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
root = Tk()
e1 = Entry(root)
e1.insert(0, 'Name please')
e1.grid(row=0, column=1)
save = IntVar()
check.grid(row=1, column = 0)
subopt = IntVar()
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()
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