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

个人所得税计算程序

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

#include <iostream>
// write your code here......
#include <vector>
#include <algorithm>
#include <iomanip>
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 this->name;
        }

        double getSalary()
        {
            return this->salary;
        }

        double getTax()
        {
            int base = this->salary - 3500;
            int tax = 0;

            if (base <= 1500)
                tax = base * 0.03;
            else if (base > 1500 && base <= 4500)
                tax = base * 0.1 - 105;
            else if (base > 4500 && base <= 9000)
                tax = base * 0.2 - 555;
            else if (base > 9000 && base <= 35000)
                tax = base * 0.25 - 1005;
            else if (base > 35000 && base <= 55000)
                tax = base * 0.3 - 2755;
            else if (base > 55000 && base <= 80000)
                tax = base * 0.35 - 5505;
            else
                tax = base * 0.45 - 13505;
            return tax;
        }

};

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

int main() {

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

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

    sort(v.begin(), v.end(), cmp);
    
    for (auto it = v.begin(); it != v.end(); it++)
    {
        cout << it->getName() << "应该缴纳的个人所得税是:" << fixed << setprecision(1) << it->getTax() << endl;
    }

    return 0;
}

全部评论

相关推荐

头像
11-09 12:17
清华大学 C++
out11Man:小丑罢了,不用理会
点赞 评论 收藏
分享
双非坐过牢:非佬,可以啊10.28笔试,11.06评估11.11,11.12两面,11.19oc➕offer
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务