#include <iostream>
using namespace std;
// Base class
class Vehicle {
protected:
int wheels; // Number of wheels
int range; // Range of the vehicle in kilometers
public:
// Constructor to initialize Vehicle
Vehicle(int w, int r) : wheels(w), range(r) {}
// Function to display Vehicle details
void displayVehicleInfo() {
cout << "Wheels: " << wheels << endl;
cout << "Range: " << range << " km" << endl;
}
};
// Derived class: Car
class Car : public Vehicle {
int passengers; // Number of passengers
public:
// Constructor to initialize Car
Car(int w, int r, int p) : Vehicle(w, r), passengers(p) {}
// Function to display Car details
void displayInfo() {
cout << "Car Information:" << endl;
displayVehicleInfo();
cout << "Passengers: " << passengers << endl;
}
};
// Derived class: Truck
class Truck : public Vehicle {
int loadLimit; // Load limit in kilograms
public:
// Constructor to initialize Truck
Truck(int w, int r, int l) : Vehicle(w, r), loadLimit(l) {}
// Function to display Truck details
void displayInfo() {
cout << "Truck Information:" << endl;
displayVehicleInfo();
cout << "Load Limit: " << loadLimit << " kg" << endl;
}
};
int main() {
// Creating a Car object
Car car(4, 500, 5); // 4 wheels, 500 km range, 5 passengers
car.displayInfo();
cout << endl;
// Creating a Truck object
Truck truck(6, 1000, 15000); // 6 wheels, 1000 km range, 15000 kg load limit
truck.displayInfo();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gQmFzZSBjbGFzcwpjbGFzcyBWZWhpY2xlIHsKcHJvdGVjdGVkOgogICAgaW50IHdoZWVsczsgLy8gTnVtYmVyIG9mIHdoZWVscwogICAgaW50IHJhbmdlOyAgLy8gUmFuZ2Ugb2YgdGhlIHZlaGljbGUgaW4ga2lsb21ldGVycwoKcHVibGljOgogICAgLy8gQ29uc3RydWN0b3IgdG8gaW5pdGlhbGl6ZSBWZWhpY2xlCiAgICBWZWhpY2xlKGludCB3LCBpbnQgcikgOiB3aGVlbHModyksIHJhbmdlKHIpIHt9CgogICAgLy8gRnVuY3Rpb24gdG8gZGlzcGxheSBWZWhpY2xlIGRldGFpbHMKICA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