Program to illustrates Virtual base class


#include<iostream.h>
#include<conio.h>
class student
{
protected :
       int roll_number;
public:
    void get_number(int a)
    {
        roll_number = a;
     }
     void put_number(void)
    {
         cout<<"Roll No.  : "<<roll_number<<endl;
     }
};


class test : virtual public student
{
 protected :
       float sem1, sem2;
public:
    void get_marks (float s1, float s2)
    {
        sem1 = s1 ;  sem2 =  s2;
     }
     void put_marks(void)
    {
         cout<<"Marks obtained   : "<<"\n"
             <<"Sem1 = " <<sem1<<"\n"
             <<"Sem2 = " <<sem2<<"\n";
     }
};


class sports : public virtual student
{
 protected :
       float score;
public:
    void get_score(float s)
    {
        score = s;
     }
     void put_score(void)
    {
         cout<<" Sports weight : "<<score<<"\n\n";
     }
};

class result : public test, public sports
{
float total;
public :
       void display(void);
};
 void result :: display (void)
{
total = sem1 + sem2 + score;
put_number( );
put_marks( );
put_score( );

cout<<"Total Marks : "<<total<<"\n";
}

void main( )
{
result R1;
R1.get_number(123);
R1.get_marks(1200,1000);
R1.get_score(150);
R1.display( );
getch( );
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|