#include <algorithm> #include <iomanip> #include <iostream> // write your code here...... #include <scoped_allocator> #include <string> #include<vector> using namespace std; class Employee { private: string name; double salary; // write your code here...... public: Employee(string name, int salary) { this->name = name; this->salary = salary; } double getsalary() { return salary; } string getname() { return name; } double caculate() { int taxable = salary - 3500; if (taxable <= 1500) { return taxable * 0.03; } else if (taxable > 1500 && taxable <= 4500) { return taxable * 0.1 - 105; } else if (taxable > 4500 && taxable <= 9000) { return taxable * 0.2 - 555; } else if (taxable > 9000 && taxable <= 35000) { return taxable * 0.25 - 1005; } else if (taxable > 35000 && taxable <= 55000) { return taxable * 0.3 - 2755; } else if (taxable > 55000 && taxable <= 80000) { return taxable * 0.35 - 5505; } else if (taxable > 80000) { return taxable * 0.45 - 13505; } else { return 0; } } }; bool salaryCompare(Employee& e1, Employee& e2) { return e1.getsalary() > e2.getsalary(); } void mesprint(Employee& e) { cout << fixed << setprecision(1); cout << e.getname() << "应该缴纳的个人所得税是:" << e.caculate() << endl; } int main() { // write your code here...... Employee e1("张三", 6500); Employee e2("李四", 8000); Employee e3("王五", 100000); vector<Employee>v; v.push_back(e1); v.push_back(e2); v.push_back(e3); sort(v.begin(), v.end(), salaryCompare); //for_each(v.begin(), v.end(), mesprint); for (vector<Employee>::iterator it = v.begin(); it != v.end(); it++) { cout << fixed << setprecision(1); cout << (*it).getname() << "应该缴纳的个人所得税是:" << (*it).caculate() << endl; } return 0; }