runxinzhi.com
首页
百度搜索
计算个税(定义一个薪水类)
(起征点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; }
运行结果:
要修改的话很方便哦!(我也注意了魔数的问题)
相关阅读:
re模块
正则表达式
python-函数基础(*arge **kwargs)
Python-类基础
Python内置函数
有些事情自己知道就好
jquery和dom之间的转换
Jquery中attr和prop的区别
thinkphp一对多HAS_MANY
thinkphp表单自动验证
原文地址:https://www.cnblogs.com/jjtx/p/2533485.html
最新文章
golang web实战之二(iris)
Git clone远程目录443:Timed out 问题(go get)
vps install ss
golang 实现HTTP代理和反向代理
用golang写了个统计各单位报送的信息数量的微服务
golang 日期时间处理
MT【227】换钱的总数
MT【226】费马点两题
MT【225】两平行直线夹曲线
MT【224】反解系数
热门文章
MT【223】二次函数最大最小
MT【222】几道自招面试真题
MT【221】几个常用的多元恒等式
MT【220】三次方程必有实根
MT【219】构造二次函数
MT【218】交点个数
time模块
序列化模块
os模块
sys模块
Copyright © 2020-2023
润新知