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

📄 cappmoneymanager.cpp

📁 AA制消费管理系统(简易型) 实现账户信息
💻 CPP
字号:
#include "link.h"
/************************************************************************/
/* 默认构造函数                                                     */
/************************************************************************/
CAppMoneyManager::CAppMoneyManager()
{

}
/************************************************************************/
/* 复制构造函数                                                     */
/************************************************************************/
CAppMoneyManager::CAppMoneyManager(CAppMoneyManager &appman)
{

}

/************************************************************************/
/* =重载函数                                                     */
/************************************************************************/
CAppMoneyManager& CAppMoneyManager::operator =(CAppMoneyManager &appman)
{
	return appman;
}
/************************************************************************/
/* 对外接口函数                                                     */
/************************************************************************/
CAppMoneyManager& CAppMoneyManager::GetInstance()
{
	static CAppMoneyManager appman;
	return appman;
}
/************************************************************************/
/* 添加充值记录函数                                                     */
/************************************************************************/
void CAppMoneyManager::AddNewAppmoneyReport(CAppMoney &cmreport)
{
	VecMoney.push_back(cmreport);
	SaveAppMoneyData();
}
/************************************************************************/
/* 充值记录个数获取函数                                                 */
/************************************************************************/
int CAppMoneyManager::GetSize()
{
	return VecMoney.size();
}
/************************************************************************/
/* 充值记录列表获取函数                                                 */
/************************************************************************/
vector<CAppMoney>& CAppMoneyManager::GetVecMoneyList()
{
	return VecMoney;
}
/************************************************************************/
/* 充值记录查看函数                                                     */
/************************************************************************/
CAppMoney& CAppMoneyManager::GetAppMoneyInfo(int _id)
{
	if(_id<=GetSize())
		return VecMoney[_id];
	else
		return *VecMoney.end();
}
/************************************************************************/
/* 充值记录保存函数                                                     */
/************************************************************************/
bool CAppMoneyManager::SaveAppMoneyData(char *filename/* = */)
{
	fstream file;
	file.open(filename,ios::out|ios::binary);
	if (!file)
	{
		cerr<<"File Open or Create Fail!"<<endl;
		return 0;
	}
	int i,count,len,id;
	float money;
	count=VecMoney.size();
	file.write((char *)&count,sizeof(count));
	for (i=0;i<count;i++)
	{
		//保存id
		id=VecMoney[i].GetID();
		file.write((char *)&id,sizeof(id));
		//保存姓名
		len=VecMoney[i].GetName().length();
		file.write((char *)&len,sizeof(len));
		file.write(VecMoney[i].GetName().c_str(),len);
		//保存日期
		len=VecMoney[i].GetDate().length();
		file.write((char *)&len,sizeof(len));
		file.write(VecMoney[i].GetDate().c_str(),len);
		//保存充值金额
		money=VecMoney[i].GetMoney();
		file.write((char *)&money,sizeof(money));
		//保存备注
		len=VecMoney[i].GetComment().length();
		file.write((char *)&len,sizeof(len));
		file.write(VecMoney[i].GetComment().c_str(),len);
	}
	file.close();
	return true;
}





/************************************************************************/
/* 充值记录读取函数                                                     */
/************************************************************************/
bool CAppMoneyManager::RestoreAppMoneyData(char *filename/* = */)
{
	fstream file;
	if(access(filename,0)==-1)
		return false;
	file.open(filename,ios::in|ios::binary);
	if (!file)
	{
		cerr<<"File Open Fail!!"<<endl;
		return 0;
	}
	int i,count,len,_id;
	float _money;
	char tempstr[200];
	string _name;
	CAppMoney tempapp;
	file.read((char*)&count,sizeof(count));
	for (i=0;i<count;i++)
	{
		//读取编号
		file.read((char *)&_id,sizeof(_id));
		tempapp.SetID(_id);
		//读取姓名
		file.read((char *)&len,sizeof(len));
		file.read(tempstr,len);
		tempstr[len]=0;
		tempapp.SetName(tempstr);
		//读取日期
		file.read((char *)&len,sizeof(len));
		file.read(tempstr,len);
		tempstr[len]=0;
		tempapp.SetDate(tempstr);
		//读取充值额
		file.read((char *)&_money,sizeof(_money));
		tempapp.SetMoney(_money);
		//读取备注
		file.read((char *)&len,sizeof(len));
		file.read(tempstr,len);
		tempstr[len]=0;
		tempapp.SetComment(tempstr);
		//临时账户添加到向量容器
		VecMoney.push_back(tempapp);
	}
	file.close();
	return true;
}

⌨️ 快捷键说明

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