// train.h #include "train.h" #include #include using namespace std; Train::Train() { } Train::~Train() { for(Car *c : cars) delete c; } void Train::add(Car *car) { cars.push_back(car); } float Train::currentMt() const { float sum = 0.0; for(Car *c : cars) sum += c->currentMt(); return sum; } Car::Car() { } Car::~Car() { } void Car::brake() { cout << "Brakes engaged for car." << endl; } float Car::currentMt() const { return measuredMt; } Locomotive::Locomotive() { } void Locomotive::disengage() { cout << "Turning locomotive off." << endl; } void Locomotive::engage() { cout << "Turning locomotive on." << endl; }; float Locomotive::maxMt() const { return currentMt(); } Wagon::Wagon() { } float Wagon::maxMt() const { return 100.0; } BoxCar::BoxCar() { } float BoxCar::volume() const { // in cubic feet // based on info at https://cs.trains.com/trn/f/111/t/127097.aspx return 40.5 * 10.5 * 9.5; // length * height * width } Tanker::Tanker() { } float Tanker::volume() const { float radius = 10.5 / 2.0; return 40.5 * 3.14159 * radius * radius; } float Tanker::maxMt() const { // assume max of 4 grams per cubic centimeter (since heavy liquids // start at 2g), 28300 cubic cm per cubic foot return volume() * 4 * 28300 / 1e6; }