0% found this document useful (0 votes)
4 views6 pages

B3 Classwork Question Paper

The document is an assessment for Year 1 IBDP Computer Science focusing on Object-Oriented Programming (OOP) concepts. It includes sections on key terms, class design, UML diagrams, static vs. instance variables, encapsulation, and applying OOP with data structures. The assessment requires students to answer questions, design classes, and write code related to various programming scenarios.
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)
4 views6 pages

B3 Classwork Question Paper

The document is an assessment for Year 1 IBDP Computer Science focusing on Object-Oriented Programming (OOP) concepts. It includes sections on key terms, class design, UML diagrams, static vs. instance variables, encapsulation, and applying OOP with data structures. The assessment requires students to answer questions, design classes, and write code related to various programming scenarios.
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

IBDP Computer Science | Year 1 B3.

1 Object-Oriented Programming — Topic Assessment

B3.1 OBJECT-ORIENTED PROGRAMMING


Topic Assessment — Fundamentals of OOP for a Single Class

SECTION A — Key Terms & Concepts (Short Answer)


Answer all questions in this section in the space provided.

1. Define the term “class”. [2]

2. Define the term “object” and explain how it differs from a class. [2]

3. Define the term “instantiation”. [2]

4. Define the term “encapsulation”. [2]

5. Distinguish between a static variable and an instance (non-static) variable. [2]

SECTION B — Class Design & UML Diagrams

A courier company wants to track parcels as they move through its delivery network. Each parcel
has a tracking number, the sender's name, the recipient's name, its weight in kilograms, and
whether it has been delivered.

6. Refer to the scenario above.


(a) Identify four attributes and two behaviours (methods) appropriate for a Parcel class based on this
scenario. [3]

Page 1 of 6
IBDP Computer Science | Year 1 B3.1 Object-Oriented Programming — Topic Assessment

(b) Construct a UML class diagram for the Parcel class. Your diagram must use correct modifier notation
and appropriate data types for the instance variables, and include suitable accessor/mutator methods. [6]

7. Evaluate whether OOP would be a suitable programming paradigm for developing a parcel-tracking
system. Justify your answer with two points. [4]

SECTION C — Static vs. Instance Variables & Constructing Code

A cinema wants a Screening class to represent each screening of a film. Each screening has a film
title, a screen number, and a start time.
The cinema also wants to keep a running total of the number of tickets sold across ALL screenings,
accessible without referring to any single screening.

9. Refer to the scenario above.


(a) Identify which variable in this scenario should be static, and explain why. [2]

(b) State one difference in how a static (class) variable and an instance variable are declared in Python. [2]

10. Construct Python code for the constructor (__init__) method of the Screening class, including the
instance variables filmTitle, screenNumber and startTime. [5]

Page 2 of 6
IBDP Computer Science | Year 1 B3.1 Object-Oriented Programming — Topic Assessment

11. Every Screening object has access to a method sellTicket(), which increases the static ticket counter by
1 each time it is called. Explain why calling sellTicket() on one Screening object affects the value returned
when the static counter is accessed via a completely different Screening object. [3]

12. Three Screening objects are created. sellTicket() is then called 2 times on the first screening, 5 times on
the second, and 3 times on the third.
(a) State the value that would be returned by a call to the static method getTotalTicketsSold(). [2]

(b) Explain what would go wrong if the ticket counter had instead been declared as an instance variable
rather than a static variable. [2]

SECTION D — Encapsulation & Information Hiding

A company pays each employee a base salary plus a bonus. The bonus calculation must not be
altered directly by other parts of the program — it should only ever be updated through the class's
own method.

13. Explain what is meant by “information hiding” in the context of this scenario. [2]

14. A junior developer writes the Employee class with all instance variables declared as public. Explain two
problems this could cause. [4]

Page 3 of 6
IBDP Computer Science | Year 1 B3.1 Object-Oriented Programming — Topic Assessment

15. State the appropriate Python naming convention (e.g. __variable, _variable, or variable) for each of the
following, and justify one of your answers. [3]

Class member Naming convention

(a) the baseSalary instance variable

(b) a calculateBonus() method used only internally within the class

(c) a getSalary() accessor method

16. Explain how encapsulation improves the maintainability of code. [3]

Page 4 of 6
IBDP Computer Science | Year 1 B3.1 Object-Oriented Programming — Topic Assessment

SECTION E — Applying OOP with Data Structures

A podcast app stores podcast episodes in a dynamic list. Each Episode object has a title, a host
name, and a duration in minutes.
The list, episodeList, currently contains the following four Episode objects:

Title Host Duration (min)

Coding Basics Amara 45

Deep Space Priya 62

Coding Basics Part 2 Amara 38

History Hour Devon 71

17. Refer to the scenario above.


(a) State the Python code needed to create an empty dynamic list called episodeList to store Episode
objects. [1]

(b) State the Python code needed to add a new Episode object to episodeList. [2]

18. A developer writes the following code to find the longest episode hosted by a given person.

longestTitle = ""
maxDuration = 0
for i in range(len(episodeList)):
if (episodeList[i].getHost() == "Amara" and
episodeList[i].getDuration() > maxDuration):
maxDuration = episodeList[i].getDuration()
longestTitle = episodeList[i].getTitle()
print(longestTitle + ", " + str(maxDuration))

(a) Using the episode data given above, state the exact output produced when this code is run. [4]

(b) Explain why episodeList[i].getHost() == "Amara" correctly compares string values, but writing
episodeOne == episodeTwo to compare two Episode objects directly would not check whether their
attributes are equal, unless the class defines special behaviour for this. [1]

Page 5 of 6
IBDP Computer Science | Year 1 B3.1 Object-Oriented Programming — Topic Assessment

19. The following code is intended to sort episodeList alphabetically by title using a bubble sort, but it
contains one error.

for i in range(len(episodeList) - 1):


for j in range(len(episodeList) - i - 1):
if episodeList[j].getTitle() > episodeList[j + 1].getTitle():
episodeList[j] = episodeList[j + 1]
episodeList[j + 1] = episodeList[j]

(a) Identify the error in this code. [1]

(b) Explain how the code should be corrected so that it performs a complete, correct swap of the two
Episode objects. [3]

20. In Python, a list of integers or strings can be sorted directly using comparison operators such as > or the
built-in sort() function. Explain why sorting a list of Episode objects by title still requires you to access an
attribute (e.g. via .getTitle() or a key function) rather than comparing the Episode objects directly. [4]

Page 6 of 6

You might also like