Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-inheritance/lab_vehicles1.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (53 sloc)
1.08 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef VEHICLES_H | |
#define VEHICLE_H | |
#include <iostream> | |
class Vehicle | |
{ | |
public: | |
const int wheels; | |
const bool motor; | |
Vehicle( int _wheels, bool _motor ) : wheels(_wheels), motor(_motor) | |
{} | |
void move() { std::cout << "Vehicle moving" << std::endl; } | |
}; | |
class Car: public Vehicle | |
{ | |
public: | |
const int doors; | |
Car( int _doors ) : doors(_doors), Vehicle( 4, true ) | |
{} | |
void open_door( int d ) | |
{ | |
if( d>0 && d<doors+1 ) | |
std::cout << "Opening door" << std::endl; | |
} | |
void rev() { std::cout << "Vrooom!" << std::endl; } | |
}; | |
class SmallCar: public Car | |
{ | |
public: | |
SmallCar() : Car( 2 ) {} | |
}; | |
class LargeCar: public Car | |
{ | |
public: | |
LargeCar() : Car( 4 ) {} | |
}; | |
class Bike: public Vehicle | |
{ | |
public: | |
Bike( bool _motor ) : Vehicle( 2, _motor ) {} | |
void do_wheelie() { std::cout << "Doing Wheelie!" << std::endl; } | |
}; | |
class Bicycle: public Bike | |
{ | |
public: | |
Bicycle() : Bike( false ) {} | |
}; | |
class MotorBike: public Bike | |
{ | |
public: | |
MotorBike() : Bike( true ) {} | |
void rev() { std::cout << "Vrooom!" << std::endl; } | |
}; | |
#endif | |