Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
1.4 kB
2
Indexable
Never
#include <iostream>
#include <string>

class Employee {
private:
    std::string name;
    double basic_salary;
    double DA_PERCENTAGE = 0.8;
    double HOUSE_RENT_PERCENTAGE = 0.2;

public:
    Employee(std::string n, double bs) : name(n), basic_salary(bs) {
        if (bs > 20000) {
            std::cout << "Error: Basic salary cannot be more than 20000" << std::endl;
            exit(1);
        }
    }

    void calculateSalary() {
        double da = basic_salary * DA_PERCENTAGE;
        double house_rent = basic_salary * HOUSE_RENT_PERCENTAGE;
        double gross_salary = basic_salary + da + house_rent;

        std::string salary_grade;
        if (gross_salary <= 25000) {
            salary_grade = "C";
        } else if (gross_salary <= 15000) {
            salary_grade = "B";
        } else {
            salary_grade = "A";
        }

        std::cout << "Employee Name: " << name << std::endl;
        std::cout << "Gross Salary: " << gross_salary << std::endl;
        std::cout << "Salary Grade: " << salary_grade << std::endl;
    }
};

int main() {
    std::string name;
    double basic_salary;

    std::cout << "Enter employee name: ";
    std::getline(std::cin, name);

    std::cout << "Enter basic salary: ";
    std::cin >> basic_salary;

    Employee e(name, basic_salary);
    e.calculateSalary();

    return 0;
}
Leave a Comment