⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc0806.cpp

📁 工资管理的一个小程序
💻 CPP
字号:
#include <afx.h>
#include <iostream.h>
// 定义工资类
class Salary
{
	float		m_fWage;				// 基本工资
	float		m_fSubsidy;			// 岗位津贴
	float		m_fInsurance;		// 劳保福利
	float		m_fRent;				// 房租
	float		m_fCostOfElec;		// 电费
	float		m_fCostOfWater;		// 水费
	float		m_fCostOfHeating;	// 取暖费
public:
	void ShowMessage();
	Salary();
	void SetWage(float fWage){		// 填写基本工资
		m_fWage = fWage;
	};
	void SetSubsidy(float fSubsidy){	// 填写岗位津贴
		m_fSubsidy = fSubsidy;
	};
	void SetInsurance(float fInsurance){		// 填写劳保福利
		m_fInsurance = fInsurance;
	};
	void SetCostOfWater(float fCostOfWater){	// 填写水费
		m_fCostOfWater = fCostOfWater;
	};
	void SetCostOfElec(float fCostOfElec){	// 填写电费
		m_fCostOfElec = fCostOfElec;
	};
	void SetCostOfHeating(float fCostOfHeating){	// 填写取暖费
		m_fCostOfHeating = fCostOfHeating;
	};
	float GetWage(){					// 查看基本工资
		return m_fWage;
	};
	float GetSubsidy(){				// 查看岗位津贴
		return m_fSubsidy;
	};
	float GetInsurance(){			// 查看劳保福利
		return m_fInsurance;
	};
	float GetCostOfWater(){			// 查看水费
		return m_fCostOfWater;
	};
	float GetCostOfElec(){			// 查看电费
		return m_fCostOfElec;
	};
	float GetCostOfHeating(){		// 查看取暖费
		return m_fCostOfHeating;
	};
	float	RealSum(){				// 计算实发工资
		return m_fWage + m_fSubsidy+m_fInsurance
			-m_fRent-m_fCostOfElec-m_fCostOfWater-m_fCostOfHeating;
	};
	void Save_Salary(CFile* p);
	void Read_Salary(CFile* p);
};
// 定义职务类型
enum Position
{
	MANAGER,						// 经理
	ENGINEER,						// 工程师
	EMPLOYEE,						// 职员
	WORKER							// 工人
};
void Salary::Save_Salary(CFile* p)
{
	p->SeekToEnd();
	p->Write(this,sizeof(Salary));
}
void Salary::Read_Salary(CFile* p)
{
	p->Read(this,sizeof(Salary));
}
void main()
{   int  i;
	Salary m_salary[10];
	CFile m_cfile;
	//存盘
	try
	{
	m_cfile.Open("salary.dat",CFile::modeCreate|CFile::modeReadWrite);
	}
	catch(CFileException *)
	{
		cout<<"文件操作错误!"<<endl;
	}
	for(i=0;i<2;i++)
	{
		m_salary[i].SetWage(2000);
		m_salary[i].SetSubsidy(2000);
		m_salary[i].SetCostOfElec(2000);
		m_salary[i].ShowMessage();
		m_salary[i].Save_Salary(&m_cfile);
		cout<<"---------------------------------"<<endl;
	}
	
	
	//查询
	//读取
	for(i=0;i<2;i++)
	{
		m_salary[i].Read_Salary(&m_cfile);
		m_salary[i].ShowMessage();
		cout<<"----------------------------------"<<endl;
	}
	m_cfile.Close();
}

Salary::Salary()
{
	m_fWage=1000;
	m_fSubsidy=500;
	m_fInsurance=0;
	m_fRent=0;
	m_fCostOfElec=0;
	m_fCostOfWater=0;
	m_fCostOfHeating=0;

}

void Salary::ShowMessage()
{
	cout<<"CostOfElec:"<<this->m_fCostOfElec<<endl;
	cout<<"Wage:"<<this->m_fWage<<endl;
	cout<<"Subsidy:"<<this->m_fSubsidy<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -