Created
June 29, 2012 20:41
-
-
Save dadarek/3020517 to your computer and use it in GitHub Desktop.
C++ Car
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
#include <iostream> | |
using namespace std; | |
class Engine | |
{ | |
public: | |
Engine(){ | |
cout << "Engine constructor" << endl; | |
} | |
void run() | |
{ | |
cout << "I'm running ..." << endl; | |
} | |
}; | |
class Wheels | |
{ | |
public: | |
Wheels(){ | |
cout << "Wheel constructor" << endl; | |
} | |
void spin() | |
{ | |
cout << "I'm spinning ... " << endl; | |
} | |
}; | |
class Doors | |
{ | |
public: | |
Doors(){ | |
cout << "Doors constructor" << endl; | |
} | |
void open() | |
{ | |
cout<< "I am opening the doors" << endl; | |
} | |
}; | |
class Car | |
{ | |
public: | |
Wheels* wheels; | |
Engine engine; | |
Doors* doors; | |
}; | |
int main() | |
{ | |
Wheels wheels; | |
Doors doors; | |
Car car; | |
car.wheels = &wheels; | |
car.doors = &doors; | |
car.wheels->spin(); | |
car.engine.run(); | |
car.doors->open(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment