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

个人所得税计算程序

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

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

class Employee {

private:
    string name;
    double salary;
    // write your code here......
public:
    Employee(string m_name, double m_salary) :name(m_name), salary(m_salary) {};
    string getname() {
        return name;
    }
    double getsalary() {
        return salary;
    }
};

double gettex(double sal) {
    double temp = sal - 3500;
    double tex=0.0;
    if (temp>0 && temp <= 1500) {
        tex = (sal - 3500) * 0.03;
    }
    if (temp > 1500 && temp<=4500) {
        tex = (sal - 3500) * 0.1 - 105;
    }
    if (temp > 4500 && temp <= 9000) {
        tex = (sal - 3500) * 0.2 - 555;
    }
    if (temp > 9000 && temp <= 35000) {
         tex = (sal - 3500) * 0.25 - 1005;
    }
    if (temp > 35000 && temp <= 55000) {
         tex = (sal - 3500) * 0.3 - 2755;
    }
    if (temp > 55000 && temp <= 80000) {
         tex = (sal - 3500) * 0.35 - 5505;
    }
    if (temp > 80000 ) {
         tex = (sal - 3500) * 0.45 - 13505;
    }
    return tex;
}
bool cmp(Employee& e1, Employee& e2) {
    return e1.getsalary() > e2.getsalary();
}

int main() {

    // write your code here......
    Employee emploee1("张三", 6500);
    Employee emploee2("李四", 8000);
    Employee emploee3("王五", 100000);
    vector<Employee> v;
    v.push_back(emploee1);
    v.push_back(emploee2);
    v.push_back(emploee3);
    sort(v.begin(), v.end(), cmp);
    for (auto it = v.begin(); it != v.end(); it++) {
        
        cout <<fixed<< setprecision(1)<< it->getname() << "应该缴纳的个人所得税是:" << gettex(it->getsalary()) << endl;
        
    }
    return 0;
}

全部评论

相关推荐

牛客517626884号:嵌入式真难啊今年,我电赛国二都成了路边野狗了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务