Multilevel Inheritance
Multilevel Inheritance
#include <iostream.h>
class student
{
protected:
int roll;
public:
void getno();
int putno();
};
void student::getno()
{
cout<<"enter roll numbe"<<endl;
cin>>roll;
}
int student::putno()
{
return(roll);
}
void test::getmark()
{
cout<<"enter mark"<<endl;
cin>>mark1>>mark2;
}
void test::putmark()
{
cout<<mark1<<"\n"<<mark2;
}
int total;
public:
void display();
};
void result::display()
{
total = mark1+mark2;
cout<<"rollno:"<<putno()<<"\n"<<"marks"<<"\n";
putmark();
cout<<"total\n"<<total<<endl;
}
void main()
{
result stdx;
stdx.getno();
stdx.getmark();
stdx.display();
}
MULTIPLE INHERITANCE
class m
{
protected:
int a;
public:
void get1();
};
void m::get1()
{
cout<<"enter number1"<<"\n";
cin>>a;
}
class n
{
protected:
int b;
public:
void get2();
};
void n::get2()
{
cout<<"enter number2"<<"\n";
cin>>b;
}
class p:public m,public n
{
int c;
public:
void mul();
};
void p::mul()
{
cout<<"result is "<<a*b;
}
void main()
{
p data;
data.get1();
data.get2();
data.mul();
}
HYBRID INHERITANCE
#include <iostream.h>
class student
{
protected:
int roll;
public:
void getno();
};
void student::getno()
{
cout<<"enter roll"<<"\n";
cin>>roll;
}
void test::getmark()
{
cout<<"enter marks"<<"\n";
cin>>mark1>>mark2;
}
class sports
{
protected:
int weight;
public:
void getweight();
};
void sports::getweight()
{
cout<<"enter weightage"<<"\n";
cin>>weight;
}
public:
void display();
};
void result::display()
{
total = mark1+mark2+weight;
cout<<"total is "<<total;
}
void main()
{
result study;
study.getno();
study.getmark();
study.getweight();
study.display();
}
class student
{
protected:
int roll;
public:
void getno();
};
void student::getno()
{
cout<<"enter number"<<"\n";
cin>>roll;
}
void test::getmarks()
{
cout<<"enter marks"<<"\n";
cin>>mark1>>mark2;
}
void sports::getweight()
{
cout<<"enter weightage"<<"\n";
cin>>weight;
}
void result::display()
{
cout<<"\n"<<"the sum is "<<(mark1+mark2+weight)<<"\n";
}
void main()
{
result student;
student.getno();
student.getmarks();
student.getweight();
student.display();
}