#include <iostream.h>
#include <string.h>
/*----------------------Class Interfaces-------------------------*/
class A
{
int x;
public :
A(int); // Constructor
void display();
};
class B
{
char w[10];
int y;
public :
B(char*,int); // Constructor
void display();
};
class C // container class
{
A obj1; // object of class A
B obj2; // object of class B
int z;
public :
C(int,int,int,char*);
void display();
};
/*----------------------Class Implementations---------------------*/
// member function definitions for 'A'
A::A(int a)
{
x = a;
}
void A::display()
{
cout << "x = "<< x << "\n";
}
// member function definitions for 'B'
B::B(char* a, int b)
{
strcpy(w, a);
y = b;
}
void B::display()
{
cout << "w = " << w << "\n";
cout << "y = " << y << "\n";
}
// member function definitions for 'C'
C::C(int a, int b, int c, char* d): obj1(a), obj2(d,c)
{
z = b;
}
void C::display()
{
obj1.display();
obj2.display();
cout << "z = " << z << "\n";
}
/*----------------------Class definitions ends here---------------*/
void main(void)
{
C c(10,20,30,"God");
c.display();
}
0 comments:
Post a Comment