// file: Car.cc // author: Robert Keller // purpose: Define class Car. // Illustrate C++ initializer. // // description: Class Car represents an automobile. Every automobile is // composed of a Chassis, which we want to be defined when // the automobile is constructed, not later. // // We thus initialize the chassis component in the constructor // for Car to avoid the anomalous situation // of an automobile with no chassis. #include "Car.hh" #include "strings.hh" #include /** Create a car of a specific make. **/ Car::Car(string _make) : make(_make), // calls constructor for string chassis(getChassisMake(_make)) // calls constructor for Chassis { } /** Return a description of the car. **/ string Car::getDescription() { return make + " with " + chassis.getDescription() + " chassis"; } /** Determine chassis make for a given car make. **/ string Car::getChassisMake(string carMake) { if( carMake == BUICK ) return FISCHER_BODY; if( carMake == CHEVROLET ) return FISCHER_BODY; if( carMake == CHRYSLER ) return CHRYSLER; if( carMake == DODGE ) return CHRYSLER; if( carMake == PLYMOUTH ) return CHRYSLER; return UNKNOWN; }