Menu

Custom Search

C++ lab Program

/*
v)create the classes first,second and third with relation as shown:

class first{
protected:
int one;
first()
first(int)
void showone()
~first()}

class second{
protected :
int one;
second
second(int)
void showtwo()
~second()}

class third:public first,public second{
int three;
third()
third(int o,int tw,int th):first(0),second(tw)
void showthree()
~third?()
}
*/

#include
#include
class first
{
protected:
int one;
public:
first()
{
one=0;
cout< }
first(int a)
{
one=a;
cout< }
void showone()
{
cout< }
~first()
{
cout< }

};
class second
{
protected:
int two;
public:
second()
{
two=0;
cout< }
second(int a)
{
two=a;
cout< }
void showtwo()
{
cout< }
~second()
{
cout< }
};
class third:public second,public first
{
int three;
public:
third()
{
three=0;
cout< }
third(int o,int tw,int th):first(o),second(tw)
{
three=th;
cout< }
void showthree()
{
showone();
showtwo();
cout< }
~third()
{
cout< }
};
void main()
{
clrscr();
third t;
third t1(10,20,30);
t1.showthree();
getch();
}

/*
o/p:
default constructor for second base class
default constructor of first base class
Default constructor of derived class
parametrized of constructor second base class
parameterized constructor of first base class
Parameterized constructor of derived class
1=10
2=20
3=30
*/

No comments:

Post a Comment