PROGRAM TO IMPLEMENT VIRTUAL BASE CLASS

PROGRAM TO IMPLEMENT VIRTUAL BASE CLASS.

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

class student
{
 protected: int rollno;
 public: void get_no();
           void put_no();
};
void student::get_no()
{
 cout<<"\n enter the roll no  :";
 cin>>rollno;
}
void student::put_no()
{
 cout<<"\n roll no is  :"<<rollno;
}

class test :virtual public student
{
 protected: float sub1,sub2;
 public: void get_marks();
           void put_marks();
};
void test:: get_marks()
{
 cout<<"\n enter the marks in two subjects  :";
 cin>>sub1>>sub2;
};
void test:: put_marks()
{
 cout<<"\n marks in sub1  :"<<sub1;
 cout<<"\n marks in sub2  :"<<sub2;
}
class sports:public virtual student
{
 protected: float score;
 public: void get_score()
           {
             cout<<"\n enter the score  :";
             cin>>score;
           }
           void put_score()
           {
            cout<<"\n sports score  :"<<score;
           }


};

class result: public test,public sports
{
 float total;
 public: void display();
};
void result:: display()
{
 total=sub1+sub2+score;
 put_no();
 put_marks();
 put_score();
 cout<<"\n total= "<<total;
}
void main()
{
 clrscr();
 result student1;
 student1.get_no();
 student1.get_marks();
 student1.get_score();
 student1.display();
 getch();

}

OUTPUT:-



Share this

Related Posts

Previous
Next Post »

Powered by Blogger.

Popular Posts