Answer to Question #223584 in C++ for Fama

Question #223584

Write a c++ program to calculate Gross salary(net salary+DA+TDS) for 4 employees where overload the +

operator for getting the total salary obtained by all the 4 employees. Also get the average salary of employees

by operator overloading. display all the details of all four employees. Also display who is getting highest

salary. Employee salary must be entered by the user at runtime.


1
Expert's answer
2021-08-05T11:36:21-0400
#include <iostream>
#include <string>
using namespace std;
class Employee{
    float net_salary, DA, TDS, total_salary;
    string name;
    public:
    Employee(){
        cout<<"\nEnter employee name: ";
        cin>>this->name;
        cout<<"Enter employee net salary: ";
        cin>>this->net_salary;
        cout<<"Enter employee DA: ";
        cin>>this->DA;
        cout<<"Enter employee TDS: ";
        cin>>this->TDS;
        this->total_salary = this->net_salary + this->DA + this->TDS;
    }
    float operator+(Employee &other){
        return this->total_salary + other.total_salary;
    }
    float get_sal(){
        return this->total_salary;
    }
    void display(){
        cout<<"\nEmployee name: "<<this->name<<endl;
        cout<<"Employee net salary: "<<this->net_salary<<endl;
        cout<<"Employee DA: "<<this->DA<<endl;
        cout<<"Employee TDS: "<<this->TDS<<endl;
        cout<<"Total salary: "<<this->total_salary<<endl;
    }
};
int main(){
    Employee A, B, C, D;
    cout<<"\nAverage Salary: "<<((A + B) + (C + D))/4<<endl;
    Employee arr[] = {A, B, C, D};
    for(int i = 0; i < 4; i++){
        arr[i].display();
    }
    cout<<"Employee with highest salary:";
    int max = 0;
    float maxSal = 0;
    for(int i = 0; i < 4; i++){
        if(arr[i].get_sal() > maxSal){
            maxSal = arr[i].get_sal();
            max = i;
        }
    }
    arr[max].display();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS