33
Total Posts
3
Categories
24/7
Updated

C++

Given that an EMPLOYEE class contains following members: data members: Employee number, Employee name, Basic, DA, IT, Net Salary and print data members.

Published on Dec 22, 2025
#include <iostream>
#include <string>
using namespace std;

class EMPLOYEE {
private:
    int empNo;
    string empName;
    float basic, da, it, netSalary;

public:
    void readData() {
        cout << "Enter Employee Number: ";
        cin >> empNo;

        cout << "Enter Employee Name: ";
        cin.ignore();
        getline(cin, empName);

        cout << "Enter Basic Salary: ";
        cin >> basic;

        cout << "Enter DA: ";
        cin >> da;

        cout << "Enter IT: ";
        cin >> it;

        netSalary = basic + da - it;
    }

    void displayData() {
        cout << "\n--- Employee Details ---" << endl;
        cout << "Employee Number: " << empNo << endl;
        cout << "Employee Name: " << empName << endl;
        cout << "Basic Salary: " << basic << endl;
        cout << "DA: " << da << endl;
        cout << "IT: " << it << endl;
        cout << "Net Salary: " << netSalary << endl;
    }
};

int main() {
    EMPLOYEE emp;

    emp.readData();
    emp.displayData();

    return 0;
}

Documentation

Input

Enter Employee Number: 101
Enter Employee Name: Amit Kumar
Enter Basic Salary: 20000
Enter DA: 5000
Enter IT: 2000

 

Output

--- Employee Details ---
Employee Number: 101
Employee Name: Amit Kumar
Basic Salary: 20000
DA: 5000
IT: 2000
Net Salary: 23000

 

✔ EMPLOYEE class
✔ Data members:

  • Employee Number

  • Employee Name

  • Basic

  • DA (Dearness Allowance)

  • IT (Income Tax)

  • Net Salary
    ✔ Input and print all data members

 

  • Net Salary = Basic + DA – IT

  • Class data members are kept private

  • Member functions are used to read and print data