会错题意了
个人所得税计算程序
https://www.nowcoder.com/practice/afd6c29943c54453b2b5e893653c627e
#include <algorithm> #include <iostream> #include <string> #include <vector> #include <iomanip> // write your code here...... using namespace std; class Employee { public: string name; double salary; // write your code here...... public: Employee(string name,double salary) { this->name=name; this->salary=salary; } }; void swop1(double &m,double &n) { double temp1=m; m=n; n=temp1; } void swop2(string &p,string &q) { string temp2=p; p=q; q=temp2; } void sorted(vector<Employee>VEC) { for(int i=0;i<VEC.size()-1;i++) { for(int j=0;j<VEC.size()-1-i;j++) { if(VEC[j].salary>VEC[j+1].salary) { swop1(VEC[j].salary,VEC[j+1].salary); swop2(VEC[j].name,VEC[j+1].name); } } } } void cal(Employee E) { double number=0; double sbtm=E.salary-3500; if(sbtm>80000) { number=sbtm*0.45-13505; } else if(E.salary>55000) { number=sbtm*0.35-5505; } else if(sbtm>35000) { number=sbtm*0.3-2755; } else if(sbtm>9000) { number=sbtm*0.25-1005; } else if(sbtm>4500) { number=sbtm*0.2-555; } else if(sbtm>1500) { number=sbtm*0.1-105; } else if (sbtm<=1500) { number=sbtm*0.03; } //cout<<E.name<<"王五应该缴纳的个人所得税是:"<<number<<endl; cout<<E.name<<"应该缴纳的个人所得税是:"<<std::fixed << std::setprecision(1)<<number<<endl; } int main() { // write your code here...... vector<Employee>vec; Employee em1("张三",6500);vec.push_back(em1); Employee em2("李四",8000);vec.push_back(em2); Employee em3("王五",100000);vec.push_back(em3); sorted(vec); reverse(vec.begin(), vec.end()); for(auto i :vec) { cal (i); } return 0; }