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; }
运行结果:
要修改的话很方便哦!(我也注意了魔数的问题)
查看全文
相关阅读:
git取消文件跟踪
servlet
查杀端口进程
初始化git仓库,并push到远端
tomcat
bootstrap
idea中web工程错误
i++和++i
js算法
编程工具
原文地址:https://www.cnblogs.com/jjtx/p/2533485.html
最新文章
设计模式--面向对象基本原则
SpringCloud源码分析(一)--Eureka服务基础知识
SpringCloud源码分析(一)--客户端搭建
springboot启动dubbo时端口占用,但相关端口项目已经关闭,还是显示端口占用
thymeleaf使用mode: LEGACYHTML5非严格模式Html需要添加nekohtml依赖否则报错
idea开启空文件夹时候没有maven选项的情况
TCP的三次握手
网络基础7层
RabbitMQ配置环境变量后启动不了的解决方法
Muse-UI自定义主题的使用方法
热门文章
9-2
工具
爬山
CLOB和BLOB的区别
自动补全
solrconfig
solr配置
solr
spring配置junit测试
tar,jar,war的区别
Copyright © 2011-2022 走看看