你们一直让我更,我就更一下吧,我也不知道以前写过没,你们需要我就更啦!多多支持,多多点赞。
例1.工资类的计算
生成一个GZ类表示工资,用静态成员表示个人所得税占工资比例。类的每个成员包含一个私有数据成员money,表示当月工资。提供一个calSDS()成员函数,计算个人应交所得税,并从money中扣除。
实例化三个不同的GZ对象people1、people2和people3,工资分别为12000 、56000 和480000。分别计算三人实际应发的工资数并打印结果。
(1)用静态数据成员表示个人所得税占工资的比例;
(2)编写计算个人应交所得税成员函数calSDS();
(3)生成GZ类的三个对象;
(4)对三个对象分别计算实际应发的工资数;
(3)显示程序结果;
代码如下:
#include<iostream>
using namespace std;
class GZ
{
private:
float money;
public:
void calSDS();
float static SDS1;
float static SDS2;
float static SDS3;
float static SDS4;
float static SDS5;
float static SDS6;
float static SDS7;
float static SDS8;
float static SDS9; //9个静态数据成员
GZ(float x);
};
float GZ::SDS1=0.05; //静态数据成员
float GZ::SDS2=0.1;
float GZ::SDS3=0.15;
float GZ::SDS4=0.2;
float GZ::SDS5=0.25;
float GZ::SDS6=0.3;
float GZ::SDS7=0.35;
float GZ::SDS8=0.4;
float GZ::SDS9=0.45;
GZ::GZ(float x) // 设置工资
{
money=x;
}
void GZ::calSDS() //成员函数 计算扣除个人所得税的实际工资数
{
float x=0.0;
cout