0% found this document useful (0 votes)
36 views2 pages

Virtual Base Class

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Virtual Base Class

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream.

h>
#include<conio.h>

class Student
{
protected:
int rno;
char name[20];
public:
void getData();
void putData();
};
void Student::getData()
{
cout<<"Enter roll number : ";
cin>>rno;
cout<<"Enter Name : ";
cin>>name;
}
void Student::putData()
{
cout<<"\n Roll No : "<<rno;
cout<<"\n Name : "<<name;
}
class Marks : virtual public Student
{
protected:
int mark1;
int mark2;
int mark3;
public:
void getMarks();
void putMarks();
};
void Marks::getMarks()
{
cout<<"Enter Mark1 : ";
cin>>mark1;
cout<<"Enter Mark2 : ";
cin>>mark2;
cout<<"Enter Mark3 : ";
cin>>mark3;
}
void Marks::putMarks()
{
cout<<"\nMark1 : "<<mark1;
cout<<"\nMark2 : "<<mark2;
cout<<"\nMark3 : "<<mark3;
}
class Sports : public virtual Student
{
protected:
int sub;
public:
void getSports();
void putSports();
};
void Sports::getSports()
{
cout<<"Enter sub : ";
cin>>sub;

}
void Sports::putSports()
{
cout<<"\n Sub : "<<sub;
}

class Result:public Marks,public Sports


{
protected:
float total;
float per;
public:
void display();
};
void Result::display()
{
total=mark1+mark2+mark3+sub;
per=total/4;
cout<<"\nTotal : "<<total;
cout<<"\n Per : "<<per;
}

int main()
{
clrscr();
Result ob;
ob.getData();
ob.getMarks();
ob.getSports();
ob.putData();
ob.putMarks();
ob.putSports();
ob.display();
getch();
return 0;
}

You might also like