(起征点800):
#include <iostream>
using namespace std;
#define TAX_THRESHOLD 800
struct Tax {
double standard;
double tax_rate;
};
class Salary {
double income;
public:
static Tax tax_array[];
Salary(int m = 0) {
income = m;
}
void operator - (int payout) {
income -= payout;
cout << "工资余额:" << income << endl;
}
void CalculateSalary(void);
};
Tax Salary::tax_array[] = {
{0,0.05}, {500, 0.10}, {2000, 0.15}, {5000,0.20}, {20000,0.25},
{40000,0.30}, {60000,0.35}, {80000,0.40}, {100000,0.45}
};
void Salary::CalculateSalary(void)
{
double tax = 0;
double x = income - TAX_THRESHOLD;
if(x > 0) {
for(int i = sizeof(tax_array) / sizeof(*tax_array) - 1; i >= 0; i--) {
if(x > tax_array[i].standard) {
tax += (x - tax_array[i].standard) * tax_array[i].tax_rate;
x = tax_array[i].standard;
}
}
}
cout << "税前工资为:" << income << endl;
cout << "个人所得税为:" << tax << endl;
income -= tax;
cout << "实发工资为:" << income << endl;
}
int main(void)
{
double myincome;
double mypayout;
while(cout << "您的月薪为:", cin >> myincome) {
Salary mysalary(myincome);
mysalary.CalculateSalary();
cout << "取款金额:";
cin >> mypayout;
mysalary - mypayout; // 硬性重载减号
cout << endl;
}
return 0;
}

要修改的话很方便哦!(我也注意了魔数的问题)
本文介绍了一个使用C++实现的薪资计算器程序,该程序能够根据不同的收入级别计算个人所得税,并显示税前工资、个人所得税及实发工资等信息。此外,还提供了工资余额查询功能。
1万+

被折叠的 条评论
为什么被折叠?



