Friday, 7 December 2012

Vehicle management cpp program

Cpp program to implement vehicle management


#include<iostream.h>
#include<conio.h>
class vehicle
{ protected:
          char vehname[15];
           int wheelcount;
  public:
          void getdata();
          void display();
};

class light:public vehicle
{ protected:
          int speedlmt;
  public:
          void getdata();
          void display();
};

class heavy:public vehicle
{ protected:
           int loadcapacity;
          char permit[15];

  public:
           void getdata();
           void display();
};

class gear:public light
{ protected:
          int gearcount;
  public:
          void getdata();
          void display();
};

class nongear:public light
{ public:
          void getdata();
          void display();
};
class passenger:public heavy
{ protected:
          int sitting;
          int standing;
  public:
          void getdata();
          void display();
};

class goods:public heavy
{ public:
          void getdata();
          void display();
};

void vehicle::getdata()
{        cout<<" Name of the Vehicle : ";
          cin>>vehname;
          cout<<" How many Wheels : ";
          cin>>wheelcount;
}

void vehicle::display()
{        cout<<vehname<<"\t\t"<<wheelcount<<"\t";
}
void light::getdata()
{        vehicle::getdata();
          cout<<" Speed Limit : ";
          cin>>speedlmt;
}

void light::display()
{        vehicle::display();
           cout<<" Light "<<"\t"<<speedlmt<<"\t--\t--\t";
}

void heavy::getdata()
{        vehicle::getdata();
          cout<<" Load Capacity : ";
          cin>>loadcapacity;
          cout<<" Permit Type : ";
          cin>>permit;
}

void heavy::display()
{        vehicle::display();
          cout<<" Heavy\t---\t"<<loadcapacity<<"\t"<<permit<<"\t";
}

void gear::getdata()
{        light::getdata();
          cout<<" Number of gears : ";
          cin>>gearcount;
}
void gear::display()
{        light::display();
          cout<<gearcount<<"\t--\t--"<<endl;
}

void nongear::getdata()
{        light::getdata();
}

void nongear::display()
{        light::display();
          cout<<"--\t--\t--"<<endl;
}

void passenger::getdata()
{        heavy::getdata();
          cout<<" Sitting Capacity : ";
          cin>>sitting;
          cout<<" Standing Capacity : ";
          cin>>standing;
}

void passenger::display()
{        heavy::display();
          cout<<"--\t"<<sitting<<'\t'<<standing<<endl;
}

void goods::getdata()
{        heavy::getdata();
}

void goods::display()
{        heavy::display();
          cout<<"--\t--\t--"<<endl;
}
void main()
{        gear glight;
          nongear nlight;
          passenger pheavy;
          goods gheavy;
          clrscr();
          cout<<" Enter the details of gear motor vehicle "<<endl;
          glight.getdata();
          cout<<" Enter the details of non-gear motor vehicle "<<endl;
          nlight.getdata();
          cout<<" Enter the details of passenger vehicle "<<endl;
          pheavy.getdata();
          cout<<" Enter the details of goods vehicle "<<endl;
          gheavy.getdata();
  cout<<"Name\t\tWheels\tType\tSpeed\tLoad\tPermit\tGear\tSit\tStand\n ";
          cout<<" --------------------------------------------------------------\n ";
          glight.display();
          nlight.display();
          pheavy.display();
          gheavy.display();
          getch();
}

No comments:

Post a Comment