#include <iostream>
#include <string>
using namespace std;
// Base class Vehicle
class Vehicle {
protected:
int numberOfWheels;
double range;
public:
Vehicle(int wheels, double range) : numberOfWheels(wheels), range(range) {}
virtual void display() const {
cout << "Number of Wheels: " << numberOfWheels << ", Range: " << range << " km" << endl;
}
};
// Derived class Car
class Car : public Vehicle {
int numberOfPassengers;
public:
Car(int wheels, double range, int passengers)
: Vehicle(wheels, range), numberOfPassengers(passengers) {}
void display() const override {
Vehicle::display();
cout << "Number of Passengers: " << numberOfPassengers << endl;
}
};
// Derived class Truck
class Truck : public Vehicle {
double loadLimit;
public:
Truck(int wheels, double range, double load)
: Vehicle(wheels, range), loadLimit(load) {}
void display() const override {
Vehicle::display();
cout << "Load Limit: " << loadLimit << " kg" << endl;
}
};
int main() {
// Creating instances of Car and Truck
Car myCar(4, 500, 5);
Truck myTruck(6, 800, 10000);
// Displaying information
cout << "Car Information:" << endl;
myCar.display();
cout << endl;
cout << "Truck Information:" << endl;
myTruck.display();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIEJhc2UgY2xhc3MgVmVoaWNsZQpjbGFzcyBWZWhpY2xlIHsKcHJvdGVjdGVkOgogICAgaW50IG51bWJlck9mV2hlZWxzOwogICAgZG91YmxlIHJhbmdlOwoKcHVibGljOgogICAgVmVoaWNsZShpbnQgd2hlZWxzLCBkb3VibGUgcmFuZ2UpIDogbnVtYmVyT2ZXaGVlbHMod2hlZWxzKSwgcmFuZ2UocmFuZ2UpIHt9CgogICAgdmlydHVhbCB2b2lkIGRpc3BsYXkoKSBjb25zdCB7CiAgICAgICAgY291dCA8PCAiTnVtYmVyIG9mIFdoZWVsczogIiA8PCBudW1iZXJPZldoZWVscyA8PCAiLCBSYW5nZTogIiA8PCByYW5nZSA8PCAiIGttIiA8PCBlbmRsOwogICAgfQp9OwoKLy8gRGVyaXZlZCBjbGFzcyBDYXIKY2x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