Question: Using C++ Program: 9. Figure 9-A shows a UML Class diagram with 3 classes : TrainCarriage, PassengerCarriage and CargoCarriage, along with their attributes, constructor and

Using C++ Program:

Using C++ Program: 9. Figure 9-A shows a UML Class diagram with

3 classes : TrainCarriage, PassengerCarriage and CargoCarriage, along with their attributes, constructor

9. Figure 9-A shows a UML Class diagram with 3 classes : TrainCarriage, PassengerCarriage and CargoCarriage, along with their attributes, constructor and method signature. Note that method showData() has the exact same method signature for all 3 classes, hence, the super-class TrainCarriage's showData() is meant to be over-ridden by the other 2 sub-classes TrainCarriage #name #lengthInM : string : int Fig. 9-A +TrainCarriage ( name : string, lengthInM : string) +showData() : void PassengerCarriage CargoCarriage #seatingCapacity: int #isLuxuryClass : bool #maxVolume InCubicM: float #maxWeightInkg : float + Passenger Carriage name : string, lengthInM : int, seatingCapacity : int, is Luxuryclass : bool ) + CargoCarriage name : string, lengthInM : int, maxVolume InCubicM : float, maxWeightInKg : float) +showData(): void +showData()void int main() { TrainCarriage * tArray [3]; tArray [0] = new CargoCarriage ("Cargo", 60, 1368.38, 8800.50); tArray [1] = new PassengerCarriage ("Passenger", 50, 30, true); tArray [2] = new TrainCarriage ("Generic Carriage", 40); for (int i=0; ishowData(); Fig. 9-B return (0) ; Figure 9-C provides a sample output when the program (in Fig 9-B) is run. Fig. 9-C Name : Cargo Length (In Meters) : 60 Max Volume : 1368.38 cu M Max Weight : 8800.5 kg Name : Passenger Length (In Meters) : 50 Seating Capacity : 30 Is Luxury Class? Yes : Name : Generic Carriage Length (In Meters) : 40 Based on the information provided in all 3 figures, you are to demonstrate the Object Oriented principles of Encapsulation, Inheritance and Polymorphism by : a) Writing the class declarations for TrainCarriage, PassengerCarriage and CargoCarriage. Where applicable, you are to include all the necessary : header guards (e.g. #ifndef ... #define ...) C++ library or user-defined headers and namespace ... as if you are writing them in separate TrainCarriage.h, PassengerCarriage.h and CargoCamiage.h files! (Note : you may write your answers on 1-2 pages if possible, there is no need to use a new page in your answer document for each class declaration) (6 marks) b) Writing the class implementation code for TrainCarriage, PassengerCarriage and CargoCarriage. Where applicable, you are to include all the necessary : header guards (e.g. #ifndef ... #define ...) C++ library or user-defined headers and namespace ... as if you are writing them in separate TrainCarriage.cpp, PassengerCarriage.cpp and CargoCarriage.cpp files! (Note: you may write your answers on 1-2 pages if possible, there is no need to use a new page in your answer document for each class implementation) (6 marks)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!