#include <iostream>
using namespace std;
class car
{
public:
virtual void showcar()=0;
};
class Hyundaicar : public car
{
public:
void showcar()
{
cout<<"Hyundai car is created"<<endl;
}
};
class Toyotacar : public car
{
public:
void showcar()
{
cout<<"Toyota Car is created"<<endl;
}
};
class bike
{
public:
virtual void showbike()=0;
};
class Hyundaibike : public bike
{
public:
void showbike()
{
cout<<"Hyundai Bike is created"<<endl;
}
};
class Toyotabike : public bike
{
public:
void showbike()
{
cout<<"Toyota Bike is created"<<endl;
}
};
class Vehiclefactory
{
public:
virtual car* createcar() = 0;
virtual bike* createbike() = 0;
};
class hyundaifactory : public Vehiclefactory
{
public:
car* createcar()
{
return new Hyundaicar();
}
bike* createbike()
{
return new Hyundaibike();
}
};
class toyotafactory : public Vehiclefactory
{
public:
car* createcar()
{
return new Toyotacar();
}
bike* createbike()
{
return new Toyotabike();
}
};
class vehiclebrandfactory
{
public:
static Vehiclefactory* getvehiclebrand(string brand)
{
Vehiclefactory* vh;
if(brand == "hyundai")
{
vh = new hyundaifactory();
}
else if(brand == "toyota")
{
vh = new toyotafactory();
}
return vh;
}
};
int main() {
string brandtype;
cout<<"enter the brand vehicle"<<endl;
cin>>brandtype;
Vehiclefactory *vehicleobj = vehiclebrandfactory:: getvehiclebrand(brandtype);
car* c = vehicleobj->createcar();
c->showcar();
bike* b = vehicleobj->createbike();
b->showbike();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: