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

View previous topic View next topic Go down

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

Post by iamdsc_0410 on 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;
}
avatar
iamdsc_0410

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

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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