Sunday, January 1, 2012

Hybrid inheritence in 'C++'

Example



#include<iostream.h>
#include<conio.h>
class stud
{
protected:
char rno[10],nm[20],co[20];
int sm;
    
public:

void getdata()
{
    cout<<"ENTER ROLLNO:";
    cin>>rno;
    cout<<"ENTER NAME:";
    cin>>nm;
    cout<<"ENTER  COURSE:";
    cin>>co;
    cout<<"SEMESTER ::";
cin>>sm;
}

    };

class result:public stud
{
protected:
int total,m1,m2,m3;
float per;
public:
void insert()
{
cout<<"\nENTER MARKS OF THREE SUB:";
cin>>m1>>m2>>m3;
}
void display()
{
      total=m1+m2+m3;
      per=total/3;
      cout<<"\n===========STUDENT DETAIL=========\n";
      cout<<"ROLLNO   NAME   COURSE    SEMESTER      "<<endl;
      cout<<rno<<"\t"<<nm<<"\t"<<co<<"\t"<<sm<<endl;
      cout<<"\n=====STUDENT MARKS==============\n";
      cout<<"  MARKS1  MARKS2  MARKS3  TOTAL  PER"<<endl;
      cout<<rno<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<total<<"\t"<<per<<endl;
}
};
class sport
{
protected:
char gm[30],gr[10];
public:
void getdata1()
{
cout<<"\n\nEnter the game:";
cin>>gm;
cout<<"Enter the status:";
cin>>gr;
}
};
class report:public result,public sport
{
public:
void display()
{
result::display();
cout<<"\n======STUDENT GAME REPORT======\n";
cout<<" GAMENAME   STATUS"<<endl;
cout<<gm<<"\t\t"<<gr;
}
};




int main()
{
clrscr();
report s;
s.getdata();
s.insert();
s.getdata1();
clrscr();
s.display();
getch();
return 0;
}

No comments:

Post a Comment