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:
- Add the
virtual
keyword before the declaration ofvoid print()
to make the print function a virtual function. - Add a new method
int getPassengerNum()
that returns the current number of passengers on the bus. We need this method sincepassengerNum
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:
- The constructor is
DoubleDeckerBus::DoubleDeckerBus(int passengerNumMax, int passengerNumMax2)
. The addedpassengerNumMax2
specifies the maximum number of passengers on the second floor, and the originalpassengerNumMax
specifies the maximum number of passengers on the first floor. Two additional private attributes are also defined for the second floor. - The virtual
print()
method is overridden, and the new requirements for output is given in the provided header file. - The
getPassengerNum()
,passengerGetOn()
andpassengerGetOff()
methods are directly inherited, and they correspond to passengers on the first floor of the bus. - Three new methods,
getPassengerNum2()
,passengerGetOn2()
, andpassengerGetOff2()
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
- Status
- Finished
- Problems
- 3
- Open Since
- 2022-07-21 18:15
- DDL
- 2022-07-22 23:59
- Extension
- 0.0 hour(s)