Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

IP6: Write a C++ program that uses the concept of hybrid inheritance.

Go down

IP6: Write a C++ program that uses the concept of hybrid inheritance. Empty IP6: Write a C++ program that uses the concept of hybrid inheritance.

Post by iamdsc_0410 Sun May 14, 2017 10:55 am

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
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum