0% found this document useful (0 votes)
152 views8 pages

COMP1005 Exam Sem1 2017

This document is an examination paper for the course COMP1005 Fundamentals of Programming at the end of Semester 1 in 2017. It contains instructions for students taking the closed book exam, which will last 2 hours with 10 minutes of reading time. The exam consists of 100 total marks across 17 multiple choice or short answer questions. Students are provided with an answer booklet and pen to complete the exam, but no other materials are permitted. The cover sheet provides space for the examiner to record marks for each question.

Uploaded by

muath
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)
152 views8 pages

COMP1005 Exam Sem1 2017

This document is an examination paper for the course COMP1005 Fundamentals of Programming at the end of Semester 1 in 2017. It contains instructions for students taking the closed book exam, which will last 2 hours with 10 minutes of reading time. The exam consists of 100 total marks across 17 multiple choice or short answer questions. Students are provided with an answer booklet and pen to complete the exam, but no other materials are permitted. The cover sheet provides space for the examiner to record marks for each question.

Uploaded by

muath
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/ 8

End of Semester 1, 2017

COMP1005 Fundamentals of Programming

Department of Computing

EXAMINATION
End of Semester 1, 2017

COMP1005 Fundamentals of Programming


This paper is for Bentley Campus students

This is a CLOSED BOOK examination


Examination paper IS to be released to student

Examination Duration 2 hours


For Examiner Use Only
Reading Time 10 minutes
Q Mark
Notes may be written on the exam paper by Students during reading time
1
Total Marks 100
2

Supplied by the University 3

1 x 16 page answer book 4

Supplied by the Student 5

6
Materials
7
none
8
Calculator
9
No calculators are permitted in this exam
10

Instructions to Students 11

Student to attempt all questions. Answers to be written in blue or black pen in the 12
supplied exam booklet.
13

14

15

16

17

18

Examination Cover Sheet

Total ________
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION ONE (Total: 20 marks): Datatypes and Data Handling


a) (2 marks) How would you modify bucket2.py (below) to accept both uppercase and
lowercase letters? Indicate which line numbers you are changing or inserting between.

1---- print('\nBUCKET LIST BUILDER\n')


2---- bucket = []
3---- choice = input('Enter selection: e(X)it, (A)dd, (L)ist...')
4---- while choice[0] != 'X':
5---- if choice[0] == 'A':
6---- print('Enter list item... ')
7---- newitem = input()
8---- bucket.append(newitem)
9---- elif choice[0] == 'L':
10--- for item in bucket:
11--- print(item)
12--- else:
13--- print('Invalid selection.')
14--- choice = input('Enter selection: e(X)it, (A)dd, (L)ist..')

b) (2 marks). Why do we use choice[0] in comparisons instead of choice in bucket2.py?

c) (6 marks). How would you modify bucket2.py to allow for deletion of an entry, based on
its position in the list? You should modify the prompts, and check the index is valid before
deleting. (Hint: use del bucket[x] to delete item x+1)

d) (1 mark). What would be the output of auspops.py below…

auspops.py
pops = {'New South Wales': 7757843, 'Victoria' : 6100877,
'Queensland' : 4860448, 'South Australia' : 1710804,
'Western Australia' : 2623164, 'Tasmania': 519783,
'Northern Territory' : 245657,
'Australian Capital Territory': 398349}

print(pops['Tasmania'])

e) (4 marks). Provide code to modify auspops.py to print out each state and population on a
separate line and then print the total population

QUESTION ONE continues on the next page…

Page 1 of 7
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION ONE (Total: 20 marks): …continued…

f) (2 marks). What would the output of the program regtest.py be if it was given the input file
phone.txt.

regtest.py phone.txt

import re +61 8 9266 1000


(08) 9266 1000
phoneRegex = re.compile(r'''( (08) 92661000
(\d{2}|\(\d{2}\)) 08 9266 1000
(\s|\.)? 08 92661000
(\d{4}\s\d{4}) 92661000
)''', re.VERBOSE)

fileobj = open('phone.txt')
data = fileobj.readlines()

for number in data:


number = number.strip()
mo = phoneRegex.search(number)
if mo:
print(number + ' found ' + mo.group())

g) (3 marks). Provide three changes that would be required for regtest.py to completely
and specifically match each of the number formats in the file.

Page 2 of 7
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION TWO (Total: 25 marks): Arrays, Grids and Plotting

a) (6 marks) The program below, prettyface.py, displays an image of a critter. Write some
additional code to:

i) create a new image, cropped_face, which crops the image by 100 pixels
on each side, and display the new image

ii) create a new image, pixel_face, which slices the image show every 20th
pixel, and display the new image

prettyface.py
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy import misc
face = misc.face(gray=True)
plt.imshow(face, cmap=plt.cm.gray)
plt.show()

b) (8 marks). What would be the output of the following code, resizeme.py?

resizeme.py
import numpy as np

data = np.zeros((2,2,2))

data[0,1,0] = 1
data[1,0,1] = 2

print(data)

data.resize(1,8)
print(data)

c) (4 marks). Gridding algorithms use neighbouring cells to calculate the next value for the
site (centre cell). With a diagram, show the difference between von Neumann
neighbourhoods and Moore neighbourhoods

QUESTION TWO continues on the next page…

Page 3 of 7
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION TWO (Total: 25 marks): …continued…

d) (7 marks). The following code creates three arrays: t, t2 and t3. Modify the code to:

• plot t as red triangles


• plot t2 as green squares
• plot t3 as black dashes
• add a title "Multiline Plot"

multilineplot.py
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0., 5., 0.2)


t2 = t**2
t3 = t**3

plt.plot(t, t, t, t2, t, t3)


plt.show()

Page 4 of 7
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION THREE (Total: 20 marks): Structured Data

a) (4 marks) List two (2) benefits of using Pandas tables as compared to using numpy
arrays.

b) (10 marks). Describe what each line of the following code, weather.py, does - given the
input file march4.csv.

weather.py march4.csv
import matplotlib.pyplot as plt "Minimum temperature (C)",
import pandas as pd "Maximum temperature (C)","9am
Temperature (C)","3pm Temperature
df = pd.read_csv('march4.csv') (C)"
20.1,37.7,28.2,37.2
print(df.head()) 22.9,29.9,24.1,25.1
print(df.tail()) 20.3,35.2,26.5,32.6
print(df.describe()) […]
12.9,24.9,16.9,24.3
plt.figure() 12.1,28.0,18.6,27.5
df.plot() 9.6,29.9,20.7,29.5
plt.show()

c) (6 marks). The following revised weather.py code adds a new column, temprange.
Provide code to:

i) print the values in the new column (2 marks)


ii) give descriptive information for the new column (2 marks)
iii) plot only the new column's data (2 marks)

import matplotlib.pyplot as plt


import pandas as pd

df = pd.read_csv('march4.csv')
df = df.assign(temprange = df['Maximum temperature (C)'] -
df['Minimum temperature (C)'])

plt.figure()
df.plot()
plt.show()

Page 5 of 7
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION FOUR (Total: 15 marks): Scripting and Automation

a) (2 marks) Define the term parameter sweep.

b) (4 marks) Provide an example of where a parameter sweep could be used (2 marks).


Describe the role of the driver and the base code in the parameter sweep for your chosen
example (2 marks).

c) (4 marks). Given the following script, myexp.sh, called as: bash myexp.sh exp1

…List the contents of exp1 and all subdirectories.

myexp.sh
#!/bin/bash

mkdir $1
cd $1
cp ~/code/hello.py .
mkdir output

python3 hello.py > output/out.txt

d) (5 marks) What is the output of the following code, commandline.py, when called as:

python3 commandline.py commandline.py 4

commandline.py
import sys

print(sys.argv)

fileobj = open(sys.argv[1])

numlines = int(sys.argv[2])

for i in range(numlines):
line = fileobj.readline().strip()
print('Line ' + str(i) + ' is: ' + line)

Page 6 of 7
End of Semester 1, 2017
COMP1005 Fundamentals of Programming

QUESTION FIVE (Total: 20 marks): Objects and Sharing

a) (14 marks). The following questions relate to the BankAccount class below:

class BankAccount (object):


interest_rate = 0.3
def __init__(self, name, number, balance):
self.name = name
self.number = number
self.balance = balance
return

i) (4 marks) Identify and name the included class variables and instance
variables. Indicate if they are class or instance variables.

ii) (7 marks) Add two (2) instance methods called deposit() and
withdraw() which increase and decrease the balance of the account.
Make sure the withdraw() method doesn't allow the class to go into
overdraft.

iii) (3 marks) Add another method called add_interest() to add interest to


the balance of the account. The interest amount is the interest rate
multiplied by the balance on the account.

b) (6 marks). Two approaches to sharing code are publishing notebooks and publishing
packages. Describe each approach (4 marks) and the situations each is suited to (2
marks).

END OF EXAMINATION

Page 7 of 7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy