#include <iostream>
#include <map>
#include <string>
#include <iomanip>
using namespace std;
struct TaxInfo {
double rate;
double deduction;
};
class Employee {
public:
Employee(string name, double salary) : name(name), salary(salary) {}
double calcTax() {
int income = salary - 3500;
int grade = getGrade(income);
const auto& tax_info = tax.at(grade);
return income * tax_info.rate - tax_info.deduction;
}
private:
int getGrade(int income) {
static const int grade_boundaries[] = {1500, 4500, 9000, 35000, 55000, 80000};
for (int i = 0; i < 6; i++) {
if (income < grade_boundaries[i]) return i;
}
return 6;
}
public:
const double& getSalary() {
return salary;
}
const string& getName() {
return name;
}
private:
string name;
double salary;
static map<int, TaxInfo> tax;
};
map<int, TaxInfo > Employee::tax = {
{0, {0.03, 0}},
{1, {0.1, 105}},
{2, {0.2, 555}},
{3, {0.25, 1005}},
{4, {0.3, 2775}},
{5, {0.35, 5505}},
{6, {0.45, 13505}}
};
int main() {
std::map<double, Employee> m;
m.emplace(6500, Employee("张三", 6500));
m.emplace(8000, Employee("李四", 8000));
m.emplace(100000, Employee("王五", 100000));
for (auto it = m.rbegin(); it != m.rend(); it++) {
cout << it->second.getName() << "应该缴纳的个人所得税是:"
<< fixed << setprecision(1) << it->second.calcTax() << endl;
}
return 0;
}