Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit 

SAIBT

SAMPLE EXAMINATION

COMP 1046 Object-Oriented Programming

PART 1: SHORT ANSWER QUESTIONS. Total 40 marks.

Five short answer questions. 8 marks for each question.

1. Class definition (8 marks): Write Python code to implement the class in the following UML diagram:


Include an initialization method. No testing of the datatype is required. Only the method skeleton is required. No code inside the methods is needed.

2. UML Relationship (8 marks): Describe the relationship in the diagram between classes Building and FamilyHouse:

Name the relationship and explain in your own words the meaning of it. Explain how a FamilyHouse object can access the attributes rooms and size specified in the Building class.

3. Iterator Pattern (8 marks):
Given is the following class EventsIterable in a UML diagram.

 

Extend the UML class diagram with an iterator class. Specify in the diagram which attributes and/or methods need to be implemented so the following code works in Python.

events = EventsIterable([“Easter”, “Halloween”, “Christmas”],[“12/04/2020”, “31/10/2020”, “25/12/2020”])

for e in events

print(e)

4. Data Structures (8 marks):
Given are the following two sets of TV shows:
tv_shows1={"Stranger Things", "Discovery", "Mandalorian", "Utopia", "Black Mirror"}
tv_shows2={"Picard", "Stranger Things", "Dark",  "Utopia", "Knight Rider"}
Write down the resultings sets x, y, and z of the following code and explain each operator in a single sentence:
x=tv_shows1.union(tv_shows2)
y=tv_shows1.intersection(tv_shows2)
z=tv_shows1.symmetric_difference(tv_shows2)

5. Testing (8 marks): Explain the output of unittest on stdout.

.F

============================================================

FAIL: test_str_float (__main__.CheckNumbers)

--------------------------------------------------------------

Traceback (most recent call last):

   File "first_unittest.py", line 9, in test_str_float

      self.assertEqual(1, "1")

AssertionError: 1 != '1'

--------------------------------------------------------------

Ran 2 tests in 0.001s

FAILED (failures=1)

Explain the output of the unittest:

How many tests have been performed? What kind of tests have been performed? Did the tests pass or not? What was the expected value in each test?

PART 2: OO DESIGN. Total 30 marks.

Design a UML Class Diagram for a student enrollement system. The system should cover the following requirements:

· Student

· Course

· Class

· Practical

· Workshop

· Tutorial

· Enrollment

A student has a student id, name, address and contact phone number.

A student is able to enrol into a course.

A student is able to enrol into a class of course. The class can be a practical, workshop or tutorial.

Each class has a weekday, time and room number.

Each class has a maximum capacity.

Students can also unenroll from a class and a course.

The diagram should include classes, attributes and methods in classes, and relationships between classes.

Attributes must contain datatypes. The exact names from the requirements above should be used to name the classes and attributes.

All classes must be related to at least one other class. All relationships except inheritance must contain a label and cardinalities.

Methods must contain parameters if applicable and a return type.

PART 3: OO Programming. Total 30 marks.

Implement the following UML class diagram in Python 3. It represents a library management system.

 

· Implement all classes by declaring the classes, creating initialisation methods and attributes.

· Implement the composition and association relationship by attributes and methods in the appropriate classes to establish the relationship between the objects of related classes.