题解 | #个人所得税计算程序#
个人所得税计算程序
https://www.nowcoder.com/practice/afd6c29943c54453b2b5e893653c627e
//第一次没通过,发现王五是十万不是一万。。
#include <iostream>
#include <vector>#include <algorithm>
#include <iomanip>
using namespace std;
class Employee {
private:
string name;
double salary;
public:
Employee(string name,double salary){
this->name=name;
this->salary=salary;
}
string getname(){
return name;
}
double getsalary(){
return salary;
}
};
double ss(double t){
double tax;
t-=3500;
if(t<=0){
tax=0.0;
}
else if(t>0&&t<=1500){
tax=t*0.03-0;
}
else if(t>1500&&t<=4500){
tax=t*0.10-105;
}
else if(t>4500&&t<=9000){
tax=t*0.20-555;
}
else if(t>9000&&t<=35000){
tax=t*0.25-1005;
}
else if(t>35000&&t<=55000){
tax=t*0.30-2755;
}
else if(t>55000&&t<=80000){
tax=t*0.35-5505;
}
else{
tax=t*0.45-13505;
}
return tax;
}
bool cmp(Employee& e1,Employee& e2){
return e1.getsalary()>e2.getsalary();
}
int main() {
Employee a("张三",6500),b("李四",8000),c("王五",100000);
vector<Employee> v;
v.emplace_back(a);
v.emplace_back(b);
v.emplace_back(c);
sort(v.begin(),v.end(),cmp);
for(auto it=v.begin();it!=v.end();it++)
cout<<it->getname()<<"应该缴纳的个人所得税是:"<<fixed<<setprecision(1)<<ss(it->getsalary())<<endl;
return 0;
}