0% found this document useful (0 votes)
74 views3 pages

PROJ13

This document discusses multiple inheritance in C++ and provides examples of defining classes for a person, student, and employee. It also includes a selection sort algorithm to sort an integer array. The main function demonstrates creating objects from the defined classes and calling their member functions to output the stored data.

Uploaded by

Gaurav Agrawal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views3 pages

PROJ13

This document discusses multiple inheritance in C++ and provides examples of defining classes for a person, student, and employee. It also includes a selection sort algorithm to sort an integer array. The main function demonstrates creating objects from the defined classes and calling their member functions to output the stored data.

Uploaded by

Gaurav Agrawal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

TO SHOW MULTIPLE INHERITANCE

#include<iostream.h>
SELECTION SORT IN
#include<conio.h>
class person

ARRAY
{
char name[20] ;
int age ;
public :
#include<iostream.h>
void read_data( ) ;
void display_data( ) ;
#include<conio.h> };
void selsort(int[ ],int) ;
class student:public person
{
void
int roll;main( )
int marks;
{ char grade;
public:
int ar[ 50 ] ,n;
void get_data( ) ;
charclrscr( );
compute_grade ();
void show_data( ) ;
cout<<"How Many Elements} Do ; You
Wantclass
To employee:public
Create ArraypersonWith ? " ;
{
cin>>n;
float bp ;
float hr ;
cout<<"Enter
float sal ; Array Elements..\n";
for(int i=0 ; i<n ; i++)
public:
void get_data( ) ;
{ cin>>ar[ i ] ; ) ;
float compute_salary(
void show_data( ) ;
} };
selsort(ar,n)) ;
void person::read_data(
{
cout<<"The
cout<<"\n Sorted Array
ENTER NAME :" ; Is .....\n";
cin>>name ;
for(i=0;i<n;i++)
cout<<"\n ENTER AGE :" ;
cout<<ar[
cin>>age ; i ]<<" ";
}
cout<<endl) ;
void person::display_data( }
{
cout<<"\n NAME :"<<name ;
cout<<"\n AGE :"<<age ;
}
voidvoid
selsort(int ar[ ],int
student::get_data( ) size)
{ read_data( ) ;
{ int cout<<"\n
small,pos,tmp;
ENTER ROLL NO.:";
cin>>roll ;
for (int i=0;i<size;i++)
cout<<"\n ENTER MARKS :";
small=ar[
cin>>marks i ]; ;
grade=compute_grade( ) }
pos=i;
char student::compute_grade( )
{ char gd ;
for (int j=i+1 ; j<size ; j++)
if(marks<200)
{ if(ar[
gd='D'j ]<small)
;
else
{
if(marks<240) small=ar[ j ] ;
gd='C' ;
if(marks<320)
pos=j ; }
gd='B' ; }
else
tmp=ar[
gd='A' ; i];
return(gd) ;
ar[ i ]= ar [pos]} ;
ar [pos]=tmp
void student::show_data( ) ;
{
cout<<"\n ROLL NO. :"<<roll ; }
cout<<"\n MARKS :"<<marks ;
cout<<"\n GRADE :"<<grade ; }

{
OUTPUT OF THE PROGRAM
void employee::get_data( )
read_data( ) ;
How Many Elements Do You Want To
cout<<"\n ENTER BASIC PAY :" ;
cin>>bp ;
Create Array With ?……. 7
cout<<"\n ENTER HOUSE RENT :" ;
cin>>hr ;

{
Enter Array Elements…
float employee::compute_salary( )
float total ;
6 2 7 9 3 5 1
total=bp+hr+2.5*bp ;
return(total) ;
The Sorted Array Is ……
void employee::show_data( )
}

{
cout<<"\n BASIC PAY :"<<bp ;
cout<<"\n HOUSE RENT :"<<hr ;
cout<<"\n SALARY:"<<sal ; }
1 2 3 5 6 7 9
void main( )
{
clrscr( ) ;
student ob1 ;
employee ob2 ;
ob1.get_data( ) ;
cout<<"\n STUDENT DATA IS:";
ob1.display_data( ) ;
ob1.show_data( ) ;
ob2.get_data( ) ;
cout<<"\n EMPLOYEE DATA IS:";
ob2.display_data( ) ;
ob2.show_data( ) ;
getch( ) ;
}

OUTPUT OF THE PROGRAM

ENTER NAME:SUMIT
ENTER ROLL NO.:42
ENTER MARKS :50

STUDENT DATA IS:


NAME:SUMIT
AGE:17
ROLL NO.:42
MARKS:50
GRADE:B

ENTER NAME:BHRIGU
ENTER AGE:17
ENTER BASIC PAY:25000
ENTER HOUSE RENT:1500

EMPLOYEE DATA IS :
NAME : BHRIGU
AGE : 17
BASIC PAY : 25000
HOUSE RENT : 1500
SALARY:89000

You might also like