IP6: Write a C++ program that uses the concept of hybrid inheritance.
Page 1 of 1
IP6: Write a C++ program that uses the concept of hybrid inheritance.
- Code:
#include<iostream>
using namespace std;
class Student
{
protected:
int roll;
public:
void getr()
{
cout<<"Enter the roll no.\n";
cin>>roll;
};
void dispr()
{
cout<<"Roll Number : "<<roll<<endl;
}
};
class Test:public Student
{
protected:
int marks1,marks2;
public:
void getmarks()
{
cout<<"Enter the marks in the two subjects \n";
cin>>marks1>>marks2;
}
void dispmarks()
{
cout<<"Marks in 1st subject : "<<marks1;
cout<<"\nMarks in 2nd subject : "<<marks2<<endl;
}
};
class Sports
{
protected:
int score;
public:
void getscore()
{
cout<<"Enter your scores :\n";
cin>>score;
}
void dispscore()
{
cout<<"Scores : "<<score<<endl;
}
};
class Result:public Test,public Sports
{
private:
int total;
public:
void disp()
{
total=marks1+marks2+score;
dispr();
dispmarks();
dispscore();
cout<<"Total : "<<total<<endl;
}
};
int main()
{
Result R;
R.getr();
R.getmarks();
R.getscore();
R.disp();
return 0;
}
iamdsc_0410- Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum