Description: This program shows how virtual base class solves duplicate properties problem.
Code:
//Compiling Tool: Code::Block IDE with MinGW
//Program shows how virtual base class solves duplicate properties problem.
#include<iostream>
using namespace std;
class student
{
protected:
int roll_no;
public:
void get_no(int x)
{
roll_no=x;
}
void put_no()
{
cout<<"\nRoll Number:"<<roll_no;
}
};
class test: virtual public student
{
protected:
float sub_marks;
public:
void get_submarks(float y)
{
sub_marks=y;
}
void put_submarks()
{
cout<<"\nSubject Marks:"<<sub_marks;
}
};
class sports: public virtual student
{
protected:
float sp_marks;
public:
void get_spmarks(float z)
{
sp_marks=z;
}
void put_spmarks()
{
cout<<"\nSports Marks:"<<sp_marks;
}
};
class result: public test, public sports
{
float total_marks;
public:
void put_result()
{
total_marks=sub_marks+sp_marks;
put_no();
put_submarks();
put_spmarks();
cout<<"\nTotal Marks: "<<total_marks;
}
};
int main()
{
result R;
R.get_no(20);
R.get_submarks(75.6);
R.get_spmarks(81.2);
R.put_result();
return 0;
}
Output:
If you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.
Add your comments in below available comment box.
Note: Click these label/tags to view all related posts. Tags: C++Code
…till next post, bye-bye & take care.
No comments:
Post a Comment