Practical-20
Define a class student having roll_number as data member and two functions get_number() and put_number(). Derive a class test from class student having marks of two subjects and two member functions two get and display marks. Derive a class result from class test having total_marks as data member and a display function.
using namespace std;
class student
{
protected:
int roll_number;
public:
void get_number();
void put_number();
};
void student::get_number()
{
cout<<"Enter roll number";
cin>>roll_number;
}
void student::put_number()
{
cout<<"Roll_number="<<roll_number<<"\n";
}
class test:public student
{
protected:
int mark[2],i;
public:
void get_marks();
void put_marks();
};
void test::get_marks()
{
for(i=0;i<2;i++)
{
cout<<"Enter marks of subject "<<i+1<<" : ";
cin>>mark[i];
}
}
void test::put_marks()
{
for(i=0;i<2;i++)
{
cout<<"marks of subject "<<i+1<<" : "<<mark[i]<<"\n";
}
}
class result:public test
{
int total_marks=0;
public:
void total();
};
void result::total()
{
for(i=0;i<2;i++)
{
total_marks=total_marks+mark[i];
}
cout<<"total_marks="<<total_marks;
}
int main()
{
result r;
r.get_number();
r.put_number();
r.get_marks();
r.put_marks();
r.total();
}
No comments:
Post a Comment