Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types of passenger trains. One train can hold only cats.

C++ ONLY Please

TRAINS

DESCRIPTION

You are completing a program that allows for several different types of passenger trains. One train can hold only cats. Another train can hold only wizards. You are going to create a Wizard class, a Cat class, and a Train class. You are provided the driver, lab2.cpp. The Train class should be a template class where the type of passenger is the template data type.

Specifications

cat class

Attributes:

  • name of cat
  • breed of cat
  • color of cat
  • age of cat

Functions:

  • constructor the constructor should have 4 parameters and should initialize the attributes to this sent data.
  • overloaded << operator whenever outside code prints out a Cat object, this function will determine which attributes will be printed and their formatting. You should print out each of the 4 pieces of data on a single line, separated by commas.

Wizard Class

Attributes:

  • name of wizard
  • age of wizard
  • height of wizard

Functions:

  • constructor the constructor should have 3 parameters and should initialize the attributes to this sent data.
  • overloaded << operator whenever outside code prints out a Wizard object, this function will determine which attributes will be printed and their formatting. You should print out each of the 3 pieces of data on a single line, separated by commas.

Train Template Class

Attributes:

  • name of the train
  • home location of the train
  • train passenger capacity (the maximum number of passengers allowed on the train)
  • the number of passengers currently on board
  • a pointer to a template data type. This eventually (in the constructor) will be used to create an array of the passengers.

Functions:

  • constructor the constructor should have 3 parameters and should initialize the train name, home location, and capacity to these values. Then, the constructor should dynamically allocate an array the size of the train capacity. The number of passengers currently on board should be initialized to zero.
  • destructor the destructor should release the dynamically allocated array
  • accessor function for the train name (getTrainName)
  • addPassenger function this function should have a template type as a parameter. If the number of passengers on board is euql to the train passenger capacity, your code should print that no more passengers can board the train. Otherwise, your code should place this new passenger in the correct spot in the array and then increment the number of passengers on board.
  • printPassengers function this function should go through the passengers array and print each passenger that is currently on board.

Provided Driver:

#include "Train.h" #include "Cat.h" #include "Wizard.h" #include using namespace std;

int main() { //Create a Wizard Train object Train wizardTrain("Hogwarts Express", "Kings Cross Station, London", 10); //Create wizards & then add them to the Wizard Train Wizard* wizard1 = new Wizard("Bill", 32, 65); wizardTrain.addPassenger(wizard1); Wizard* wizard2 = new Wizard("Jill", 24, 45); wizardTrain.addPassenger(wizard2); Wizard* wizard3 = new Wizard("Will", 10, 42); wizardTrain.addPassenger(wizard3); Wizard* wizard4 = new Wizard("Neal", 88, 73); wizardTrain.addPassenger(wizard4); //Print all the Wizard Train passengers cout << " Here are the wizards who have boarded the " << wizardTrain.getTrainName() << "! "; wizardTrain.printPassengers();

cout << endl << endl;

//Create a Cat Train object Train kittyTrain("Hello Kitty Express", "Japan", 10); //Create Cats & then add them to the Cat Train Cat* cat1 = new Cat("Yella Cat", "mixed", "orange & yellow", 8); kittyTrain.addPassenger(cat1); Cat* cat2 = new Cat("Mouth", "mixed", "black & white", 8); kittyTrain.addPassenger(cat2); Cat* cat3 = new Cat("Chloe", "siamese", "black & white", 3); kittyTrain.addPassenger(cat3); Cat* cat4 = new Cat("Brutus", "hairless", "skin color", 4); kittyTrain.addPassenger(cat4); Cat* cat5 = new Cat("Wally", "catdog", "lime", 1); kittyTrain.addPassenger(cat5); Cat* cat6 = new Cat("Gladass", "siamese", "black & white", 6); kittyTrain.addPassenger(cat6); //Print all the Cat Train passengers cout << "Here are the cats who have boarded the " << kittyTrain.getTrainName() << "! "; kittyTrain.printPassengers();

cout << endl << endl; return 0;

}

Sample Output

After you create the three classes required for lab2.cpp, you need to test all the code to make sure you get the same output as below! There is no user input in this program.

Here are the wizards who have boarded the Hogwarts Express!

Bill, 32 years old, 65 inches tall

Jill, 24 years old, 45 inches tall

Will, 10 years old, 42 inches tall

Neal, 88 years old, 73 inches tall

Here are the cats who have boarded the Hello Kitty Express!

Yella Cat, mixed, orange & yellow, 8

Mouth, mixed, black & white, 8

Chloe, siamese, black & white, 3

Brutus, hairless, skin color, 4

Wally, catdog, lime, 1

Gladass, siamese, black & white, 6

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_2

Step: 3

blur-text-image_3

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

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions