#include <iostream>
#include <string>
class Vehicle {
protected:
double speed;
std::string direction;
public:
Vehicle(double s = 0, const std::string& d = "forward") : speed(s), direction(d) {}
virtual ~Vehicle() {}
double getSpeed() const { return speed; }
std::string getDirection() const { return direction; }
virtual void printInfo() const {
std::cout << "Speed: " << speed << " Direction: " << direction << std::endl;
}
};
class Car : public Vehicle {
private:
std::string fuelType;
public:
Car(double s, const std::string& d, const std::string& ft) : Vehicle(s, d), fuelType(ft) {}
~Car() override {}
void printInfo() const override {
std::cout << "Car - Speed: " << speed << " Direction: " << direction << " Fuel Type: " << fuelType << std::endl;
}
};
class Bicycle : public Vehicle {
private:
int numGears;
public:
Bicycle(double s, const std::string& d, int ng) : Vehicle(s, d), numGears(ng) {}
~Bicycle() override {}
void printInfo() const override {
std::cout << "Bicycle - Speed: " << speed << " Direction: " << direction << " Number of Gears: " << numGears << std::endl;
}
};
int main() {
Vehicle* vehicle1 = new Car(60, "north", "gasoline");
Vehicle* vehicle2 = new Bicycle(15, "east", 7);
vehicle1->printInfo();
vehicle2->printInfo();
delete vehicle1;
delete vehicle2;
return 0;
}