You are on page 1of 2
Car Aggregation - Example ============================================ #include <string.h> #include <iostream.h> class Engine{ public: Engine(){} Engine(int p) {
Car Aggregation - Example
============================================
#include <string.h>
#include <iostream.h>
class Engine{
public:
Engine(){}
Engine(int p)
{
hp=p;
cout<<"\nEngine is Created";
}
int getHp(){return hp;}
private:
int hp;
};
class Body{
public:
Body(){}
Body(char *m)
{
strcpy(maker,m);
cout<<"\nBody is Created";
}
char *getMaker(){return maker;}
private:
char maker[20];
};
class Car{
public:
Car(){}
Car(int p,char *m):e(p),b(m){cout<<"\nCar is Created";}
void Print()
{
cout<<"\nEngine Hours Power is: "<<e.getHp();
cout<<"\nBody Maker is: "<<b.getMaker();
}
private:
Engine e;
Body b; }; void main() { int engPwr; char bMaker[20]; cout<<"\nEnter Hours Power of Engine: ";
Body b;
};
void main()
{
int engPwr;
char bMaker[20];
cout<<"\nEnter Hours Power of Engine: ";
cin>>engPwr;
cout<<"\nEnter the Name of Body Maker: ";
cin>>bMaker;
Car c(engPwr,bMaker);
c.Print();
cout<<endl;
}
http://www.ravianeducation.blogspot.com
FARHAN: 03008855006