C++ Project – Employee Payroll Management System

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

    // Project: Employee Payroll Management

#include <iostream>
#include <string>
using namespace std;

class Employee 
{
private:
    int empID;  // id of employee
    string name; // for name of employee
    float basicSalary; // basic salary of employee
    float hra, da,ta, totalSalary; // allowence
    float hi;

public:
    // Constructor
    Employee() 
    {
        empID = 0;
        basicSalary = hra = da = totalSalary = ta=hi=0;
        name = "";
    }

    // method to take employee input
    void input() 
    {
        cout << "\nEnter Employee ID: ";
        cin >> empID;
        cin.ignore(); // to ignore leftover newline character

        cout << "Enter Employee Name: ";
        getline(cin, name); 

        cout << "Enter Basic Salary: ";
        cin >> basicSalary;
    }

    // Function to calculate salary
    void calculateSalary() 
    {
        da = 0.80f * basicSalary;
        hra = 0.10f * basicSalary;
        ta=0.15f * basicSalary;
        hi=0.50f * basicSalary;
        totalSalary = (basicSalary + da + hra+ta)-hi;
    }

    // Function to display employee details
    void display() 
    {
        cout << "\n--- Employee Payroll Details ---\n";
        cout << "Employee ID      : " << empID << endl;
        cout << "Employee Name    : " << name << endl;
        cout << "Basic Salary     :" << basicSalary <<" Rs" << endl;
        cout << "DA (80%)         :" << da <<" Rs"<< endl;
        cout << "HRA (10%)        :" << hra <<" Rs" << endl;
        cout << "TA (15%)        :" << ta <<" Rs" << endl;
        cout << "Health Ins. (5%)        :" << hi <<" Rs" << endl;
        cout << "-------------------------------" << endl;
        cout << "Total Salary     : Rs" << totalSalary << endl;
    }
};

int main() 
{
    system("cls");
    Employee emp; // one employee for now

    int choice;

    do {
        cout << "\n\n------ Employee Payroll Menu ------\n";
        cout << "1. Add Employee\n";
        cout << "2. Calculate Salary\n";
        cout << "3. Display Employee Details\n";
        cout << "4. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
        case 1:
            emp.input();
            break;

        case 2:
            emp.calculateSalary();
            break;

        case 3:
            emp.display();
            break;

        case 4:
            cout << "\nExiting Program. Goodbye!\n";
            break;

        default:
            cout << "\nInvalid choice. Try again.";
        }

    } while (choice != 4);

    return 0;
}

 

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *