Single Inheritance
#include
#include
class person
{
char name[10];
int age;
public:
void getperson(void)
{
cout<<"Enter
your Name and Age\n";
cin>>name>>age;
}
void dispersion(void)
{
cout<<"\n Name\t"<
cout<<"\nage\t"<
}
};
class mark: public person
{
int m1,m2;
public:
void getmark(void)
cout<<"\n Enter Mark1\t";
cin>>m1;
cout<<"\nEnter Mark2\t;
cin>>m2;
}
void dismark(void)
{
cout<<"\n Mark1"<
cout<<"\n Mark2"<
}
};
void main()
{
clrscr();
person p;
cout<<"\n Object created to class
person\n";
p.getperson();
p.disperson();
mark m1;
cout<<"\n Object created to class
mark\n";
m1.getperson();
m1.getmark();
m1.disperson();
m1.dismark();
getch();
}
Output
Object created to class person
Enter your Name and Age
Aruna
19
Name Aruna
Age 19
Object created to class mark
Enter your Name and Age
Hema
20
Enter Mark1 99
Enter Mark2 69
Name : Hema
Age : 20
Mark1 : 99
Mark2 : 69
Multiple Inheritances
#include
#include
class hosp
{
public:
char pname[20],sex[10];
int age;
void getdata()
{
cout<<"\t\t Vinayaga
Hospital";
cout<<"\t\t*****************************************\n";
cout<<"\n Enter the patient Name:
";
cin>>pname;
cout<<"\n Enter the age: ";
cin>>age;
}
void disp()
{
cout<<"\n\t"<
cout<<"\t"<
cout<<"\t"<
}
};
class ward
{
public:
char ill[15];
int ano,beno;
void getdata()
{
cout<<"\n Enter the ward no:
";
cin>>wano;
cout<<"\n Enter the bed no: ";
cin>>beno;
cout<<"\n Enter the nature of
illness: ";
cin>>ill;
}
void disp()
{
cout<<"\t"<
cout<<"\t"<
cout<<"\t"<
}
};
class dat: public ward, virtual public hosp
{
public:
char adda[10];
void getdata()
{
hosp::getdata();
ward::getdata();
cout<<"\n Enter the data of
admission: ";
cin>>adda;
}
void disp()
{
hosp::disp();
ward::getdata();
cout<<"\t"<
}
void opt()
{
cout<<"\n";
cout<<"\n\t\t Vinayaga
Hospital";
cout<<"\n\t\t***************************************";
cout<<"\n
Name\tSex\tAge\tWardno\tBedno\tReson\tDate";
cout<<"\n----------------------------------------------------------------";
}
};
void main()
{
clrscr();
int i,j;
char ch;
clrscr();
dat d[100],d1;
i=0;
start;
d[i].getdata();
++I;
getch();
d1.opt();
for(j=0;j
{
d[j].disp();
}
cout<<"\n Do u want to continue(Y /
N)? ";
cin>>ch;
if(ch==’y’)
{
clrscr();
goto start;
}
}
Output
Vinayaga
Hospital
*******************************
Enter the patient
name : Amutha
Enter the sex : Female
Enter the age : 28
Enter the ward no : 25
Enter the bed no : 3
Enter the natures
of illness : Eye problem
Enter the data of
Admission : 5.6.2010
Vinayaga Hospital
***********************************
Name Sex Age Wardno Bedno
Reson Date
--------------------------------------------------------------------------------------------
Amutha Female 28 25 3
Eye problem 5.6.11
Do u want to continue (Y/N)?
Multilevel Inheritance
#include
#include
class one
{
protected:
int x;
public:
one()
{
x=10;
}
void disp1()
{
cout<<""<
}
};
class two: public one
{
protected:
int y;
public:
two()
{
y=20;
}
void disp2()
{
cout<<""<
}
};
class three: public two
{
protected:
int z;
public:
three()
{
z=30;
}
void disp3()
{
cout<<""<
}
};
void main()
{
clrscr();
one obj1;
two obj2;
three obj3;
obj3.disp1();
obj3.disp2();
obj3.disp3();
getch();
}
Output
10
10 20
10 20 30
No comments:
Post a Comment