C++ Inheritance Programs
C++ Inheritance Programs
#include <iostream>
using namespace std;
class student
{
public:
char a[30];
int roll;
void get()
{
cout<<"Enter the name :"<<endl;
cin>>a;
cout<<"Enter the roll.no :"<<endl;
cin>>roll;
}
};
class mark
{
public:
int mark[4],i;
void in()
{
cout<<"Enter the marks :"<<endl;
for(i=0;i<4;i++)
{
cin>>mark[i];
}
}
};
class process:public student,public mark
{
public:
int t;
float avg;
void calc()
{
t=mark[0]+mark[1]+mark[2]+mark[3];
avg=t/4;
}
void dis()
{
cout<<"Name :"<<a<<endl;
cout<<"Roll.no :"<<roll<<endl;
cout<<"Marks entered :";
for(i=0;i<4;i++)
{
cout<<mark[i]<<" ";
}
cout<<endl;
cout<<"Total marks :"<<t<<endl;
cout<<"Average :"<<avg<<endl;
}
};
int main()
{
cout<<"\t\tStudent mark list using multiple inheritance"<<endl;
cout<<"\t\t____________________________________________"<<endl;
process v;
v.get();
v.in();
v.calc();
v.dis();
return 0;
#include<iostream>
#include<stdio.h>
#include<conio.h>
class Employee {
int eno;
char name[20], des[20];
// Private members cannot call from outside class.
public:
void getEmpDetails() {
cout << "\nEnter the Employee number:";
cin>>eno;
cout << "Enter the Employee name:";
cin>>name;
cout << "Enter the Employee designation:";
cin>>des;
}
void employee_display() {
cout <<"\nEmployee number:"<<eno;
cout <<"\nEmployee name:"<<name;
cout <<"\nEmployee designation:"<<des;
}
};
void getPayDetails() {
getEmpDetails();
cout << "Enter the Basic pay:";
cin>>bp;
cout << "Enter the Humen Resource Allowance:";
cin>>hra;
cout << "Enter the Dearness Allowance :";
cin>>da;
cout << "Enter the Profitablity Fund:";
cin>>pf;
calculate();
}
void calculate() {
np = bp + hra + da - pf;
}
void salary_display() {
employee_display();
cout <<"\nEmployee Basic pay:"<<bp;
cout <<"\nEmployee Humen Resource Allowance:"<<hra;
cout <<"\nEmployee Dearness Allowance:"<<da;
cout <<"\nEmployee Profitablity Fund:"<<pf;
cout <<"\nEmployee Net Pay:"<<np;
}
};
void display() {
salary_display();
cout <<"\nEmployee Bank Name:"<<bank;
cout <<"\nEmployee IFSC:"<<ifsc_code;
cout <<"\nEmployee Account
Number:"<<account_number<<endl;
}
};
int main() {
int i, n;
char ch;
BankCredit s[10];
cout << "Simple Multi Level Inheritance Example Program : Payroll
System \n";
cout << "Enter the number of employee:";
cin>>n;
for (i = 0; i < n; i++) {
cout << "\nEmployee Details # "<<(i+1)<<" : ";
s[i].getBankDetails();
}
for (i = 0; i < n; i++) {
s[i].display();
}
getch();
return 0;
}
Output
Simple Multi Level Inheritance Example Program : Payroll System
Employee Details # 1 :
Enter the Employee number:101
Enter the Employee name:MASTE
Enter the Employee designation:Er
Enter the Basic pay:26000
Enter the Humen Resource Allowance:1300
Enter the Dearness Allowance :1200
Enter the Profitablity Fund:500
Enter the Bank Name:SBI
Enter the IFSC:ISFC001
Enter the Account Number :10001
Employee Details # 2 :
Enter the Employee number:102
Enter the Employee name:FORGE
Enter the Employee designation:Dr
Enter the Basic pay:32000
Enter the Humen Resource Allowance:2000
Enter the Dearness Allowance :300
Enter the Profitablity Fund:500
Enter the Bank Name:CITI
Enter the IFSC:ISFC0004
Enter the Account Number :20001
Employee number:101
Employee name:MASTE
Employee designation:Er
Employee Basic pay:26000
Employee Humen Resource Allowance:1300
Employee Dearness Allowance:1200
Employee Profitablity Fund:500
Employee Net Pay:28000
Employee Bank Name:SBI
Employee IFSC:ISFC001
Employee Account Number:10001
Employee number:102
Employee name:FORGE
Employee designation:Dr
Employee Basic pay:32000
Employee Humen Resource Allowance:2000
Employee Dearness Allowance:300
Employee Profitablity Fund:500
Employee Net Pay:33800
Employee Bank Name:CITI
Employee IFSC:ISFC0004
Employee Account Number:20001
--------------------------------
Process exited after 82.2 seconds with return value 0
Press any key to continue . . .
#include<iostream>
#include<stdio.h>
#include<conio.h>
class Person {
int eno;
char name[20], des[20];
// Private members cannot call from outside class.
public:
void getPersonDetails() {
cout << "\nEnter the Person number:";
cin>>eno;
cout << "Enter the Person name:";
cin>>name;
cout << "Enter the Person designation:";
cin>>des;
}
void person_display() {
cout <<"\nPerson number:"<<eno;
cout <<"\nPerson name:"<<name;
cout <<"\nPerson designation:"<<des;
}
};
void getEmployeeDetails() {
getPersonDetails();
cout << "Enter the Basic pay:";
cin>>bp;
cout << "Enter the Humen Resource Allowance:";
cin>>hra;
cout << "Enter the Dearness Allowance :";
cin>>da;
cout << "Enter the Profitablity Fund:";
cin>>pf;
calculate();
}
void calculate() {
np = bp + hra + da - pf;
}
void employee_display() {
person_display();
cout <<"\nEmployee Basic pay:"<<bp;
cout <<"\nEmployee Humen Resource Allowance:"<<hra;
cout <<"\nEmployee Dearness Allowance:"<<da;
cout <<"\nEmployee Profitablity Fund:"<<pf;
cout <<"\nEmployee Net Pay:"<<np;
}
};
void student_display() {
person_display();
cout <<"\nStudent college Name:"<<college;
cout <<"\nStudent IFSC:"<<course<<endl;
}
};
int main() {
int i, n;
char ch;
Student s[10];
Employee e[10];
cout << "Simple Hierarchical Inheritance Example Program : Payroll
System \n";
return 0;
}
Output
Simple Hierarchical Inheritance Example Program : Payroll System
Enter the number of Student:2
Student Details # 1 :
Enter the Person number:101
Enter the Person name:Booke
Enter the Person designation:10th
Enter the Student college Name:CGR
Enter the Student course Name:BSC
Student Details # 2 :
Enter the Person number:102
Enter the Person name:Moste
Enter the Person designation:12th
Enter the Student college Name:IIT
Enter the Student course Name:BE
Person number:101
Person name:Booke
Person designation:10th
Student college Name:CGR
Student IFSC:BSC
Person number:102
Person name:Moste
Person designation:12th
Student college Name:IIT
Student IFSC:BE
Employee Details # 1 :
Enter the Person number:201
Enter the Person name:ASHK
Enter the Person designation:Er
Enter the Basic pay:12000
Enter the Humen Resource Allowance:1200
Enter the Dearness Allowance :1100
Enter the Profitablity Fund:900
Employee Details # 2 :
Enter the Person number:203
Enter the Person name:ROK
Enter the Person designation:Dr
Enter the Basic pay:13000
Enter the Humen Resource Allowance:1300
Enter the Dearness Allowance :800
Enter the Profitablity Fund:700
Person number:201
Person name:ASHK
Person designation:Er
Employee Basic pay:12000
Employee Humen Resource Allowance:1200
Employee Dearness Allowance:1100
Employee Profitablity Fund:900
Employee Net Pay:13400
Person number:203
Person name:ROK
Person designation:Dr
Employee Basic pay:13000
Employee Humen Resource Allowance:1300
Employee Dearness Allowance:800
Employee Profitablity Fund:700
Employee Net Pay:14400
--------------------------------
Process exited after 108.4 seconds with return value 0
Press any key to continue . . .