zoukankan
html css js c++ java
计算个税(定义一个薪水类)
(起征点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; }
运行结果:
要修改的话很方便哦!(我也注意了魔数的问题)
查看全文
相关阅读:
bootstrap
bootstrap
bootstrap
【k8s】Pod-terminationGracePeriodSeconds
【k8s】Pod-tolerations
【k8s】Pod-nodeSelector
【k8s】Pod-nodeName
【k8s】Pod-hostname
【k8s】Pod-hostPID
【k8s】Pod-hostNetwork
原文地址:https://www.cnblogs.com/jjtx/p/2533485.html
最新文章
家庭记账本6
家庭记账本5
家庭记账本4
家庭记账本3
家庭记账本2
家庭记账本1
今日总结
Element-UI中Drawer抽屉去除标题自带黑色边框
小程序跳转到h5页面无法获取参数
让一段代码执行在new Vue之前
热门文章
css 宽度分离原则
cookie的设置读取
true=='true'这个等式成立吗?
像elementui一样封装自定义按钮
如何处理开发环境没有问题,线上环境有问题这个bug
vue/cli3.0相对路径打包
2021年度训练联盟热身训练赛第七场 Problem M: Mixtape Management(构造/思维)
2021年度训练联盟热身训练赛第七场 Problem K: Knightly Knowledge(离散化)
牛客IOI周赛25-普及组 B. 学姐的编码1.0(简单DP)
Leetcode 137. 只出现一次的数字 II(位运算)
Copyright © 2011-2022 走看看