Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Whats causing this...Please help me. Please keep in mind tester.cpp CANNOT be ch

ID: 673976 • Letter: W

Question

Whats causing this...Please help me. Please keep in mind tester.cpp CANNOT be changed.

/////////////MY ERROR MESSAGE/////////////////////

clang++ -std=c++11 -I. -c vehicles.cpp

vehicles.cpp:122:14: error: out-of-line definition of 'LoadCapacity' does not

      match any declaration in 'Truck'

float Truck::LoadCapacity() const

             ^~~~~~~~~~~~

vehicles.cpp:172:9: error: out-of-line definition of 'Tanker' does not match any

      declaration in 'Tanker'

Tanker::Tanker( const char *serialNumber, unsigned int passengerCapacity,

        ^~~~~~

vehicles.cpp:199:10: error: out-of-line definition of 'Flatbed' does not match

      any declaration in 'Flatbed'

Flatbed::Flatbed( const char *serialNumber, unsigned int passengerCapacity,

         ^~~~~~~

3 errors generated.

makefile:28: recipe for target 'vehicles.o' failed

make: *** [vehicles.o] Error 1

////////////////////////////////////////////////////

vehicle.cpp

#include

#include

#include

#include

#include

VehicleType Vehicle::SnDecode(const char *sn)

{

//std::cout << "sn    = " << sn << " ";

//std::cout << "sn[0] = " << sn[0] << " ";

switch (sn[0])

{

case '1':

    return vehicle;

case '2':

    return car;

case '3':

    return truck;

case '4':

    return van;

case '5':

    return tanker;

case '6':

    return flatbed;

default:

    return badSn;

}

}

Vehicle::Vehicle()

: serialNumber_(0), passengerCapacity_(0)

{}

Vehicle::Vehicle( const char *serialNumber, unsigned int passengerCapacity )

: serialNumber_(0), passengerCapacity_(passengerCapacity)

{

//std::cout << "Vehicle() ";

serialNumber_ = new(std::nothrow) char[1 + strlen(serialNumber)];

if (serialNumber_ == 0)

{

    std::cerr << "Unable to allocate memory for Vehicle::serialNumber ";

    exit(EXIT_FAILURE);

}

strcpy(serialNumber_, serialNumber);

}

Vehicle::~Vehicle()

{

//std::cout << "~Vehicle() ";

delete[] serialNumber_;

}

const char *Vehicle::SerialNumber() const

{

return serialNumber_;

}

float Vehicle::LoadCapacity() const

{

return 0.0;

}

unsigned int Vehicle::PassengerCapacity() const

{

return passengerCapacity_;

}

const char *Vehicle::ShortName() const

{

return "UNK";

}

float Vehicle::Toll() const

{

return 2.00; // Non-Truck toll

}

Car::Car()

: Vehicle()

{}

Car::Car( const char *serialNumber, unsigned int passengerCapacity )

: Vehicle( serialNumber, passengerCapacity)

{

//std::cout << "Car() ";

}

Car::~Car()

{

//std::cout << "~Car() ";

}

const char *Car::ShortName() const

{

return "CAR";

}

Truck::Truck()

: Vehicle(), DOTLicense_(0)

{}

Truck::Truck( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense)

: Vehicle(serialNumber, passengerCapacity), DOTLicense_(0)

{

//std::cout << "Truck() ";

DOTLicense_ = new(std::nothrow) char[1 + strlen(DOTLicense)];

if (DOTLicense_ == 0)

{

    std::cerr << "Unable to allocate memory for Truck::DOTLicense ";

    exit(EXIT_FAILURE);

}

strcpy(DOTLicense_, DOTLicense);

}

Truck::~Truck()

{

//std::cout << "~Truck() ";

delete[] DOTLicense_;

}

float Truck::LoadCapacity() const

{

return Vehicle::LoadCapacity();

}

const char *Truck::ShortName() const

{

return "TRK";

}

float Truck::Toll() const

{

return 10.00; // Truck toll

}

const char *Truck::DOTLicense() const

{

return DOTLicense_;

}

Van::Van()

: Truck(), Box()

{}

Van::Van( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense, float length, float width, float height)

: Truck(serialNumber, passengerCapacity, DOTLicense),

Box(length, width, height) // Truck and Box constructor initializations

{

//std::cout << "Van() ";

}

Van::~Van()

{

//std::cout << "~Van() ";

}

float Van::LoadCapacity() const

{

return Box::Volume();

}

const char *Van::ShortName() const

{

return "VAN";

}

Tanker::Tanker()

: Truck(), Cylinder()

{}

Tanker::Tanker( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense, float length, float radius )

: Truck(serialNumber, passengerCapacity, DOTLicense),

Cylinder(length, radius) // Truck and Cylinder constructor initializations

{

//std::cout << "Tanker() ";

}

Tanker::~Tanker()

{

//std::cout << "~Tanker() ";

}

float Tanker::LoadCapacity() const

{

return Cylinder::Volume();

}

const char *Tanker::ShortName() const

{

return "TNK";

}

Flatbed::Flatbed()

: Truck(), Plane()

{}

Flatbed::Flatbed( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense, float length, float width)

: Truck(serialNumber, passengerCapacity, DOTLicense),

Plane(length, width) // Truck and Plane constructor initializations

{

//std::cout << "Flatbed() ";

}

Flatbed::~Flatbed()

{

//std::cout << "~Flatbed() ";

}

float Flatbed::LoadCapacity() const

{

return Plane::Area();

}

const char *Flatbed::ShortName() const

{

return "FLT";

}

////////////////////////////////////////////////////

vehicle.h

#ifndef VEHICLES_H

#define VEHICLES_H

#include

enum VehicleType { badSn, vehicle, car, truck, van, tanker, flatbed };

class Vehicle

{

public:

Vehicle(); // default constructor

Vehicle( const char *, unsigned int ); // 2-arg constructor

virtual ~Vehicle();

const char*           SerialNumber() const; // returns serial number

unsigned int          PassengerCapacity() const; //returns passenger capacity

virtual float         LoadCapacity() const; // returns 0

virtual const char* ShortName() const; // returns "UNK"

virtual float         Toll() const; // returns toll using fee schedule

static VehicleType   SnDecode(const char* sn);

private:

char *        serialNumber_;

unsigned int passengerCapacity_;

};

class Car : public Vehicle

{

public:

Car();

Car( const char *, unsigned int );

virtual ~Car();

const char* ShortName() const; // returns "CAR"

};

class Truck : public Vehicle

{

public:

Truck();

Truck( const char *, unsigned int, char * );

virtual ~Truck();

const char*   ShortName() const; // returns "TRK"

float         Toll() const; // returns toll using fee schedule

const char*   DOTLicense() const; // returns the license no

virtual float LoadCapacity() const;

private:

char *DOTLicense_;

};

class Van : public Truck, public Box

{

public:

Van();

Van( const char *, unsigned int, char *, float, float, float );

virtual ~Van();

float         LoadCapacity() const; // returns volume of box

const char*   ShortName() const; // returns "VAN"

};

class Tanker : public Truck, public Cylinder

{

public:

Tanker();

Tanker( const char *, unsigned int, char *, float, float );

virtual ~Tanker();

float LoadCapacity() const; // returns volume of cylinder

const char*   ShortName() const; // returns "TNK"

};

class Flatbed : public Truck, public Plane

{

public:

Flatbed();

Flatbed( const char *, unsigned int, char *, float, float );

virtual ~Flatbed();

float         LoadCapacity() const; // returns area of plane

const char*   ShortName() const; // returns "FLT"

};

#endif

////////////////////////////////////////////////////

shapes.h

#ifndef SHAPES_H

#define SHAPES_H

class Box

{

public:

Box(); // default constr

Box(float, float, float); // 3-arg constructor

~Box();

float Volume() const; // returns volume of box object

private:

float length_;

float width_;

float height_;

};

class Cylinder

{

public:

Cylinder(); //default constr

Cylinder(float, float); // 2-arg constructor

~Cylinder();

float Volume() const; // returns volume of cylinder object

private:

float length_;

float radius_;

};

class Plane

{

public:

Plane(); // default constr

Plane(float, float); // 2-arg constructor

~Plane();

float Area() const; // returns area of plane object

private:

float length_;

float width_;

};

#endif

////////////////////////////////////////////////////

shapes.cpp

#include

#include

const double PI = 3.14159;

Box::Box()

: length_(0), width_(0), height_(0)

{}

Box::Box(float length, float width, float height)

: length_(length), width_(width), height_(height)

{

// std::cout << "Box() ";

}

Box::~Box()

{

// std::cout << "~Box() ";

}

float Box::Volume() const

{

return length_ * width_ * height_;

}

Cylinder::Cylinder()

: length_(0), radius_(0)

{}

Cylinder::Cylinder(float length, float radius)

: length_(length), radius_(radius)

{

// std::cout << "Cylinder() ";

}

Cylinder::~Cylinder()

{

// std::cout << "~Cylinder() ";

}

float Cylinder::Volume() const

{

return PI * radius_ * radius_ * length_; // v = pi * r^2 * h

}

Plane::Plane()

: length_(0), width_(0)

{}

Plane::Plane(float length, float width)

: length_(length), width_(width)

{

// std::cout << "Plane() ";

}

Plane::~Plane()

{

// std::cout << "~Plane() ";

}

float Plane::Area() const

{

return length_ * width_;

}

////////////////////////////////////////////////////

tester.cpp

#include

#include

#include

#include

#include

#include

char snMessage [54] = "*** OOPS - serial number not owned by vehicle object";

char dotMessage [55] = "*** OOPS - license number not owned by vehicle object"

;

char dotLicense [15] = "DOTLICENSE OK";

const size_t maxEntrySize = 1+strlen(dotMessage);

int main(int argc, char* argv[])

{

bool BATCH = 0;

std::istream * isptr = &std::cin;

std::ifstream ifs;

if (argc > 1)

{

    ifs.open(argv[1]);

    if (ifs.fail())

    {

      std::cout << " ** cannot open command file " << argv[1] << ' ';

      exit (EXIT_FAILURE);

    }

    isptr = &ifs;

    BATCH = 1;

}

Vehicle *   Vptr;              // pointer to dynamically allocated Vehicle ob

ject

VehicleType v;                 // to hold type of vehicle

char        sn [maxEntrySize]; // to hold user entry

char        dot[maxEntrySize]; // used to test ownership of DOT License numbe

r

std::cout << std::fixed << std::showpoint << std:: setprecision(2); // set fl

oat output format

do

{

    std::cout << " Enter sn ('x' to quit): ";

    (*isptr) >> std::setw(maxEntrySize) >> sn;

    if (BATCH) std::cout << sn << ' ';

    if (sn[0] == 'x') break;

    v = Vehicle::SnDecode(sn);

    switch (v)

    {

      case vehicle:

        Vptr = new Vehicle(sn, 1, 1);

        break;

      case car:

        Vptr = new Car(sn, 2, 1);

        break;

      case truck:

        strcpy (dot,dotLicense);

        Vptr = new Truck(sn, 3, dot, 1);

        break;

      case van:

       strcpy (dot,dotLicense);

        Vptr = new Van(sn, 4, dot, 20, 4, 8, 1);

        break;

      case tanker:

        strcpy (dot,dotLicense);

        Vptr = new Tanker(sn, 5, dot, 40, 3, 1);

        break;

      case flatbed:

      strcpy (dot,dotLicense);

        Vptr = new Flatbed(sn, 6, dot, 20, 6, 1);

        break;

      case badSn:

        Vptr = new Vehicle ("BadSerialNumber",0, 1);

        break;

      default: // should never get here

        std::cerr << "** ERROR: bad serial number passed to decision logic ";

        break;

    } // end switch

strcpy (sn, snMessage);

    strcpy (dot, dotMessage);

    std::cout << "Short Name:    " << Vptr -> ShortName() << ' ';

    std::cout << "Toll Charge:   " << Vptr -> Toll() << ' ';

    std::cout << "Serial Number: " << Vptr -> SerialNumber() << ' ';

    std::cout << "Passenger Cap: " << Vptr -> PassengerCapacity() << ' ';

    std::cout << "Load Capacity: " << Vptr -> LoadCapacity() << ' ';

    if ( truck <= v ) // all types of trucks

    {

      std::cout << "DOT License:   " << (dynamic_cast(Vptr)) -> DOTLice

nse() << ' ';

    }

    delete Vptr;

} // end do

while (sn[0] != '0');

return 0;

} // end main

/////////////////////////////////////////////////////////////////////////

You are to define and implement the following classes: Box, Cylinder, Plane, Vehicle, Car, Truck, Van, Tanker, and Flatbed.

File shapes.h should contain the definitions of the classes Box, Cylinder, and Plane. File shapes.cpp should contain the member function implementations for these classes.

File vehicles.h should contain the definitions of the classes Vehicle, Car, Truck, Van, Tanker, and Flatbed. File vehicles.cpp should contain the implementations for these classes.

Turn in the files vehicles.h, vehicles.cpp, shapes.h, shapes.cpp, and log.txt using the submit script. Warning: Submit scripts do not work on the program and linprogservers. Use shell.cs.fsu.edu to submit projects. If you do not receive the second confirmation with the contents of your project, there has been a malfunction.

Code Requirements and Specifications - Server Side

You are to define and implement the following classes:

Class Name:

  Box

Services (added or changed):

  float Volume() const // returns volume of box object

Private variables:

  float length_, width_, height_;

  bool verbose_;

Class Name:

  Cylinder

Services (added or changed):

  float Volume() const // returns volume of cylinder object

Private variables:

  float length_, radius_;

  bool verbose_;

Class Name:

  Plane

Services (added or changed):

  float Area() const // returns area of plane object

Private variables:

  float length_, width_;

  bool verbose_;

Class Name:

  Vehicle

Services (added or changed):

  const char*           SerialNumber       () const // returns serial number

  unsigned int          PassengerCapacity () const // returns passenger capacity

  float                 LoadCapacity       () const // returns 0

  const char*           ShortName          () const // returns "UNK"

  float                 Toll               () const // returns toll using fee schedule

  static VehicleType   SnDecode           (const char* sn)

Private variables:

  char*        serialNumber_;

  unsigned int passengerCapacity_;

Protected variable:

  bool verbose_;;

Class name:

  Car

Inherits from:

  Vehicle

Services (added or changed):

  const char* ShortName() const // returns "CAR"

Class name:

  Truck

Inherits from:

  Vehicle

Services (added or changed):

  const char*   ShortName          () const // returns "TRK"

  float         Toll               () const // returns toll using fee schedule

  const char*   DOTLicense         () const // returns the license no

Private variables:

  char* DOTLicense_;

Class name:

  Van

Inherits from:

  Truck , Box

Services (added or changed):

  float         LoadCapacity       () const // returns volume of box

  const char*   ShortName          () const // returns "VAN"

Class name:

  Tanker

Inherits from:

  Truck , Cylinder

Services (added or changed):

  float         LoadCapacity       () const // returns volume of cylinder

  const char*   ShortName          () const // returns "TNK"

Class name:

  Flatbed

Inherits from:

  Truck , Plane

Services (added or changed):

  float         LoadCapacity       () const // returns area of plane

  const char*   ShortName          () const // returns "FLT"

Each class should have the following:

Default constructor

Parametrized constructor that initializes the class variables; default value for verbose_ is 0 = false

Destructor

Private copy constructor prototype

Private assignment operator prototype

Follow the notation conventions:

Compound names use uppercase letters to separate words likeThis or LikeThis

Class, method, and function names begin with upper case letters LikeThis

Object and variable names names begin with lower case letters likeThis

Class member variables end with underscore likeThis_

Note that Vehicle::verbose_ is protected so that derived classes can access it directly.

Be sure to make exactly the methods virtual that are needed - that is, those that are overridden in derived classes. Do not make a method virtual unless it is needed virtual.

The toll fee schedule is:minimum for all vehicles: $2.00all trucks: $10.00

For development and testing of the classes, each constructor and destructor should include a line of code that conditionally sends an identifying message to standard output, whenever verbose_ is 1 = true. For example, the Van destructor should output the message "~Van()" if Vehicle::verbose_ is true.

The user-defined type VehicleType is an enumerated type:

Type name:

  VehicleType

Enumerated values:

  badSn, vehicle, car, truck, van, tanker, flatbed

The static method VehicleType Vehicle::SnDecode(const char* sn) returns the vehicle type based on the first (index 0) character of the serial number sn according to this table:       sn[0]: 0        1        2        3        4        5        6

VehicleType: badSn    vehicle car      truck    van      tanker   flatbed

After your classes have been fully developed and debugged, so they compile without warnings, it is time to test with tester.cpp. Thoroughly test your vehicle objects with this program. Note that this program prompts you for a serial number. The serial number is decoded to get a vehicle type, and an object of that type is created dynamically. You should see the constructor calls displayed, in correct order, because tester creates the objects with "verbose" set to 1 = true. Then the methods of this object are called. You should see correct serial number (and, for trucks, dot license) displayed. An "OOPS" message may be displayed if a problem is detected with your constructors. Finally the object is deleted, and you should see the destructors called in correct order. Read the source code in tester.cpp both to understand how it works.

Hints

You will need a value for = "Pi" for calculating the volume of a cylinder. This is supported by the math library under the name M_PI: #include // M_PI defined to 21 significant digits

The example executable tester.x is for your information only - it is not needed for your project. However, tester.cpp is indispensable: This is one of the test programs that will be used to assess your project. Moreover, it will help you debug your classes and gives some example code that can serve as a model for your client tracker program in the next assignment.

To execute tester, enter a serial number at the prompt. The first digit determines the vehicle type. Tester uses the verbose implementations, so you should see all of the constructor and destructor calls for the selected type.

All destructors should be declared virtual. Be sure you understand why. There will likely be an exam question related to this.

The program tester.cpp is central to your effort in several ways:

Class Name:

  Box

Services (added or changed):

  float Volume() const // returns volume of box object

Private variables:

  float length_, width_, height_;

  bool verbose_;

Explanation / Answer

#include

#include

#include

#include

#include

VehicleType Vehicle::SnDecode(const char *sn)

{

//std::cout << "sn    = " << sn << " ";

//std::cout << "sn[0] = " << sn[0] << " ";

switch (sn[0])

{

case '1':

    return vehicle;

case '2':

    return car;

case '3':

    return truck;

case '4':

    return van;

case '5':

    return tanker;

case '6':

    return flatbed;

default:

    return badSn;

}

}

Vehicle::Vehicle()

: serialNumber_(0), passengerCapacity_(0)

{}

Vehicle::Vehicle( const char *serialNumber, unsigned int passengerCapacity )

: serialNumber_(0), passengerCapacity_(passengerCapacity)

{

//std::cout << "Vehicle() ";

serialNumber_ = new(std::nothrow) char[1 + strlen(serialNumber)];

if (serialNumber_ == 0)

{

    std::cerr << "Unable to allocate memory for Vehicle::serialNumber ";

    exit(EXIT_FAILURE);

}

strcpy(serialNumber_, serialNumber);

}

Vehicle::~Vehicle()

{

//std::cout << "~Vehicle() ";

delete[] serialNumber_;

}

const char *Vehicle::SerialNumber() const

{

return serialNumber_;

}

float Vehicle::LoadCapacity() const

{

return 0.0;

}

unsigned int Vehicle::PassengerCapacity() const

{

return passengerCapacity_;

}

const char *Vehicle::ShortName() const

{

return "UNK";

}

float Vehicle::Toll() const

{

return 2.00; // Non-Truck toll

}

Car::Car()

: Vehicle()

{}

Car::Car( const char *serialNumber, unsigned int passengerCapacity )

: Vehicle( serialNumber, passengerCapacity)

{

//std::cout << "Car() ";

}

Car::~Car()

{

//std::cout << "~Car() ";

}

const char *Car::ShortName() const

{

return "CAR";

}

Truck::Truck()

: Vehicle(), DOTLicense_(0)

{}

Truck::Truck( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense)

: Vehicle(serialNumber, passengerCapacity), DOTLicense_(0)

{

//std::cout << "Truck() ";

DOTLicense_ = new(std::nothrow) char[1 + strlen(DOTLicense)];

if (DOTLicense_ == 0)

{

    std::cerr << "Unable to allocate memory for Truck::DOTLicense ";

    exit(EXIT_FAILURE);

}

strcpy(DOTLicense_, DOTLicense);

}

Truck::~Truck()

{

//std::cout << "~Truck() ";

delete[] DOTLicense_;

}

float Truck::LoadCapacity() const

{

return Vehicle::LoadCapacity();

}

const char *Truck::ShortName() const

{

return "TRK";

}

float Truck::Toll() const

{

return 10.00; // Truck toll

}

const char *Truck::DOTLicense() const

{

return DOTLicense_;

}

Van::Van()

: Truck(), Box()

{}

Van::Van( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense, float length, float width, float height)

: Truck(serialNumber, passengerCapacity, DOTLicense),

Box(length, width, height) // Truck and Box constructor initializations

{

//std::cout << "Van() ";

}

Van::~Van()

{

//std::cout << "~Van() ";

}

float Van::LoadCapacity() const

{

return Box::Volume();

}

const char *Van::ShortName() const

{

return "VAN";

}

Tanker::Tanker()

: Truck(), Cylinder()

{}

Tanker::Tanker( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense, float length, float radius )

: Truck(serialNumber, passengerCapacity, DOTLicense),

Cylinder(length, radius) // Truck and Cylinder constructor initializations

{

//std::cout << "Tanker() ";

}

Tanker::~Tanker()

{

//std::cout << "~Tanker() ";

}

float Tanker::LoadCapacity() const

{

return Cylinder::Volume();

}

const char *Tanker::ShortName() const

{

return "TNK";

}

Flatbed::Flatbed()

: Truck(), Plane()

{}

Flatbed::Flatbed( const char *serialNumber, unsigned int passengerCapacity,

char *DOTLicense, float length, float width)

: Truck(serialNumber, passengerCapacity, DOTLicense),

Plane(length, width) // Truck and Plane constructor initializations

{

//std::cout << "Flatbed() ";

}

Flatbed::~Flatbed()

{

//std::cout << "~Flatbed() ";

}

float Flatbed::LoadCapacity() const

{

return Plane::Area();

}

const char *Flatbed::ShortName() const

{

return "FLT";

}

////////////////////////////////////////////////////

vehicle.h

#ifndef VEHICLES_H

#define VEHICLES_H

#include

enum VehicleType { badSn, vehicle, car, truck, van, tanker, flatbed };

class Vehicle

{

public:

Vehicle(); // default constructor

Vehicle( const char *, unsigned int ); // 2-arg constructor

virtual ~Vehicle();

const char*           SerialNumber() const; // returns serial number

unsigned int          PassengerCapacity() const; //returns passenger capacity

virtual float         LoadCapacity() const; // returns 0

virtual const char* ShortName() const; // returns "UNK"

virtual float         Toll() const; // returns toll using fee schedule

static VehicleType   SnDecode(const char* sn);

private:

char *        serialNumber_;

unsigned int passengerCapacity_;

};

class Car : public Vehicle

{

public:

Car();

Car( const char *, unsigned int );

virtual ~Car();

const char* ShortName() const; // returns "CAR"

};

class Truck : public Vehicle

{

public:

Truck();

Truck( const char *, unsigned int, char * );

virtual ~Truck();

const char*   ShortName() const; // returns "TRK"

float         Toll() const; // returns toll using fee schedule

const char*   DOTLicense() const; // returns the license no

virtual float LoadCapacity() const;

private:

char *DOTLicense_;

};

class Van : public Truck, public Box

{

public:

Van();

Van( const char *, unsigned int, char *, float, float, float );

virtual ~Van();

float         LoadCapacity() const; // returns volume of box

const char*   ShortName() const; // returns "VAN"

};

class Tanker : public Truck, public Cylinder

{

public:

Tanker();

Tanker( const char *, unsigned int, char *, float, float );

virtual ~Tanker();

float LoadCapacity() const; // returns volume of cylinder

const char*   ShortName() const; // returns "TNK"

};

class Flatbed : public Truck, public Plane

{

public:

Flatbed();

Flatbed( const char *, unsigned int, char *, float, float );

virtual ~Flatbed();

float         LoadCapacity() const; // returns area of plane

const char*   ShortName() const; // returns "FLT"

};

#endif

////////////////////////////////////////////////////

shapes.h

#ifndef SHAPES_H

#define SHAPES_H

class Box

{

public:

Box(); // default constr

Box(float, float, float); // 3-arg constructor

~Box();

float Volume() const; // returns volume of box object

private:

float length_;

float width_;

float height_;

};

class Cylinder

{

public:

Cylinder(); //default constr

Cylinder(float, float); // 2-arg constructor

~Cylinder();

float Volume() const; // returns volume of cylinder object

private:

float length_;

float radius_;

};

class Plane

{

public:

Plane(); // default constr

Plane(float, float); // 2-arg constructor

~Plane();

float Area() const; // returns area of plane object

private:

float length_;

float width_;

};

#endif

////////////////////////////////////////////////////

shapes.cpp

#include

#include

const double PI = 3.14159;

Box::Box()

: length_(0), width_(0), height_(0)

{}

Box::Box(float length, float width, float height)

: length_(length), width_(width), height_(height)

{

// std::cout << "Box() ";

}

Box::~Box()

{

// std::cout << "~Box() ";

}

float Box::Volume() const

{

return length_ * width_ * height_;

}

Cylinder::Cylinder()

: length_(0), radius_(0)

{}

Cylinder::Cylinder(float length, float radius)

: length_(length), radius_(radius)

{

// std::cout << "Cylinder() ";

}

Cylinder::~Cylinder()

{

// std::cout << "~Cylinder() ";

}

float Cylinder::Volume() const

{

return PI * radius_ * radius_ * length_; // v = pi * r^2 * h

}

Plane::Plane()

: length_(0), width_(0)

{}

Plane::Plane(float length, float width)

: length_(length), width_(width)

{

// std::cout << "Plane() ";

}

Plane::~Plane()

{

// std::cout << "~Plane() ";

}

float Plane::Area() const

{

return length_ * width_;

}

////////////////////////////////////////////////////

tester.cpp

#include

#include

#include

#include

#include

#include

char snMessage [54] = "*** OOPS - serial number not owned by vehicle object";

char dotMessage [55] = "*** OOPS - license number not owned by vehicle object"

;

char dotLicense [15] = "DOTLICENSE OK";

const size_t maxEntrySize = 1+strlen(dotMessage);

int main(int argc, char* argv[])

{

bool BATCH = 0;

std::istream * isptr = &std::cin;

std::ifstream ifs;

if (argc > 1)

{

    ifs.open(argv[1]);

    if (ifs.fail())

    {

      std::cout << " ** cannot open command file " << argv[1] << ' ';

      exit (EXIT_FAILURE);

    }

    isptr = &ifs;

    BATCH = 1;

}

Vehicle *   Vptr;              // pointer to dynamically allocated Vehicle ob

ject

VehicleType v;                 // to hold type of vehicle

char        sn [maxEntrySize]; // to hold user entry

char        dot[maxEntrySize]; // used to test ownership of DOT License numbe

r

std::cout << std::fixed << std::showpoint << std:: setprecision(2); // set fl

oat output format

do

{

    std::cout << " Enter sn ('x' to quit): ";

    (*isptr) >> std::setw(maxEntrySize) >> sn;

    if (BATCH) std::cout << sn << ' ';

    if (sn[0] == 'x') break;

    v = Vehicle::SnDecode(sn);

    switch (v)

    {

      case vehicle:

        Vptr = new Vehicle(sn, 1, 1);

        break;

      case car:

        Vptr = new Car(sn, 2, 1);

        break;

      case truck:

        strcpy (dot,dotLicense);

        Vptr = new Truck(sn, 3, dot, 1);

        break;

      case van:

       strcpy (dot,dotLicense);

        Vptr = new Van(sn, 4, dot, 20, 4, 8, 1);

        break;

      case tanker:

        strcpy (dot,dotLicense);

        Vptr = new Tanker(sn, 5, dot, 40, 3, 1);

        break;

      case flatbed:

      strcpy (dot,dotLicense);

        Vptr = new Flatbed(sn, 6, dot, 20, 6, 1);

        break;

      case badSn:

        Vptr = new Vehicle ("BadSerialNumber",0, 1);

        break;

      default: // should never get here

        std::cerr << "** ERROR: bad serial number passed to decision logic ";

        break;

    } // end switch

strcpy (sn, snMessage);

    strcpy (dot, dotMessage);

    std::cout << "Short Name:    " << Vptr -> ShortName() << ' ';

    std::cout << "Toll Charge:   " << Vptr -> Toll() << ' ';

    std::cout << "Serial Number: " << Vptr -> SerialNumber() << ' ';

    std::cout << "Passenger Cap: " << Vptr -> PassengerCapacity() << ' ';

    std::cout << "Load Capacity: " << Vptr -> LoadCapacity() << ' ';

    if ( truck <= v ) // all types of trucks

    {

      std::cout << "DOT License:   " << (dynamic_cast(Vptr)) -> DOTLice

nse() << ' ';

    }

    delete Vptr;

} // end do

while (sn[0] != '0');

return 0;

} // end main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote