Write a C++ program to find out the student details and sport score using hybrid inheritance.




Program Algorithm:
Step 1: Include the header files
Step 2: Declare the base class stu.
Step 3: Declare and define the function get_ no () and put_no().
Step 4: Declare the derived class test for stu
Step 5: Declare and define the function get_ mark () and put_marks().
Step 6: Declare another base class sports
Step 7: Declare and define the function \getscore () and putscore ()
Step 8: Declare the derived class result from test and sports
Step 9: Declare and define the function display ()
Step 8: Create objects for the derived class.
Step 9: Declare the derived class object, call the functions get_ no ( ),get_ mark ( ),getsscore (),display ()




Program Code in C++:
#include<iostream.h>
#include<conio.h>
class stu
{
protected:
public:
{
rno=a;
}
int rno;
void get_no(int a)
void put_no(void)
{
cout<<"Roll no"<<rno<<"\n";
}
};
class test:public stu
{
protected:
float part1,part2;
public:
void get_mark(float x,float y)
{
part1=x;
part2=y;
}
void put_marks()
{
cout<<"Marks obtained:"<<"part1="<<part1<<"\n"<<"part2="<<part2<<"\n";
}
};
class sports
{
protected:
float score;
public:
void getscore(float s)
{
score=s;
}
void putscore(void)
{
cout<<"sports:"<<score<<"\n";
}
};
class result: public test, public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total=part1+part2+score;
put_no();
put_marks();
putscore();
cout<<"Total Score="<<total<<"\n";
}
int main()
{
clrscr(); result stu;
stu.get_no(523);
stu.get_mark(47.5,53.0);
stu.getscore(7.0);
stu.display();
return 0;
}





Program Output:
Roll no 523
Marks obtained: part1=47.5
Part2=53
Sports=6
Total score = 106.5

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: