题解 | #个人所得税计算程序#

个人所得税计算程序

https://www.nowcoder.com/practice/afd6c29943c54453b2b5e893653c627e

#include <iomanip>
#include <iostream>
// write your code here......
#include <vector>
#include <algorithm>
using namespace std;

class Employee {

    private:
        string name;
        double salary;
    // write your code here......
    public:
        Employee(string name, double salary){
            this->name = name;
            this->salary = salary;
        }
        string getName(){
            return name;
        }
        double getSalary(){
            return salary;
        }

};

bool compare(Employee e1, Employee e2){
    return e1.getSalary() > e2.getSalary();
}

void show(Employee &e){
    double tax = 0.0;
    double t = e.getSalary() - 3500;
    if(t <= 0){}
    else if (t > 80000){
        tax = t * 0.45 - 13505;
    }
    else if(t > 55000){
        tax = t * 0.35 - 5505;
    }
    else if(t > 35000){
        tax = t * 0.30 - 2755;
    }
    else if(t > 9000){
        tax = t * 0.25 - 1005;
    }
    else if(t > 4500){
        tax = t * 0.20 - 555;
    }
    else if(t > 1500){
        tax = t * 0.10 - 105;
    }
    else tax = t * 0.03;
    cout << fixed << setprecision(1);
    cout << e.getName() << "应该缴纳的个人所得税是:" << tax << endl;
}

int main() {

    // write your code here......
    Employee e1("张三",6500);
    Employee e2("李四",8000);
    Employee e3("王五",100000);

    vector<Employee> emp;
    emp.push_back(e1);
    emp.push_back(e2);
    emp.push_back(e3);

    sort(emp.begin(),emp.end(),compare);
    for_each(emp.begin(),emp.end(),show);
    return 0;
}

全部评论

相关推荐

05-23 20:31
已编辑
武汉大学 Java
内向的柠檬精在研究求职打法:注意把武大标粗标大 本地你俩不是乱杀
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务