Sunday, January 26, 2014

C++ Program to Demonstrate Hybrid Inheritance

with 0 Comment
C++ Program to Demonstrate Hybrid Inheritance:

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number=a;
}
void put_number(void)
{
cout<<"Roll No: "<<roll_number<<"\n";
}
};

class test:public student
{
protected:
float part1,part2;
public:
void get_marks(float x,float y)
{
part1=x;
part2=y;
}
void put_marks(void)
{
cout<<"Marks Obtained: "<<"\n";
cout<<"Part1= "<<part1<<"\n";
cout<<"Part2= "<<part2<<"\n";
}
};
class sports
{
protected:
float score;
public:
void get_score(float s)
{
score=s;
}
void put_score(void)
{
cout<<"Sports wt: "<<score<<"\n\n";
}
};
class result:public test,public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total=part1+part2+score;
put_number();
put_marks();
put_score();
cout<<"Total Score: "<<total<<"\n";
}
int main()
{
clrscr();
result student_1;
student_1.get_number(1234);
student_1.get_marks(27.5,33.0);
student_1.get_score(6.0);
student_1.display();
getch();
return 0;
}

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive