Practice D.2 Features of OOP with authentic IB Computer Science (CS) exam questions for both SL and HL students. This question bank mirrors Paper 1, 2, 3 structure, covering key topics like programming concepts, algorithms, and data structures. Get instant solutions, detailed explanations, and build exam confidence with questions in the style of IB examiners.
A smartphone app is being developed to manage tasks and reminders. The app uses classes such as Task, Reminder, and Event, which inherit from a base class ScheduleItem.
Define the term polymorphism.
Explain one advantage of polymorphism in this app.
Describe two advantages of using libraries of objects in the development of this app.
A generic Event class is defined as follows:
class Event
{
private String eventID;
private int numberOfRaces;
private Race$$ races;
private Race finals;
public Event(String ID, int numberOfRaces)
{
eventID = ID;
races = new Race;
for(int i = 0; i < numberOfRaces; i++)
{
races = new Race();
}
finals = new Race();
}
public void addSwimmers()
{
// fills the qualifying heats with swimmers
}
public void fillFinals()
{
// fills the finals race with the best 8 from the qualifying heats
}
// more methods()
}
The Event class above assumes that the event has more than 8 swimmers and requires qualifying heats. However, an event with less than 9 swimmers has no qualifying heats, so the original Event class was inherited by a new class FinalsOnlyEvent.
The same method identifier addSwimmersis used in both classes Raceand Event.
Explain why this does not cause a conflict.
Outline two advantages of the OOP feature “inheritance”.
Outline how method overriding can help to create the new class FinalsOnlyEvent.
An airline company is updating its reservation system, which includes classes like Seat, EconomySeat, and BusinessSeat. EconomySeat and BusinessSeat inherit from Seat.
Explain one advantage of polymorphism in this reservation system.
Explain two advantages of modularity in developing this system.
Define the term polymorphism.
A hotel chain has a loyalty scheme in which customers are awarded 1000 points for each day they stay in one of their hotels. With these points, customers can achieve one of three status levels: Gold, Silver or Bronze. The level will determine the extra services to which they are entitled.
The total number of points collected during the current year will determine which of the three status levels they are assigned for the following year: For example only the points collected in 2018 will determine the status level for 2019.
Occasionally, new customers receive additional bonus points as part of a promotion.
The Pointsclass keeps details of the points and status levels of each customer.
public class Points
{
private String memberId; // id of the hotel customer
private int totalPoints; // this year's points
private int bonusPoints; // any bonus points given to this year's new member
private String statusNow; // current(this year's)status
private String statusNextYear; // following year's status
private Visits$$ allVisits = new Visits;//details of each visit
// during this year
int y; // number of visits this year
public Points(String id) // constructor for new member
{
memberId = id;
bonusPoints = 0;
y = 0;
statusNow = 'Bronze';
}
//constructor for new member given bonus points (valid for current year only)
public Points(String id, int bp)
{
memberId = id;
bonusPoints = bp; // multiples of 1000 - maximum number is 5000
y = 0;
statusNow = 'Bronze';
}
// all the accessor and mutator methods are present but not shown
public Visits getAllVisits(int v)
{
return allVisits;
}
public void addVisit(Visits v) // adds a new Visit object to the array
{
allVisits = v;
y = y + 1;
}
isGold() {code missing}
calculateTotalPoints(){code missing}
daysMissing(){code missing}
}
The instance variables in the Pointsclass are preceded by the modifier private. The choice of modifier affects the way in which these variables are accessed or used.
The customers will be assigned one of three levels for the following year (Gold, Silver or Bronze) depending upon the current year’s total points as follows.
In 2018, Tim became a member for the first time and was awarded a bonus of 1000 points. So far, in 2018, Tim has stayed three times at one of these hotels. The first visit lasted 2 days, the second visit lasted 1 day and the third visit lasted 6 days.
The different Pointsobjects are stored in an array which is declared globally in the main (driver) class as follows:Points[] allPoints = new Points[10000];
With the use of two examples other than private, outline how the choice of this modifier affects the way in which these variables are accessed or used.
With reference to the two methods with the same name in the Pointsclass, explain the OOP feature that makes it possible to successfully implement either of these methods.
State the status level that Tim has been assigned, for 2019, following these visits.
State how an individual object can be identified using this array.
The attribute statusNowis assigned its correct value at the beginning of every year for existing members. It cannot be changed during the year.
Construct the method isGold()in the Pointsclass, which will return whether the current status is “Gold”.
The Arrivalobject has two methods named compareWith.
Outline why calling the compareWithmethod does not cause a conflict.
Outline the use of data-hiding as a security feature in OOP.
A company is developing an AI chatbot system with classes such as Chatbot, CustomerServiceBot, and SalesBot. Both CustomerServiceBot and SalesBot inherit from Chatbot.
Define the term inheritance.
Explain one advantage of using inheritance in this AI chatbot system.
Describe two advantages of using libraries of objects in developing this system.
Outline the need for higher level languages.
Explain two benefits of using sub-procedures within a computer program.
Identify three characteristics of a collection.
Construct in pseudocode an algorithm, using the access methods of a collection, which will iterate through the collection NUMBERS and count how many elements stored in the collection are in the interval [-1,1]. The final answer should be output.
A company is developing a suite of financial software tools, utilizing programming teams in different countries.
Discuss the use of programming teams in software development projects.
Outline two reasons why using programming teams in different locations may be problematic.
Describe one advantage and one disadvantage of object-oriented programming for the development of financial software tools.
By making reference to any of the classes from 12(a), describe two benefits that a programming team would gain from the use of encapsulation.
Construct a diagram showing the relationships between the Payment, FoodItem, DrinkItem, and Itemclasses. You do not need to include the names of attributes or methods.
The company that owns this restaurant also owns hotels, shops, and a car hire business. The programs that manage the finances of these different businesses include classes similar to the ones shown in this paper.
Explain how inheritance could be used as a tool to both improve the clarity of the design and to reduce the amount of code that needs to be written.
A multimedia software company is creating a graphics editor with classes such as Shape, Circle, and Rectangle. Both Circle and Rectangle inherit from Shape.
Explain the term encapsulation.
Explain one advantage of encapsulation in the graphics editor.
Describe two disadvantages of object-oriented programming for this software.