2dix-The Student Choice
Log in Register now

Program for Composition concept in c++ ? (Run in Dev C++)

Develop a Program for Composition concept in c++ ? (Run in Dev C++)

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class dept{
public:
char name[10];
dept()
//cout<<"dept class created"<<endl;
strcpy(name,"abc");
}
~dept()
{
cout<<"dept class destroyed"<<endl;
}
};
class pro{
public:
int pid;
dept *d;
pro()
{
strcpy(d->name,"xyz");
pid=100;
// cout<<"prfessor class created"<<endl;
}
~pro()
{
cout<<"professor class destroyed but dept exists;"<<endl;
delete d;
}
};
main()
{
pro p;
getch();
}


Output:

dept class destroyed
professor class destroyed but dept exists;

Description: 

This program is made for clear the concept of composition in c++. in which more than one individual class makes a complex class i.e composition.

(by Dr. Ayush Vashishtha )

comments (0)

avatar