Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

In C++:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

9 a Figure 9-A shows 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 + PassengerCarriage ( name : string, lengthInM : int, seatingCapacity : int, isLuxuryclass : bool) + CargoCarriage name : string, lengthInM : int, maxVolumeInCubicM : 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 : Cargo : 60 Name Length (In Meters) Max Volume Max Weight : 1368.38 cu M : 8800.5 kg Name Length (In Meters) Seating Capacity Is Luxury Class? Passenger : 50 : 30 : Yes Name Length (In Meters) : Generic Carriage : 40 Based on the information provided in all 3 figures, you are to demonstrate the object Oriented principles of Encapsulation, Inheritance and Polymorphism by : 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 CargoCarriage.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) 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)

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