google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C++ program to calculate an employee's salary

Thursday, March 13, 2025

C++ program to calculate an employee's salary

 Here's a simple C++ program to calculate an employee's salary:



#include <iostream>

#include <string>

using namespace std;


class Employee {

private:

    string name;

    int employeeId;

    string department;

    double basicSalary;

    double allowance;

    double deduction;

    double netSalary;


public:

    void inputDetails() {

        cout << "Enter employee name: ";

        cin.ignore();

        getline(cin, name);

        cout << "Enter employee ID: ";

        cin >> employeeId;

        cout << "Enter department: ";

        cin.ignore();

        getline(cin, department);

        cout << "Enter basic salary: ";

        cin >> basicSalary;

        cout << "Enter allowance: ";

        cin >> allowance;

        cout << "Enter deduction: ";

        cin >> deduction;

    }


    void calculateNetSalary() {

        netSalary = basicSalary + allowance - deduction;

    }


    void displayDetails() {

        cout << "\nEmployee Details\n";

        cout << "Name: " << name << endl;

        cout << "Employee ID: " << employeeId << endl;

        cout << "Department: " << department << endl;

        cout << "Basic Salary: $" << basicSalary << endl;

        cout << "Allowance: $" << allowance << endl;

        cout << "Deduction: $" << deduction << endl;

        cout << "Net Salary: $" << netSalary << endl;

    }

};


int main() {

    Employee employee;

    employee.inputDetails();

    employee.calculateNetSalary();

    employee.displayDetails();

    return 0;

}



*Example Output:*


Enter employee name: John Doe

Enter employee ID: 123

Enter department: HR

Enter basic salary: 5000

Enter allowance: 1000

Enter deduction: 500


Employee Details

Name: John Doe

Employee ID: 123

Department: HR

Basic Salary: $5000

Allowance: $1000

Deduction: $500

Net Salary: $5500



This program defines an `Employee` class with private member variables for employee details and public methods for inputting details, calculating the net salary, and displaying details.


In the `main()` function, an `Employee` object is created, and the user is prompted to input employee details. The program then calculates the net salary and displays the employee details.

No comments:

Post a Comment

The rotation of money in business

 The rotation of money in business refers to the flow of funds within a company, encompassing various financial activities and transactions....