/*Write a program that defines a base class Vehicle with a constructor that takes a make and model parameter.
Derive two classes Car and Truck from Vehicle, each with a constructor that takes additional parameters.
Implement a virtual function printInfo() in the base class that prints the make and model of the vehicle,
and override the function in the derived classes to include additional information specific to cars and trucks.
Create an array of Vehicle pointers and populate it with instances of Car and Truck.
Iterate through the array and call the printInfo() function on each object*/
#include <iostream>
using namespace std;
// BASE classCLASS
class VEHICLE {
public:
string brand ="Mercedes-Benz";
void honk(){
cout<<"welcome in \n";
}
};
// derived class car
class car : public VEHICLE {
public:
string model = "Maserati";
};
// derived class truck
class truck : public VEHICLE {
public:
string model = "Tourismo demonstrator";
};
int main()
{
car mycar;
truck mytruck;
mycar.honk();
cout<< mycar.brand+" "+ mycar.model<<endl;
cout<< mytruck.brand +" "+ mytruck.model;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: