TYPE OF DERIVATION THROUGH MULTILEVEL INHERITENCE
#include#include
#include
class student
{
protected:
char name[30];
char enroll[8];
public:
void input()
{
cout<<"Enter name of student";
gets(name);
cout<<"ENter enroll";
gets(enroll);
}
void output()
{
cout<<"Name of student is... "<
};
class course:public student
{
protected:
char cours[6];
public:
void input()
{
student::input();
cout<<"Enter course of student";
gets(cours);
}
void output()
{ student::output();
cout<<"Name of course is... "<
};
class subject:protected course
{
protected:
char sub[20];
public:
void input()
{
course::input();
cout<<"Enter subject of student";
gets(sub);
}
void output()
{ course::output();
cout<<"Name of subject is... "< }
};
class marks:private subject
{
protected:
int markss;
public:
void input()
{
subject::input();
cout<<"Enter marks of student";
cin>>markss;
}
void output()
{ subject::output();
cout<<"Marks of subject is... "<
};
void main()
{
clrscr();
marks a;
a.input();
a.output();
getch();
}
BELOW PROGRAM SHOW HOW PUBLIC MEMBER BECOME PRIVATE AND ACCESS BY OTHER DERIVE CLASS
#include
#include
#include
class student
{
 protected:
 char name[30];
 char enroll[8];
 public:
 void input()
 {
   cout<<"Enter name of student";
   gets(name);
   cout<<"ENter enroll";
   gets(enroll);
 }
 void output()
   {
    cout<<"Name of student is... "<
    cout<<"Enroll of student is... "<
 
   }
};
class course:public student
{
 protected:
 char cours[6];
 public:   
  void input()
 {
   student::input();
   cout<<"Enter course of student";
   gets(cours);
 }
 void output()
 {  student::output();
    cout<<"Name of course is... "<
 
 }
};
class subject:protected course
{
 protected:
 char sub[20];
 public:
void input()
 {
   course::input();
   cout<<"Enter subject of student";
   gets(sub);
 }
 void output()
 {  course::output();
    cout<<"Name of subject is... "<
 }
};
class marks:private subject
{
 protected:
 int markss;
 public:
void input()
 {
   course::input();//here we can acces becouse input of course is protected
   // in subject class
   cout<<"Enter marks of student";
   cin>>markss;
 }
 void output()
 {  subject::output();
    cout<<"Marks of subject is... "<
 
 }
};
class sports:private marks
{
 protected:
 char sports_name[20];
 public:
void input()
 {
  // subject::input(); // here input function of subject private in marks
   //so it cannot access
   cout<<"Enter fav sports of student";
   gets(sports_name);
 }
 void output()
 {  marks::output();
    cout<<"fav sports of subject is... "<
 
 }
};
void main()
{
 clrscr();
 sports a;
 a.input();
 a.output();
 getch();
}
 
