一、问题及代码
文件名称:Ex1-1.cpp
作 者:石伟强
完成日期:2017 年 3月 1 3日
项目1:个人所得税计算器
编写选择结构程序,输入个人月收入总额,计算出他本月应缴税款和税后收入(计算办法见附:关于个人所得税的有关背景知识)。
(1)自选if语句的嵌套或/和switch语句完成程序设计;
(2)下面给出程序的基本框架,请下载使用。
#include <iostream>
using namespace std;
int main( )
{
double dSalary,dTax=0,dNetIncome=0,x;
cout<<"请输入您本月的收入总额(元):";
cin>>dSalary;
x = dSalary - 3500;
if (x > 0)
{
if (x <= 1500)
{
dTax = x*0.03;
dNetIncome = dSalary - dTax;
}
else if (1500 < x <=4500)
{
dTax = x*0.1 - 105;
dNetIncome = dSalary - dTax ;
}
else if (4500 < x <=9000)
{
dTax = x*0.2 - 555;
dNetIncome = dSalary - dTax ;
}
else if (9000 < x <=35000)
{
dTax = x*0.25 - 1005;
dNetIncome = dSalary - dTax;
}
else if (35000 <=x <= 55000)
{
dTax = x*0.3 - 2755;
dNetIncome = dSalary - dTax ;
}
else if (55000 <x<= 80000)
{
dTax = x*0.35 - 5505;
dNetIncome = dSalary - dTax;
}
else
dTax = x*0.45-13505;
dNetIncome = dSalary - dTax ;
}
else
{
dNetIncome = dSalary;
dTax = 0;
}
cout<<"您本月应缴个人所和税 "<<dTax<<" 元,税后收入是 "<<dNetIncome<<" 元。\n";
cout<<"依法纳税,共享繁荣。谢谢使用!\n";
return 0;
}
二、运行结果:
问题及代码:
文件名称:Ex1-1.cpp
作 者:石伟强
完成日期:2017 年 3 月 13 日
【项目6:输出质数】输出1000-10000之间,个位和千位相等的所有质数。
#include<iostream>
#include<cmath>
using namespace std;
int is_prime(int a)
{
int i;
for(i=2;i<=sqrt(a);i++)
if(a%i==0)
{
break; return 0;
}
else
return 1;
}
int main()
{
int i;
for(i=1000;i<=10000;i++)
if(is_prime(i)&&(i%10==i/1000))
cout<<i<<" ";
cin.get();
}
运行结果: