Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

3. What are potential solutions?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago