Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Exercise: Vehicle System Enhanced (part 2)

Note: Con nue with codes from the previous exercise (Homework 6)
1. Base Class and Basic Polymorphism:
 Vehicle class: (updated)
o Implement two virtual methods:
 displayInfo(): A virtual method to print the make, model, and year of
the vehicle.
 getFuelType(): A pure virtual func on making Vehicle an abstract
class. This method will return a string represen ng the fuel type (e.g.,
"Petrol", "Diesel", "Electric").
2. Abstract Class and Interface Implementa&on:
o Make Vehicle abstract by defining getFuelType() as a pure virtual func on.
o Define an interface IMaintenance with a pure virtual func on
performMaintenance(). This func on outlines maintenance rou nes specific
to a vehicle.
o Ensure the Car class implements this interface, providing a concrete
implementa on of performMaintenance(), such as detailing maintenance
checks for oil, brakes, and res.
3. Main Func&on Implementa&on: (updated)
o Instan ate Derived Class Objects:
 Create an object of the Car class, providing values for its a'ributes (make,
model, year, and number_of_doors).
 Create an object of the Bike class, providing values for its a'ributes
(make, model, year, and isElectric).
o Display Vehicle Informa on:
 Call the displayInfo() method on both the Car and Bike objects to print
their details. This demonstrates method overriding, as the derived classes
provide specific implementa ons of this method.
o Show Fuel Type:
 Call the getFuelType() method on both objects to display the fuel type of
each vehicle. This method is a pure virtual func on in the base class
Vehicle and showcases how abstract classes enforce the implementa on
of this method in derived classes.
o Demonstrate Interface Implementa on:
 Specifically for the Car object, invoke the performMaintenance() method
to show the implementa on of the IMaintenance interface. This should
detail the maintenance checks performed, such as oil, brakes, and res,
illustra ng how interfaces can be used to enforce certain behaviors in
derived classes.

You might also like