33
Total Posts
3
Categories
24/7
Updated

C++

Write a C++ program to read the data of N employee and compute Net salary of each employee (DA=52% of Basic and Income Tax (IT) =30% of the gross salary).

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

class Employee {
private:
    int empNo;
    string empName;
    float basic, da, it, gross, 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;
    }

    void calculateSalary() {
        da = 0.52 * basic;
        gross = basic + da;
        it = 0.30 * gross;
        netSalary = gross - it;
    }

    void displayData() {
        cout << "\nEmployee No: " << empNo << endl;
        cout << "Employee Name: " << empName << endl;
        cout << "Basic Salary: " << basic << endl;
        cout << "DA (52%): " << da << endl;
        cout << "Gross Salary: " << gross << endl;
        cout << "IT (30%): " << it << endl;
        cout << "Net Salary: " << netSalary << endl;
    }
};

int main() {
    int N;
    cout << "Enter number of employees: ";
    cin >> N;

    Employee emp[N];   // Array of objects

    for (int i = 0; i < N; i++) {
        cout << "\nEnter details of Employee " << i + 1 << endl;
        emp[i].readData();
        emp[i].calculateSalary();
    }

    cout << "\n--- Employee Salary Details ---\n";
    for (int i = 0; i < N; i++) {
        emp[i].displayData();
    }

    return 0;
}

Documentation

Input

Enter number of employees: 2

Enter details of Employee 1
Enter Employee Number: 101
Enter Employee Name: Rahul
Enter Basic Salary: 20000

Enter details of Employee 2
Enter Employee Number: 102
Enter Employee Name: Neha
Enter Basic Salary: 30000

 

Output

--- Employee Salary Details ---

Employee No: 101
Employee Name: Rahul
Basic Salary: 20000
DA (52%): 10400
Gross Salary: 30400
IT (30%): 9120
Net Salary: 21280

Employee No: 102
Employee Name: Neha
Basic Salary: 30000
DA (52%): 15600
Gross Salary: 45600
IT (30%): 13680
Net Salary: 31920

 

✔ Reads data of N employees
✔ Calculates DA = 52% of Basic
✔ Calculates Income Tax (IT) = 30% of Gross Salary
✔ Computes and displays Net Salary for each employee

 

Salary Formula Used

  • DA = 52% of Basic

  • Gross Salary = Basic + DA

  • IT = 30% of Gross Salary

  • Net Salary = Gross Salary − IT