{}
run-icon
main.cpp
#include <iostream> #include <string> using namespace std; class Employee { protected: int employeeID; string employeeName; double basicSalary; public: Employee(int id, string name, double salary) { employeeID = id; employeeName = name; basicSalary = salary; } void displayEmployee() { cout << "Employee ID : " << employeeID << endl; cout << "Employee Name : " << employeeName << endl; cout << "Basic Salary : " << basicSalary << endl; } }; class PermanentEmployee : public Employee { public: PermanentEmployee(int id, string name, double salary) : Employee(id, name, salary) { } double calculateAllowance() { return basicSalary * 0.20; } double calculateTotalSalary() { return basicSalary + calculateAllowance(); } void displayDetails() { displayEmployee(); cout << "Allowance (20%) : " << calculateAllowance() << endl; cout << "Total Salary : " << calculateTotalSalary() << endl; cout << "-----------------------------" << endl; } }; int main() { PermanentEmployee emp1(101, "Rahim", 30000); PermanentEmployee emp2(102, "Karim", 40000); PermanentEmployee emp3(103, "Jamal", 35000); cout << "Employee Details\n\n"; emp1.displayDetails(); emp2.displayDetails(); emp3.displayDetails(); PermanentEmployee *highest = &emp1; if (emp2.calculateTotalSalary() > highest->calculateTotalSalary()) highest = &emp2; if (emp3.calculateTotalSalary() > highest->calculateTotalSalary()) highest = &emp3; cout << "\nEmployee with Highest Total Salary\n"; highest->displayDetails(); return 0; }
Output