Tuesday, 2 July 2013

PROGRAM TO IMPLEMENT THE VIRTUAL BASE CLASS

//PROGRAM TO IMPLEMENT THE VIRTUAL BASE CLASS
/*MADE BY KRISHNA AGARWAL*/
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
    protected:
    int roll_number;
    public:
    void getroll_number()
    {
        cout<<"please enter the roll no.\n";
        cin>>roll_number;
    }
    void putroll_number()
    {
        cout<<"\nthe roll_number is = "<<roll_number;
    }
};
class test:virtual public student
{
    protected:
    float part1, part2;
    public:
    void get_marks()
    {
        cout<<"\nenter the marks in part 1\n";
        cin>>part1;
        cout<<"\nenter the marks in part2\n";
        cin>>part2;
    }
    void put_marks()
    {
        cout<<"\nthe marks obtained are";
        cout<<"\nthe marks in part1 is = "<<part1;
        cout<<"\nthe marks in part2 is = "<<part2;
    }
};
class sports:public virtual student
{
    protected:
    float score;
    public:
    void get_score()
    {
        cout<<"\nenter the score\n";
        cin>>score;
    }
    void put_score()
    {
        cout<<"\nthe score is = "<<score;
    }
};
class result:public test, public sports
{
    float total;
    public:
    void display()
    {
        total=part1+part2+score;
        putroll_number();
        put_marks();
        put_score();
        cout<<"\ntotal result obtained is = "<<total;
    }
};
//------------------------------------
int main()
{
    result student1;
    student1.getroll_number();
    student1.get_marks();
    student1.get_score();
    student1.display();
    return 0;
}

1 comment: