9618/33/O/N/22 question 11: worked solution (October/November 2022, paper 33)
Show as plain textHide plain text
Cambridge A2 Level Computer Science 9618 · 20.1 Programming Paradigms Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 1 of 2. Q9 9618/33/O/N/22 original Q11 Structured · 8 marks Worked solution (a) Write one definition for each term: Instance : a specific object made from a class (an instantiation of the class) [1] Inheritance : defining a new class that gets all the attributes and methods of a parent class [1] Polymorphism : the same method can behave differently depending on the class used (methods can be redefined in derived classes) [1] (b) Name the class, declare the other four PRIVATE attributes, add the constructor parameters, assign them, and close the class. CLASS Car PRIVATE Make : STRING PRIVATE Model : STRING PRIVATE BodyType : STRING PRIVATE Fuel : STRING PRIVATE NumberBuilt : INTEGER PUBLIC PROCEDURE NEW(CarMake : STRING, CarModel : STRING, CarBodyType : STRING) Make ← CarMake Model ← CarModel BodyType ← CarBodyType Fuel ← "" NumberBuilt ← 0 ENDPROCEDURE GetFuel() GetNumberBuilt() ENDCLASS CLASS Car and ENDCLASS [1] Four PRIVATE declarations (Model, BodyType, Fuel as STRING and NumberBuilt as INTEGER) using the identifiers in the assignments [1] Constructor header with the parameter CarBodyType [1] Assignments Make ← CarMake and Model ← CarModel [1] The constructor parameter for the model matches the identifier in the Model assignment [1] KEY IDEA A class keeps its attributes PRIVATE and sets them in a constructor; inheritance reuses a parent class and polymorphism lets methods differ by class. TOTAL 8 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by O/Alevel CS by Wasiq. Tap the picture to open it on YouTube.