题解 | #个人所得税计算程序#
个人所得税计算程序
https://www.nowcoder.com/practice/afd6c29943c54453b2b5e893653c627e
#include <algorithm> //#include <functional> #include <iomanip> //#include <ios> #include <iostream> //#include <string> #include <vector> // write your code here...... using namespace std; class Employee { private: string name; double salary; // write your code here...... public: void savename (string s){ name = s; } void savesalary (double num){ salary = num; } string getname(){ return name; } double getsalary(){ return salary; } double calculate(double Sa, double taxper, double kou ){ double result = Sa * taxper - kou; return result; } double Tax(){ double tax; double standard = 3500; double Sa = salary - standard; if ( Sa <= 0 ) { tax = 0; }else if(Sa <= 1500 && Sa >0){ tax = calculate(Sa, 0.03, 0); }else if(Sa <= 4500 && Sa >1500){ tax = calculate(Sa, 0.1, 105); }else if (Sa <= 9000 && Sa >4500) { tax = calculate(Sa, 0.2, 555); }else if (Sa <= 35000 && Sa > 9000) { tax = calculate(Sa, 0.25, 1005); }else if(Sa <= 55000 && Sa > 35000) { tax = calculate(Sa, 0.3, 2755); }else if(Sa <= 80000 && Sa > 55000) { tax = calculate(Sa, 0.35, 5505); }else if(Sa > 80000) { tax = calculate(Sa, 0.45, 13505); } return tax; } bool operator>(const Employee& other) const{ return salary > other.salary; } }; int main() { // write your code here...... Employee ep1; Employee ep2; Employee ep3; ep1.savename("张三"); ep1.savesalary(6500); ep2.savename("李四"); ep2.savesalary(8000); ep3.savename("王五"); ep3.savesalary(100000); vector<Employee*> v; v.push_back(&ep1); v.push_back(&ep2); v.push_back(&ep3); sort(v.begin(), v.end() , [](Employee* a,Employee* b){ return *a > *b; });//需要重装载 cout << fixed << setprecision(1); for(const auto &iter : v){ cout << iter->getname(); cout<< "应该缴纳的个人所得税是:" ; cout << iter->Tax() << endl; } return 0; }