#include <iostream>
using namespace std;
class vehicle
{
public:
virtual void showvehicle()=0;
};
class Bus : public vehicle
{
public:
void showvehicle()
{
cout<<"Bus vehicle is created"<<endl;
}
};
class Cycle : public vehicle
{
public:
void showvehicle()
{
cout<<"Cycle vehicle is created"<<endl;
}
};
class Car : public vehicle
{
public:
void showvehicle()
{
cout<<"Car vehicle is created"<<endl;
}
};
class VehicleFactory
{
public:
static vehicle* getvehicle(string vehicletype)
{
vehicle *veh;
if(vehicletype == "Bus")
{
veh = new Bus;
}
else if(vehicletype == "Car")
{
veh = new Car;
}
else if(vehicletype == "Cycle")
{
veh = new Cycle;
}
return veh;
}
};
int main()
{
string vtype;
cout<<"Enter the type of vehicle"<<endl;
cin>>vtype;
vehicle *vh = VehicleFactory::getvehicle(vtype);
vh->showvehicle();
}
To embed this project on your website, copy the following code and paste it into your website's HTML: