Sunday, May 4, 2014

C++ inheritance program using virtual keyword in hybrid or single or multilevel inheritance




/*C++ inheritance program using virtual keyword in hybrid or single or multilevel inheritance*/

#include<iostream.h>
#include<conio.h>

using namespace std;

class student
{
public:
int roll;
void putroll()
{
cout<<"Enter your roll no :";
cin>>roll;
}
};


class test:virtual public student
{
     public:
     float sub1;
     float sub2;
void putsub()
{
     cout<<"Enter marks of two subjects: ";
     cin>>sub1>>sub2;
}
};


class Sports:virtual public student
{
     public:
     float score;
     void putscore()
     {
           cout<<"Enter Your score: ";
           cin>>score;
     }
};


class result :public virtual test,public virtual Sports
{
     public:
     float total;
     void display()
     {
           total=sub1+sub2;
           cout<<"Your roll no: "<<roll;
           cout<<"Marks is "<<total;
           cout<<"Score is "<<score;
     }
};


int main()
{
     result std1;
     std1.putroll();
     std1.putsub();
     std1.putscore();
     std1.display();
     getch();
}

No comments:

Post a Comment