Simple Program for Single Inheritance Using C++ Programming
Inheritance Definition:
Inheritance is the concept in which a class derives the characters of another class similar to a child deriving character from his/her parents.
To write a program to find out the payroll system using single inheritance.
Single Inheritance Definition
Single inheritance is straightforward to learn. A class extends (inherit) another only one class, Its called single inheritance. One subclass is allowed to inherit by only one base class. It provides a derived class to inherit all properties and all behavior of a base class.
Simple Program for Single Inheritance Algorithm/Steps:
- Step 1: Start the program.
- Step 2: Declare the base class emp.
- Step 3: Define and declare the function get() to get the employee details.
- Step 4: Declare the derived class salary.
- Step 5: Declare and define the function get1() to get the salary details.
- Step 6: Define the function calculate() to find the net pay.
- Step 7: Define the function display().
- Step 8: Create the derived class object.
- Step 9: Read the number of employees.
- Step 10: Call the function get(),get1() and calculate() to each employees.
- Step 11: Call the display().
- Step 12: Stop the program.
Payroll System: Simple Program for Single Inheritance Example Program
#include<iostream.h>
#include<conio.h>
class emp {
public:
int eno;
char name[20], des[20];
void get() {
cout << "Enter the employee number:";
cin>>eno;
cout << "Enter the employee name:";
cin>>name;
cout << "Enter the designation:";
cin>>des;
}
};
class salary : public emp {
float bp, hra, da, pf, np;
public:
void get1() {
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;
}
void calculate() {
np = bp + hra + da - pf;
}
void display() {
cout << eno << "\t" << name << "\t" << des << "\t" << bp << "\t" << hra << "\t" << da << "\t" << pf << "\t" << np << "\n";
}
};
void main() {
int i, n;
char ch;
salary s[10];
clrscr();
cout << "Enter the number of employee:";
cin>>n;
for (i = 0; i < n; i++) {
s[i].get();
s[i].get1();
s[i].calculate();
}
cout << "\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for (i = 0; i < n; i++) {
s[i].display();
}
getch();
}
Sample Output
Enter the Roll no: 100
Enter two marks
90
80
Enter the Sports Mark: 90
Roll No: 100
Total : 260
Average: 86.66
Inheritance In C++ Programs
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Inheritance Base Class Private Member Example Program
- Simple Inheritance Private Base Class Example Program
- Simple Multi Level Inheritance Example Program
- Simple Hierarchical Inheritance Example Program
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Exception Handling Divide by zero Using C++ Programming