Thursday, December 13, 2012

write a program multiple inheritance in c++


#include<iostream.h>
#include<conio.h>
class Student
{
protected:
int roll;
public:
void get_num(int);
void put_num();
};
void Student::get_num(int a)
{
roll=a;
}
void Student::put_num()
{
cout<<"Roll number is "<<roll<<"\n";
}
class Test
{
protected:
float sub1,sub2;
public:
void get_mks(float,float);
void put_mks();
};
void Test::get_mks(float a,float b)
{
sub1=a;sub2=b;
}
void Test::put_mks()
{
cout<<"marks in sub1= "<<sub1<<"\n";
cout<<"marks in sub2= "<<sub2<<"\n";
}
class Result:public Test,public Student
{
float total;
public:
void display();
};
void Result::display()
{
total=sub1+sub2;
put_num();
put_mks();
cout<<"total = "<<total<<"\n";
}
void main()
{
int r;
float s1,s2;
Result obj;
clrscr();
cout<<"enter the Roll no of Student\n";
cin>>r;
cout<<"\nenter the marks of the student in 2 subject\n";
cin>>s1>>s2;
obj.get_num(r);
obj.get_mks(s1,s2);
obj.display();
getch();
}

Output