HYBRID INHERITANCE

SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class student
{
  protected:
       int rollno;
  public:
    void getroll();
    void putroll();
};
void student::getroll()
{
  cout<<"\n Enter the Rollno:\t";
  cin>>rollno;
}
void student::putroll()
{
  cout<<"\n The Rollno is:\t"<<rollno;
}
class subject:public student
{
  protected:
  int sub1,sub2;
  public:
    void getsub();
    void putsub();
};
void subject::getsub()
{
  cout<<"\n Enter the subject marks:\t";
  cin>>sub1>>sub2;
}
void subject::putsub()
{
  cout<<"\n\n Marks scored in Subjects:\t";
  cout<<sub1<<"\t"<<sub2<<"\n";
}
class sports
{
  protected:
  int spo;
  public:
    void getspo();
    void putspo();
};
void sports::getspo()
{
  cout<<"\n Enter the sports marks:\t";

  cin>>spo;
}
void sports::putspo()
{
  cout<<"\n Marks scored in Sports:\t"<<spo<<"\n";
}
class result:public subject,public sports
{
  int res;
  public:
    void input();
    void calculate();
    void output();
};
void result::input()
{
  getroll();
  getsub();
  getspo();
}
void result::calculate()
{
  res=sub1+sub2+spo;
}
void result::output()
{
 putroll();
 putsub();
 putspo();
 cout<<"\n Total Result:\t"<<res;
}
void main()
{
 result R;
 clrscr();
 R.input();
 R.calculate();
 R.output();
 getch();
}

OUTPUT:

 Enter the Rollno:      5089

 Enter the subject marks:       90      90

 Enter the sports marks:        75










 The Rollno is: 5089

 Marks scored in Subjects:      90      90

 Marks scored in Sports:        75

 Total Result:  255
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: