You are on page 1of 5

Program 8

Objective : Define a class SCHOOL with the following details:


Private members: sname of type string, sfees of type integer
Public members: void SINPUT() to enter details
Void SOUTPUT() to display details
Define a class BUS with the following details:
Private members: bno of type integer, bfess of type integer
Public members: void BINPUT() to enter details
Void BOUTPUT() to display dtails
Define another class STUDENT privately deriving from class SCHOOL and publicily deriving from class
BUS with the following details:
Private members: name of type string, totfee of type integer
Protected members: int calc() to calculate and return totfee as the sum of sfees and bfees
Public members: void IN() to enter details
Void OUT() to display details
Develop a complete C++ program to enter details of n students and then display all the details on the
screen.

Source code:
#include<iostream.h>
#include<conio.h>
class SCHOOL
{char sname[25];
int sfees;
public:
void SINPUT()
{cout<<"\n\tEnter the school name:";
cin>>sname;
cout<<"\tEnter the school fees:";
cin>>sfees;
}

void SOUTPUT()
{cout<<sname<<"\t"<<sfees<<"\t\t";
}
int Schoolfees()
{
return sfees;
}
};
class BUS
{int bno,bfees;
public:
void BINPUT()
{cout<<"\tEnter the bus number:";
cin>>bno;
cout<<"\tEnter the bus fees:";
cin>>bfees;
}
void BOUTPUT()
{cout<<bno<<"\t"<<bfees<<"\t";
}
int Busfees()
{
return bfees;
}
};

class STUDENT:private SCHOOL,public BUS


{char name[25];
int totfee;

protected:
int calc()
{
return(Schoolfees()+Busfees());
}
public:
void IN()
{cout<<"\n\tEnter the student's name:";
cin>>name;
SINPUT();
BINPUT();
totfee=calc();
}
void OUT()
{cout<<name<<"\t\t";
SOUTPUT()
BOUTPUT();
cout<<totfee<<endl;
}
}S[10];

int main()
{int n;
cout<<"\nEnter the number of students whose details are to be
cin>>n;
for(int i=0;i<n;++i)
S[i].IN();
cout<<"\n\nStudent name\tSchool\tSchool fee\tBus no\tBus fee\tTotal fee\n";
for(int i=0;i<n;++i)

entered:";

S[i].OUT();
getch();
return 0;
}

OUTPUT:

Enter the number of students whose details are to be entered: 3

Enter the student's name: Afrah

Enter the school name: ENS


Enter the school fees: 840
Enter the bus number: 11
Enter the bus fees: 200

Enter the student's name: Maria

Enter the school name: DPS


Enter the school fees:1500
Enter the bus number: 34
Enter the bus fees: 300

Enter the student's name: Munaiza

Enter the school name: IES


Enter the school fees:750
Enter the bus number:45
Enter the bus fees:150

Student name

School School fee

Afrah

ENS

840

Maria

DPS

1500

34

300

1800

750

45

150

900

Munaiza

IES

11

Bus no Bus fee Total fee


200

1040

You might also like