AQA A-Level Computer Science: Programming & OOP
6 exam-style questions with full mark schemes and model answers. Write your own answer and the AI examiner marks it against the mark scheme.
The following scenario was written for this exercise.
A gym membership system needs to model its members. Every Member has a name, a membership number, and a running total of the number of fitness classes they have booked this month. The system has two rules it must enforce:
- a member may book at most 8 classes per month (a booking beyond this must be rejected);
- the system must always know how many members in total have ever been created.
The gym later introduces a new kind of member, the PremiumMember, who is allowed a higher monthly limit and who also has a personal-trainer name.
You may answer in AQA-style pseudocode or a high-level language of your choice; the markers below assume the AQA pseudocode convention (CLASS … END CLASS, PUBLIC PROCEDURE new(…), PRIVATE attribute: TYPE).
(a) Design the Member class. It must use encapsulation appropriately (private attributes accessed through public methods), provide a constructor that initialises every attribute, provide a getter for the booking count and a method to book a class that enforces the limit, and maintain a class-level counter of all members created. [8 marks]
(b) Design a subclass PremiumMember that inherits from Member. Its constructor must take the personal-trainer name as well, call the superclass constructor, and the class must override the booking limit so that a premium member may book up to 12 classes per month. [4 marks]
A software house is starting work on a large, long-lived hospital management system — patients, staff, wards, appointments and billing — that a big team will extend and maintain for many years. One developer argues it should be built using the object-oriented paradigm; another insists the procedural paradigm they already know would be quicker to get going and is "good enough".
Discuss the advantages of using the object-oriented paradigm rather than the procedural paradigm for a project of this kind, and conclude with a justified recommendation. [9 marks]
The following scenario was written for this exercise.
A drawing program models shapes with a superclass Shape that defines a method area(). Two subclasses, Rectangle and Circle, each store their own attributes. The program keeps a single list that may contain a mixture of Rectangle and Circle objects, and a reporting routine loops over the list calling area() on each object.
Explain how polymorphism, achieved through method overriding, allows this single loop to compute the correct area for every shape. Use a short code example of an overridden area() method in your answer. [6 marks]
When modelling the relationships between classes, three "has-a" style relationships are distinguished: association, aggregation and composition.
Explain the difference between these three relationships, and give one example of each (you may invent suitable classes). [5 marks]
The object-oriented paradigm is built on four defining principles.
Name the principles of encapsulation, inheritance and polymorphism, give a one-line explanation of each, and state which one of these is associated with the "is-a" relationship and which models a class gaining the members of another. [4 marks]
In object-oriented programming the terms class and object are closely related but distinct, and creating an object from a class is called instantiation.
Define the terms class and object, making the difference between them clear, and state what is meant by instantiation. Use a single worked example (you may invent a suitable class) to illustrate all three. [3 marks]