Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Vehicle {
- protected:
- string name;
- int year;
- public:
- Vehicle() {}
- Vehicle(string name, int year) {
- this->name = name;
- this->year = year;
- }
- Vehicle(const Vehicle & tmp) {
- this->name = tmp.name;
- this->year = tmp.year;
- }
- ~Vehicle() {}
- virtual void print() {
- cout << name << " " << year << endl;
- }
- };
- class MotorVehicle : public Vehicle {
- protected:
- double consume;
- int tyres;
- public:
- MotorVehicle() : Vehicle() {}
- MotorVehicle(string name, int year, double consume, int tyres) : Vehicle(name, year) {
- this->consume = consume;
- this->tyres = tyres;
- }
- MotorVehicle(const MotorVehicle &tmp) : Vehicle(tmp) {
- this->consume = tmp.consume;
- this->tyres= tmp.tyres;
- }
- virtual void print() override {
- cout << consume << " " << tyres << endl;
- }
- };
- int main() {
- Vehicle * v = new MotorVehicle("car", 2025, 20, 4);
- v->print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment