Lab 10 Ex2

You cannot submit for this problem because the homework's deadline is due.

Ex2. Class exercise - Double Decker Bus (30 marks)

In this exercise, you need to implement a class called DoubleDeckerBus that publicly inherits the Bus class you wrote in the above exercises. As its name suggests, it models a double decker bus and has more functionalities beyond a normal bus.

First, we need to make a few modifications of the Bus class to better support inheritance:

  1. Add the virtual keyword before the declaration of void print() to make the print function a virtual function.
  2. Add a new method int getPassengerNum() that returns the current number of passengers on the bus. We need this method since passengerNum is a private attribute and cannot be accessed by the derived class.

We have done this for you since it requires little amount of code and a new Bus.h is given on Canvas.

After this, you need to implement the DoubleDeckerBus type that has these new properties:

  1. The constructor is DoubleDeckerBus::DoubleDeckerBus(int passengerNumMax, int passengerNumMax2). The added passengerNumMax2 specifies the maximum number of passengers on the second floor, and the original passengerNumMax specifies the maximum number of passengers on the first floor. Two additional private attributes are also defined for the second floor.
  2. The virtual print() method is overridden, and the new requirements for output is given in the provided header file.
  3. The getPassengerNum(), passengerGetOn() and passengerGetOff() methods are directly inherited, and they correspond to passengers on the first floor of the bus.
  4. Three new methods, getPassengerNum2(), passengerGetOn2(), and passengerGetOff2() are added, and they correspond to passengers on the second floor of the bus.

We provide you with DoubleDeckerBus.h, and you need to write the corresponding DoubleDeckerBus.cpp that implements the methods declared in the header file. You should submit only DoubleDeckerBus.cpp.

A simple test program called ex2.cpp is given on Canvas.

Lab 10 Exercises

Not Claimed
Status
Finished
Problems
3
Open Since
2022-07-21 18:15
DDL
2022-07-22 23:59
Extension
0.0 hour(s)