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

Project 4: DOT Common Carrier Framework A class framework supporting the DOT Fas

ID: 3839548 • Letter: P

Question

Project 4: DOT Common Carrier Framework

A class framework supporting the DOT FastLane project

Revision dated 02/20/17

Educational Objectives: After completing this assignment the student should have the following knowledge, ability, and skills:

Define a class hierarchy using inheritance

Define a class hierarchy using multiple inheritance

Define virtual member functions in a class hierarchy

Implement a class hierarchy using inheritance

Implement a class hierarchy using multiple inheritance

Implement virtual member functions in a class hierarchy

Use initialization lists to call parent class constructors for derived class constructors

State the call sequence for constructors in an inheritance chain

State the call sequence for destructors in an inheritance chain

Operational Objectives: Create (define and implement) classes Shape, Box, Cylinder, Rectangle, CommercialVehicle, Carriage, Limo, Bus, Truck, Van, Tanker, and Flatbed.

Deliverables: Six (6) files: vehicles.h, vehicles.cpp, shapes.h, shapes.cpp, makefile, and log.txt

Assessment Rubric

The DOT FastLane Project

The DOT Common Carrier Framework supports an application known as FastLane for the Florida Deperatment of Transportation in which data from commercial vehicle transponders is collected in real time at all commercial vehicle inspection locations, enabliing pre-certified vehicles with manifests to bypass physical inspection. The sensors detect a FastLane-equiped vehicle and actively inquire further data from the vehicle and screen the data in real time at an inspector's workstation, who can green-light the vehicle, thus avoiding stopping for physical inspection.

We use "FastLane" to encompass the current assignment, which is to develope the DOT Common Carrier Framework, as well as the next project which is to create the Tracker application client. Together these assignments simulate FastLane.

The current assignment focusses on the "server side" of the FastLane project: creating the various classes that are used by a client program to collect data.

Procedural Requirements

Create and work within a separate subdirectory cop3330/proj4. Review the COP 3330 rules found in Introduction/Work Rules.

Begin by copying all files from the course project directory into your proj4 directory. These should include:

Also copy the sample executables from area51:

Change the permissions on the area51 copies to executable:

It is a good idea to start by looking at the source code for the two test programs and running the area51 executables to get a feel for the testing environment. You can run these in batch mode with a com file:

Begin a log file named log.txt. This should be an ascii text file in cop3330/proj4 with the following header:

This file should document all work done by date and time, including all testing and test results. A free-form section at the end may be used for any other purpose.

You are to define and implement the following classes: Shape, Box, Cylinder, Rectangle, CommercialVehicle, Carriage, Bus, Limo, Truck, Van, Tanker, and Flatbed.

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

File vehicles.h should contain the definitions of the classes CommercialVehicle, Carriage, Bus, Limo, 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, makefile, and log.txt using the submit script.

It is assumed that you have an executable copy of the most current submit script LIB/scripts/submit.sh in your ~/.bin available as a command.

Warning: Submit scripts do not work on the program and linprog servers. 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:

Each class should have the following:

Default constructor

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

Destructor

Private copy constructor prototype with no implementing code

Private assignment operator prototype with no implementing code

Follow the notation conventions discussed in the Code Standards document.

Note that (iv) and (v) together ensure that copies of objects cannot be made. Privatizing the copy constructor and assignment operator prototypes will cause a compiler error if client code attemps to make a copy, and not providing implementing code will cause a link error if an attempt is made to copy objects anywhere in the class implementations.

The parameterized constructors for the classes in the framework are required to have the following arguments:

Only the last argument, verbose, should have a default value of 0 (= false).

Note that CommercialVehicle::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.

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: if CommercialVehicle::verbose_ is true the Van constructor should output something like "Van(622,Lacher,12345,8.00,10.00,40.00,1)", displaying the actual values of the constructor arguments, and the Van destructor should output the message "~Van()". Run the area51 examples for behavior.

The user-defined type VehicleType is an enumerated type:

The static method VehicleType CommercialVehicle::RegDecode(const char* sn) returns the vehicle type based on the first (index 0) character of the serial number snaccording to this table:

Using stester and vtester, it is required that your output match the area51 examples exactly.

After your classes have been fully developed and debugged, so they compile without warnings, it is time to test with the tester programs: stester.cpp tests the shapes classes by themselves (and may be used before the vehicles classes are developed) and vtester.cpp tests the vehicles classes.

Thoroughly test your objects with these programs before submitting the project, and keep test records in your log.txt. Note that vtester 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 vtester creates the objects with "verbose" set to 1 = true. Then the methods of this object are called. You should see correct serial number 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 both tester programs both to understand how they work.

Hints

It is best to use an incremental approach to development. Start with the Shapes classes. First create the header file shapes.h with file header documentation, various #include<xxx> statements, and protection against multiple read. Then, inside the multiple read protection, create the various shape class definitions following the specifications above. (Note: there is no way yet to test the header file.)

Next create the code file shapes.cpp. Begin with file header documentation and the required #include<shapes.h> statement. Then start implementing the functions prototyped in the header file one at a time. After each implementation is written, debug the code using the "co3330" command. (This also debugs the header file.)

Once the shapes are debugged, test them with stester.x. Keep working on these until stester.x output is identical to that of stester_i.x

After getting the shapes done and passed testing, follow the same process with vehicles and vtester.

You will need a value for = "Pi" for calculating the volume and surface area of a cylinder. This is supported by the math library under the name M_PI:

The example executables stester_i.x and vtester_i.x are for your use in testing as well, because we require that your output be exactly the same as ours. The unix "diff" command should be useful in comparing output from our benchmarks and your executables.

Trucks carry freight, not passengers. Carriages carry passengers, not freight.

To execute vtester, enter a serial number at the prompt. The first digit determines the vehicle type. Tester uses the verbose = 1, 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.

Your makefile will need these targets: stester.x vtester.x stester.o vtester.o shapes.o vehicles.o along with the top target

You can debug using the co3330 macro:

Your classes will be independently tested with client programs written to the interfaces defined above.

Run the distributed executables in LIB/area51/ to see how your programs are expected to behave.

where I need help is in Vehicles on getting the correct output for ShortName and PassengerCapacity as well as using "new" to get the output for "vehicleRegistration", "operatorID" and "operatorCDL". this is what I have.

#include "shapes.h"
#include "vehicles.h"
#include <iostream>
#include <string.h>
#include <cmath>

const char* CommercialVehicle::Registration () const{
return vehicleRegistration_;
}

const char* CommercialVehicle::Operator () const{
return operatorID_;
}

const char* CommercialVehicle::CDL () const{
return operatorCDL_;
}

unsigned int CommercialVehicle::PassengerCapacity () const{
return passengerCapacity_;
}

float CommercialVehicle::LoadCapacity() const{return 0;}
const char* CommercialVehicle::ShortName() const{return "UNK";}

//CommercialVehicle::~ShortName(){
// delete ShortName();}

VehicleType CommercialVehicle::RegDecode (const char* sn){
VehicleType a;
switch (sn[0]){
case '0':
a=badReg;
break;
case '1':
a=vehicle;
break;
case '2':
a=carriage;
break;
case '3':
a=bus;
break;
case '4':
a=limo;
break;
case '5':
a=truck;
break;
case '6':
a=van;
break;
case '7':
a=tanker;
break;
case '8':
a=flatbed;
break;
default:
return carriage;
}
return a;
}

/*CommercialVehicle::CommercialVehicle(){}
Carriage::Carriage():CommercialVehicle(){}
Truck::Truck():CommercialVehicle(){}
Limo::Limo():Carriage(){}
Bus::Bus():Carriage(){}
Tanker::Tanker():Truck(), Cylinder(){}
Van::Van():Truck(), Box(){}
Flatbed::Flatbed():Truck(), Rectangle(){}*/


const char* Carriage::ShortName() const{return "CAR";}

const char* Bus::ShortName() const{return "BUS";}

const char* Limo::ShortName() const{return "LIM";}

const char* Truck::ShortName() const{return "TRK";}

const char* Van::ShortName() const{return "VAN";}

float Van::LoadCapacity() const{return Box::Volume();}

const char* Tanker::ShortName() const{return "TNK";}

float Tanker::LoadCapacity() const{return Cylinder::Volume();}

const char* Flatbed::ShortName() const{return "FLT";}

float Flatbed::LoadCapacity() const{return x_*z_;}//Rectangle::Area();}


Carriage::Carriage(const char* VR, const char* OI, const char* OC, unsigned short PC, bool VB):CommercialVehicle(VR, OI, OC, PC, VB){
if(CommercialVehicle::verbose_==1){std::cout<<"Carriage("<<VR<<","<<OI<<","<<OC<<","<<PC<<","<<VB<<")"<<' ';}
}

Bus::Bus(const char* VR, const char* OI, const char* OC, unsigned short PC, bool VB):Carriage(VR, OI, OC, PC, VB){
if(CommercialVehicle::verbose_==1){std::cout<<"Bus("<<VR<<","<<OI<<","<<OC<<","<<PC<<","<<VB<<")"<<' ';}
}

CommercialVehicle::CommercialVehicle(const char* VR, const char* OI, const char* OC, unsigned short PC, bool VB){
verbose_= VB;
vehicleRegistration_=new const char VR;
operatorID_=new OI ;
operatorCDL_=new OC ;
passengerCapacity_=PC;
if(verbose_==1){std::cout<<"Commercial Vehicle("<<VR<<","<<OI<<","<<OC<<","<<PC<<","<<VB<<")"<<' ';}
}
Limo::Limo(const char* VR, const char* OI, const char* OC, unsigned short PC, bool VB):Carriage(VR, OI, OC, PC, VB){
if(CommercialVehicle::verbose_==1){std::cout<<"Limo("<<VR<<","<<OI<<","<<OC<<","<<PC<<","<<VB<<")"<<' ';}
}
Truck::Truck(const char* VR, const char* OI, const char* OC, bool VB):CommercialVehicle(VR, OI, OC, 0, VB){
if(CommercialVehicle::verbose_==1){std::cout<<"Truck("<<VR<<","<<OI<<","<<OC<<","<<VB<<")"<<' ';}
}
Van::Van(const char* VR, const char* OI, const char* OC, float x, float y, float z, bool VB):Truck(VR, OI, OC, VB),Box(x,y,z,VB){
x_=x;
y_=y;
z_=z;
if(Truck::verbose_==1){std::cout<<"Van("<<VR<<","<<OI<<","<<OC<<","<<x<<","<<y<<","<<z<<","<<VB<<")"<<' ';}
}
Tanker::Tanker(const char* VR, const char* OI, const char* OC, float x, float y, bool VB):Truck(VR, OI, OC, VB),Cylinder(x,y, VB){
x_=x;
y_=y;
if(Truck::verbose_==1){std::cout<<"Tanker("<<VR<<","<<OI<<","<<OC<<","<<x<<","<<","<<y<<VB<<")"<<' ';}
}
Flatbed::Flatbed(const char* VR, const char* OI, const char* OC, float x, float z, bool VB):Truck(VR, OI, OC, VB),Rectangle(x,z,VB){
x_=x;
z_=z;
if(Truck::verbose_==1){std::cout<<"Flatbed("<<VR<<","<<OI<<","<<OC<<","<<x<<","<<z<<","<<VB<<")"<<' ';}
}

Carriage::~Carriage(){if(CommercialVehicle::verbose_==1){std::cout<<"~Carriage()" << ' ';}
}

CommercialVehicle::~CommercialVehicle(){
if(CommercialVehicle::verbose_==1){
std::cout<<"~CommercialVehicle()" << ' ';
}
}

Van::~Van(){
if(Truck::verbose_==1){
std::cout<<"~Van()" << ' ';
}
}

Tanker::~Tanker(){
if(Truck::verbose_==1){
std::cout<<"~Tanker()" << ' ';
}
}

Truck::~Truck(){
if(CommercialVehicle::verbose_==1){
std::cout<<"~Truck()" << ' ';}
}
  
Flatbed::~Flatbed(){
if(Truck::verbose_==1){
std::cout<<"~Flatbed()" << ' ';
}
}


Limo::~Limo(){
if(CommercialVehicle::verbose_==1){
std::cout<<"~Carriage()" << ' ';
}
}


Bus::~Bus(){
if(CommercialVehicle::verbose_==1){
std::cout<<"~Carriage()" << ' ';
}
}

  Class Name:
    Shape  
  Services (added or changed):
    const char* Name   () const  // returns "generic"    float       Volume () const  // returns volume of object      float       Area   () const  // returns area of object    
  Protected variables:
    float x_, y_, z_; // dimensions of shape    bool  verbose_;   // default value 0 given in constructor prototype   

Explanation / Answer

//CommercialVehicle.h

#pragma once
#include "Shape.h"
#include <string>

enum VehicleType{
   badReg = 0, vehicle, carriage, bus, limo, truck, van, tanker, flatbed
};

class CommercialVehicle
{
   char* vehicleRegistration_;
   char* operatorID_;
   char* operatorCDL_;
   unsigned short passengerCapacity_;
   CommercialVehicle(const CommercialVehicle &obj)
   {
   }
   void operator=(const CommercialVehicle &obj ) {
   }
protected:
   bool verbose_;
public:
   CommercialVehicle(void){
       vehicleRegistration_ = NULL;
       operatorID_ = NULL;
       operatorCDL_ = NULL;
       passengerCapacity_ = 0;
       verbose_ = 0;
   }

   CommercialVehicle(const char* registration , const char* operatorID , const char* operatorCDL , unsigned short passengerCapacity , bool verbose = 0)
   {
       vehicleRegistration_ = new char[strlen(registration) +1]();
       strncpy(vehicleRegistration_, registration, strlen(registration));

       operatorID_ = new char[strlen(operatorID) +1]();
       strncpy(operatorID_, operatorID, strlen(operatorID));

       operatorCDL_ = new char[strlen(operatorCDL) +1]();
       strncpy(operatorCDL_, operatorCDL, strlen(operatorCDL));

       passengerCapacity_ = passengerCapacity;
       verbose_ = verbose;
   }

   ~CommercialVehicle(){
       delete   vehicleRegistration_;
       delete operatorID_ ;
       delete operatorCDL_;
   }

   const char* Registration () const ; // returns vehicle registration number
   const char* Operator () const ; // returns operator ID   
   const char* CDL () const ; // returns operator CDL
   unsigned int PassengerCapacity () const ; // returns passenger capacity
   float LoadCapacity () const ; // returns volume or area of cargo space
   const char* ShortName () const ; // returns "UNK"
   static VehicleType RegDecode (const char* sn);
};

class Carriage : public CommercialVehicle
{
   Carriage(const Carriage &obj)
   {
   }
   void operator=(const Carriage &obj ) {
   }
public:
   Carriage()
   {
   }
   Carriage(const char* registration , const char* operatorID , const char* operatorCDL , unsigned short passengerCapacity , bool verbose = 0)
       : CommercialVehicle(registration , operatorID , operatorCDL , passengerCapacity , verbose )
   {
   }

   ~Carriage(void)
   {
   }
   const char* ShortName() const
   {
       return "CAR";
   }
};

class Bus : public CommercialVehicle
{
   Bus(const Bus &obj)
   {
   }
   void operator=(const Bus &obj )
   {
   }
public:
   Bus(void){
   }
   Bus(const char* registration , const char* operatorID , const char* operatorCDL , unsigned short passengerCapacity , bool verbose = 0)
       : CommercialVehicle(registration , operatorID , operatorCDL , passengerCapacity , verbose )
   {
   }
   ~Bus(void){}
   const char* ShortName() const
   {
       return "BUS" ;
   }

};

class Limo : public CommercialVehicle
{
   Limo(const Bus &obj)
   {
   }
   void operator=(const Limo &obj )
   {
   }
public:
   Limo(void);
   Limo(const char* registration , const char* operatorID , const char* operatorCDL , unsigned short passengerCapacity , bool verbose = 0)
       : CommercialVehicle(registration , operatorID , operatorCDL , passengerCapacity , verbose )
   {
   }
   ~Limo(void);
   const char* ShortName() const
   {
       return "LIM" ;
   }
};

class Truck : public CommercialVehicle
{
   Truck(const Truck &obj)
   {
   }
   void operator=(const Truck &obj )
   {
   }
public:
   Truck(void);
   Truck(const char* registration , const char* operatorID , const char* operatorCDL , bool verbose = 0)
       : CommercialVehicle(registration, operatorID, operatorCDL,0, verbose)
   {
   }
   ~Truck(void){}
   const char* ShortName() const
   {
       return "TRK" ;
   }

};

class Van : public CommercialVehicle, public Shape
{
   Van(const Van &obj)
   {
   }
   void operator=(const Van &obj )
   {
   }
public:
   Van(void)
   {
   }

   Van(const char* registration , const char* operatorID , const char* operatorCDL , float width , float length , float height , bool verbose = 0 )
       : CommercialVehicle(registration, operatorID, operatorCDL,0,verbose), Shape(width,length,height,verbose)
   {
   }
   ~Van(void);
   float LoadCapacity() const
   {
       return Volume();
   }
   const char* ShortName() const { return "VAN" ; }
};

class Tanker : public Truck, public Cylinder
{
   Tanker(const Tanker &obj)
   {
   }
   void operator=(const Tanker &obj )
   {
   }
public:
   Tanker(void){}
   ~Tanker(void);
  
   Tanker(const char* registration , const char* operatorID , const char* operatorCDL , float radius , float length , bool verbose=0):
  
   Truck(registration,operatorID,operatorCDL,verbose),
       Cylinder(radius, length, verbose)
   {
   }
  
   float LoadCapacity() const
   {
       return Volume();
   }

   const char* ShortName() const   
   {
       return "TNK";
   }
};

class Flatbed : public Truck, public Rectangle
{
   Flatbed(const Flatbed &obj)
   {
   }
   void operator=(const Flatbed &obj )
   {
   }
public:
   Flatbed(void){
   }
   Flatbed(const char* registration , const char* operatorID , const char* operatorCDL , float width , float length , bool verbose=0)
       :Truck(registration,operatorID,operatorCDL,verbose),Rectangle(width, length,verbose)
   {
   }
   ~Flatbed(void);

   float LoadCapacity() const
   {
       Area();// returns volume of rectangle
   }
   const char* ShortName() const
   {
       return "FLT";
   }
};

//CommercialVehicle.cpp

#include "StdAfx.h"
#include "CommercialVehicle.h"

CommercialVehicle::~CommercialVehicle(void)
{
}

const char* CommercialVehicle::Registration() const
{
   return vehicleRegistration_;
}

const char* CommercialVehicle::Operator() const
{
   return operatorID_;
}

const char* CommercialVehicle::CDL() const {
   return operatorCDL_;
}
unsigned int CommercialVehicle::PassengerCapacity () const
   {
       return passengerCapacity_;
}
float CommercialVehicle::LoadCapacity() const
{
   return 0.0;
}
const char* CommercialVehicle::ShortName() const
{
   return "UNK";
}

VehicleType CommercialVehicle::RegDecode(const char* sn)
{

return static_cast<VehicleType>(sn[0]);

}

//Shape.h

#pragma once
class Shape
{
   float x_, y_, z_; // dimensions of shape
   bool verbose_; // default value 0 given in constructor prototype
   Shape(const Shape &obj)
   {
   }
   void operator=(const Shape &obj )
   {
   }
public:
   Shape(){
       x_ = 0;
       y_ = 0;
       z_ = 0;
       verbose_ = 0;
   }
   Shape(float x , float y , float z, bool verbose){
       x_ = x;
       y_ = y;
       z_ = z;
       verbose_ = verbose;
   }
   ~Shape(void);
   const char* Name () const
       {
           return "generic";
   }
   float Volume () const
   {
   }
   float Area () const {
   }
};

class Box : public Shape
{
   float width_ ;
   float length_ ;
   float height_ ;
   bool verbose_;
   Box(const Box &obj)
   {
   }
   void operator=(const Box &obj )
   {
   }
public:
   Box(){
       width_ = 0;
       length_ = 0;
       height_ = 0;
       verbose_ = 0;
   }
   Box(float width , float length , float height , bool verbose)
   {
       width_ = width;
       length_ = length;
       height_ = height;
       verbose_ = verbose;
   }

   ~Box(void);
   const char* Name () const
   {
       return "box";
   }
   float Volume () const
       {
           //returns volume of box object
           return width_*length_*height_;
   }
   float Area () const
   {
       return 2*length_*width_ + 2*length_*height_ + 2* height_*width_;
   }
};

class Cylinder : public Shape
{
   float radius_;
   float height_;
   bool verbose_;
   Cylinder(const Cylinder &obj)
   {
   }
   void operator=(const Cylinder &obj )
   {
   }
public:
   Cylinder(void)
   {
       radius_ = 0;
       height_ = 0;
       verbose_ = 0;
   }
   Cylinder(float radius , float height , bool verbose)
   {
       radius_ = radius;
       height_ = height;
       verbose_ = verbose;
   }
   ~Cylinder(void);
   const char* Name () const
   {
       return "cylinder";
   }
   float Volume () const {
       // returns volume of cylinder object
       float pie = 3.14;
       return pie*radius_*radius_*height_;
   }
   float Area () const
   {
       // returns surface area of cylinder object
       //2rh+2r2
       float pie = 3.14;
       return 2*pie*radius_*height_ + 2*pie*radius_*radius_;
   }

};

class Rectangle : public Shape
{
   float width_ ;
   float length_ ;
   bool verbose_ ;
   Rectangle(const Rectangle &obj)
   {
   }
   void operator=(const Rectangle &obj )
   {
   }
public:
   Rectangle(void)
   {
       width_ = 0;
       length_ = 0;
       verbose_ = 0;
   }
   Rectangle(float width , float length , bool verbose)
   {
       width_ = width;
       length_ = length;
       verbose_ = verbose;
   }

   ~Rectangle(void);
   const char* Name () const
   {
       return "rectangle";
   }
   float Area () const {
       return width_*length_;
   }
};

//Shape.cpp

#include "StdAfx.h"
#include "Shape.h"


const char* Shape::Name() const
{
   return "generic";
}


Shape::~Shape(void)
{
}