Saturday, January 25, 2014

C++ Program to Implement the Concept of Hybrid Inheritance

with 0 Comment
HYBRID INHERITANCE
AIM:

  • To write a C++ program to implement the concept of Hybrid Inheritance.

ALGORITHM:
1. Start the program
2. Include suitable header files
3. Create a base class student and sports
4. In the base class student define the function void get number and put number
5. In the base class sports define the function void get score and void put score
6. Derive a class test form base student and define the function get mark and put mark
7. Derive a class result from test and sports class and define function void display
8. Get the value for get number ,get marks and get score function through main function
9. Call the display function in class result
10. Stop the program

CODING:
#include<iostream.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 obtined:"<<"\n"
<<"part1="<<part1<<"\n"
<<"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()
{
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();
return 0;
}

OUTPUT:
Roll no: 1234
Marks obtained:
Part1=27.5
Part2=33
Total score: 66.5

RESULT:

  • Thus to write a C++ program for Hybrid Inheritance was successfully completed.

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive