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; }
运行结果:
要修改的话很方便哦!(我也注意了魔数的问题)
查看全文
相关阅读:
【C++学习】C++中的new VS C语言中的malloc
【C++学习】多态——解析树实例分析
【C++错误处理】multiple definition of
VS.NET控件命名规范
ASP.NET跨页面传值技巧总结
marquee+js实现某个区域的“无缝滚动效果”
vs2008与oracle数据库连接
C#中HashTable的用法
1. asp.net实现单点登陆
GridView实现某列中相同值合并(不规则表)
原文地址:https://www.cnblogs.com/jjtx/p/2533485.html
最新文章
SHELL技巧:处理文件名中的那些空格
Mac下使用Phonegap(Apache Cordorva)开发iOS应用
CSS中的计数器
简单实用的防止多次提交辅助类
转载:Windows Phone 7 资源汇总(超全)
我的程序人生语言学习之路
VS输出窗口(output view)的小技巧文件行号字符定位
(翻译)31 Days of Windows Phone 2(页面导航)、3(回退按钮)
FCK去掉p标签 和加Body标签
MEF学习笔记
热门文章
VS调试Tip集结
JS的一些扩展:String、StringBuilder、Uri
F#初试(2)
【C++错误处理】no matching function for call to transform
【QT学习】如何分析一个QT类
【QT学习】搭建环境+hello world
【QT学习】QT处理XML文件总结
【QT学习】字符串和数字
【C++学习】零散笔记
【C++习作】用多态计算一百以内的质数
Copyright © 2011-2022 走看看