Dec 10, 2015

Program in C++ for hybrid inheritance

#include<iostream.h>
#include<conio.h>
class student
{
int regno;
char name[10];
public:
void input()
{
cout<<"Enter the regno & name : ";
cin>>regno>> name;
}
void output()
{
cout<<"\n Name :"<<name;
cout<<"\n Regno :"<<regno;
}
};
class test:public student
{
protected:
int m1,m2,m3;
public:
void input()
{
cout<<"\n Enter the 3 subject marks \n";
cin>>m1>>m2>>m3;
}
void output()
{
cout<<"\n subject1 marks :"<<m1;
cout<<"\n subject2 marks :"<<m2;
cout<<"\n subject3 marks :"<<m3;
}
};
class sports
{
protected:
int wt;
public:
void input()
{
cout<<"Enter the ports weightage \n";
cin>>wt;
}
void output()
{
cout<<"\n sports weightage :"<<wt;
}
};
class result:public test,sports
{
int total;
public:
void caltotal()
{
student::input();
test::input();
sports::input();
total=m1+m2+m3+wt;
clrscr();
student::output();
test::output();
sports::output();
cout<<"\n Total marks "<<total;
}
};
void main()
{
clrscr();
result r;
r.caltotal();
getch();
}

No comments:

Post a Comment