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 5
class Employee
{
int empid;
string name;
float bs, gs, ta, da, hra;
// Private member function
void 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 details
void 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 details
void 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 records
for (int i = 0; i < N; i++)
{
cout << "\nEmployee " << i + 1 << endl;
e[i].setEmp();
}
// Displaying employee records
for (int i = 0; i < N; i++)
{
cout << "\n------------------------" << endl;
e[i].getEmp();
}
return 0;
}

Output:

Employee 1
Enter Employee Details:
Enter Employee ID: 101
Enter Name: Amit
Enter Basic Salary: 20000

Employee 2
Enter Employee Details:
Enter Employee ID: 102
Enter Name: Ravi
Enter Basic Salary: 25000

Employee 3
Enter Employee Details:
Enter Employee ID: 103
Enter Name: Neha
Enter Basic Salary: 30000

Employee 4
Enter Employee Details:
Enter Employee ID: 104
Enter Name: Pooja
Enter Basic Salary: 18000

Employee 5
Enter Employee Details:
Enter Employee ID: 105
Enter Name: Mohan
Enter Basic Salary: 22000
------------------------
Employee Details:
Employee ID = 101
Name = Amit
Basic Salary = 20000
TA = 5000
DA = 10000
HRA = 2000
Gross Salary = 37000
------------------------
Employee Details:
Employee ID = 102
Name = Ravi
Basic Salary = 25000
TA = 6250
DA = 12500
HRA = 2500
Gross Salary = 46250
------------------------
Employee Details:
Employee ID = 103
Name = Neha
Basic Salary = 30000
TA = 7500
DA = 15000
HRA = 3000
Gross Salary = 55500
------------------------
Employee Details:
Employee ID = 104
Name = Pooja
Basic Salary = 18000
TA = 4500
DA = 9000
HRA = 1800
Gross Salary = 33300
------------------------
Employee Details:
Employee ID = 105
Name = Mohan
Basic Salary = 22000
TA = 5500
DA = 11000
HRA = 2200
Gross Salary = 40700

Explanation (व्याख्या)

1. Macro Definition

#define N 5

The 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

Popular posts from this blog

Important Questions of C++ including OOP's

Programming Methodologies and OOP's using C++ Language

OOP's using CPP Syllabus AND Programming Methodologies and Data Structures Using C++ (NEP 2020)