You are on page 1of 2

Car Aggregation 1

============================================
#include <string.h>
#include <iostream.h>

class Ac{

public:

Ac(){cout<<"\nAC is Created....Blank Constructor";}


Ac(int t){ton=t;cout<<"\nAC is Created....Param
Constructor";}
int getAc(){return ton;}

private:

int ton;
};

class Engine{

public:

Engine(){cout<<"\nEngine is Created....Blank Constructor";}


~Engine(){cout<<"\nEngine is Destruted";}
Engine(int p){hp=p;cout<<"\nEngine is Created....Param
Constructor";}
int getHp(){return hp;}

private:

int hp;
};

class Body{

public:

Body(){cout<<"\nBody is Created....Blank Constructor";}


~Body(){cout<<"\nBody is Destruted";}
Body(char *m){strcpy(maker,m);cout<<"\nBody is
Created....Param Constructor";}
char *getMaker(){return maker;}
private:

char maker[20];
};

class Car{

public:

Car(){cout<<"\nCar is Created....Blank Constructor";}


~Car(){cout<<"\nCar is Destruted";}

Car(int p,char *m,int t):e(p),b(m)


{
a=new Ac(t);
cout<<"\nCar is Created....Param Constructor";
}

void Print()
{
cout<<"\nEngine Hours Power is: "<<e.getHp();
cout<<"\nBody Maker is: "<<b.getMaker();
//cout<<"\nAC of the car: "<<a.getAc()<<" ton";
}

private:

Engine e;
Body b;
Ac *a;
};

void main()
{

Car c(1000,"Saloon",4);
c.Print();
cout<<endl;
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006