C++ Program to Load and Store Records of N Employees N कर्मचारियों के रिकॉर्ड को इनपुट एवं स्टोर करने का C++ प्रोग्राम
In C++, an array of objects can be used to store records of multiple employees. Each object represents one employee and stores information such as Employee ID, Name, and Basic Salary.
We can also calculate different salary components such as Travel Allowance (TA), Dearness Allowance (DA), House Rent Allowance (HRA), and Gross Salary using member functions.
C++ में Multiple Employees के Records को Store करने के लिए Array of Objects का उपयोग किया जा सकता है। प्रत्येक Object एक Employee को दर्शाता है तथा इसमें Employee ID, Name और Basic Salary जैसी जानकारियाँ Store की जाती हैं।
Member Functions की सहायता से Travel Allowance (TA), Dearness Allowance (DA), House Rent Allowance (HRA) तथा Gross Salary की गणना भी की जा सकती है।
Salary Calculation Formula (सैलरी कैलकुलेशन फॉर्मूला)
TA = 25% of Basic Salary
DA = 50% of Basic Salary
HRA = 10% of Basic Salary
Gross Salary = Basic Salary + TA + DA + HRA
Program:
#include <iostream>#include <string>#include <iomanip>using namespace std;#define N 5class Employee{int empid;string name;float bs, gs, ta, da, hra;// Private member functionvoid grossSalary(){ta = 0.25 * bs;da = 0.50 * bs;hra = 0.10 * bs;gs = bs + ta + da + hra;}public:void setEmp();void getEmp();};// Function to accept employee detailsvoid Employee::setEmp(){cout << "Enter Employee Details:" << endl;cout << "Enter Employee ID: ";cin >> empid;cout << "Enter Name: ";cin >> name;cout << "Enter Basic Salary: ";cin >> bs;}// Function to display employee detailsvoid Employee::getEmp(){grossSalary();cout << "\nEmployee Details:" << endl;cout << "Employee ID = " << empid << endl;cout << "Name = " << name << endl;cout << "Basic Salary = " << bs << endl;cout << "TA = " << ta << endl;cout << "DA = " << da << endl;cout << "HRA = " << hra << endl;cout << "Gross Salary = " << gs << endl;}int main(){Employee e[N];// Accepting employee recordsfor (int i = 0; i < N; i++){cout << "\nEmployee " << i + 1 << endl;e[i].setEmp();}// Displaying employee recordsfor (int i = 0; i < N; i++){cout << "\n------------------------" << endl;e[i].getEmp();}return 0;}
Output:
Employee 1Enter Employee Details:Enter Employee ID: 101Enter Name: AmitEnter Basic Salary: 20000Employee 2Enter Employee Details:Enter Employee ID: 102Enter Name: RaviEnter Basic Salary: 25000Employee 3Enter Employee Details:Enter Employee ID: 103Enter Name: NehaEnter Basic Salary: 30000Employee 4Enter Employee Details:Enter Employee ID: 104Enter Name: PoojaEnter Basic Salary: 18000Employee 5Enter Employee Details:Enter Employee ID: 105Enter Name: MohanEnter Basic Salary: 22000------------------------Employee Details:Employee ID = 101Name = AmitBasic Salary = 20000TA = 5000DA = 10000HRA = 2000Gross Salary = 37000------------------------Employee Details:Employee ID = 102Name = RaviBasic Salary = 25000TA = 6250DA = 12500HRA = 2500Gross Salary = 46250------------------------Employee Details:Employee ID = 103Name = NehaBasic Salary = 30000TA = 7500DA = 15000HRA = 3000Gross Salary = 55500------------------------Employee Details:Employee ID = 104Name = PoojaBasic Salary = 18000TA = 4500DA = 9000HRA = 1800Gross Salary = 33300------------------------Employee Details:Employee ID = 105Name = MohanBasic Salary = 22000TA = 5500DA = 11000HRA = 2200Gross Salary = 40700
Explanation (व्याख्या)
1. Macro Definition
#define N 5The macro N defines the number of employees. In this program, five employee records are stored.
इस प्रोग्राम में N Macro कर्मचारियों की संख्या निर्धारित करता है। यहाँ पाँच Employees के Records Store किए जाते हैं।
2. Class Declaration
The Employee class contains the following data members:
empid– Stores Employee ID.name– Stores Employee Name.bs– Stores Basic Salary.ta– Stores Travel Allowance.da– Stores Dearness Allowance.hra– Stores House Rent Allowance.gs– Stores Gross Salary.
Employee Class में निम्न Data Members होते हैं:
empid– Employee ID Store करता है।name– Employee का नाम Store करता है।bs– Basic Salary Store करता है।ta– Travel Allowance Store करता है।da– Dearness Allowance Store करता है।hra– House Rent Allowance Store करता है।gs– Gross Salary Store करता है।
3. Private Member Function grossSalary()
void grossSalary(){ta = 0.25 * bs;da = 0.50 * bs;hra = 0.10 * bs;gs = bs + ta + da + hra;}
This is a private member function that calculates TA, DA, HRA, and Gross Salary using the employee's Basic Salary.
यह एक Private Member Function है, जो Employee की Basic Salary के आधार पर TA, DA, HRA तथा Gross Salary की गणना करता है।
4. setEmp() Function
This member function accepts Employee ID, Name, and Basic Salary from the user.
यह Member Function User से Employee ID, Name तथा Basic Salary Input करता है।
5. getEmp() Function
This member function first calls grossSalary() to calculate the salary components and then displays all employee details.
यह Member Function सबसे पहले Salary Components की गणना करने के लिए grossSalary() Function को Call करता है। इसके बाद Employee की सभी Details Display करता है।
6. Array of Objects
Employee e[N];This statement creates an array of five objects of the Employee class. Each object stores the details of one employee.
यह Statement Employee Class के पाँच Objects का Array बनाता है। प्रत्येक Object एक Employee की Details Store करता है।
7. Using for Loops
The first for loop calls setEmp() for each employee object to accept records. The second for loop calls getEmp() to calculate and display the salary details of all employees.
पहला for Loop प्रत्येक Employee Object के लिए setEmp() Function Call करके Records Input करता है। दूसरा for Loop getEmp() Function Call करके सभी Employees की Salary Details Calculate तथा Display करता है।
This program demonstrates the use of classes, objects, arrays of objects, private member functions, and loops in C++. It also shows how salary components can be calculated and displayed for multiple employees.
यह प्रोग्राम C++ में Classes, Objects, Array of Objects, Private Member Functions तथा Loops के उपयोग को प्रदर्शित करता है। साथ ही, यह भी दर्शाता है कि Multiple Employees के Salary Components की गणना करके उन्हें Display कैसे किया जा सकता है।
Comments
Post a Comment