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

📄 cconsumemanager.cpp

📁 AA制消费管理系统(简易型) 实现账户信息
💻 CPP
字号:
#include "link.h"

/************************************************************************/
/* 默认构造函数                                                     */
/************************************************************************/
CConManager::CConManager()
{

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

}

/************************************************************************/
/* =重载函数                                                     */
/************************************************************************/
CConManager& CConManager::operator =(CConManager &conman)
{
	return conman;
}
/************************************************************************/
/* 对外接口函数                                                     */
/************************************************************************/
CConManager& CConManager::GetInstance()
{
	static CConManager appman;
	return appman;
}
/************************************************************************/
/* 向量容器获取函数                                                     */
/************************************************************************/
vector<CConsume>& CConManager::GetConsumeList()
{
	return VecConsume;
}
/************************************************************************/
/* 添加充值记录函数                                                     */
/************************************************************************/
void CConManager::AddNewCon(CConsume &con)
{
	VecConsume.push_back(con);
	SaveConsumeData();
}
/************************************************************************/
/* 充值记录个数获取函数                                                 */
/************************************************************************/
int CConManager::GetSize()
{
	return VecConsume.size();
}
/************************************************************************/
/* 充值记录查看函数                                                     */
/************************************************************************/
CConsume& CConManager::GetConsume(int _id)
{
	if(_id<=GetSize())
		return VecConsume[_id];
	else
		return *VecConsume.end();
}
/************************************************************************/
/* 充值记录保存函数                                                     */
/************************************************************************/
bool CConManager::SaveConsumeData(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;
	int _id;
	string	_idlist;
	string	_date;
	float	_money;
	int		_mancount;
	string _comment;
	count=VecConsume.size();
	file.write((char *)&count,sizeof(count));
	for (i=0;i<count;i++)
	{
		
		//保存id
		_id=VecConsume[i].GetID();
		file.write((char *)&_id,sizeof(_id));
		//保存消费人数
		_mancount=VecConsume[i].GetManCount();
		file.write((char *)&_mancount,sizeof(_mancount));
		//保存消费编号名单表
		len=VecConsume[i].GetIDList().length();
		file.write((char *)&len,sizeof(len));
		_idlist=VecConsume[i].GetIDList();
		file.write(_idlist.c_str(),len);
		//保存日期
		len=VecConsume[i].GetDate().length();
		file.write((char *)&len,sizeof(len));
		file.write(VecConsume[i].GetDate().c_str(),len);
		//保存消费金额
		_money=VecConsume[i].GetMoney();
		file.write((char *)&_money,sizeof(_money));
		//保存备注
		len=VecConsume[i].GetComment().length();
		file.write((char *)&len,sizeof(len));
		file.write(VecConsume[i].GetComment().c_str(),len);
		
	}
	file.close();
	return true;
}





/************************************************************************/
/* 充值记录读取函数                                                     */
/************************************************************************/
bool CConManager::RestoreConsumeData(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 false;
	}
	int i,count,len;
	int _id;
	float _money;
	string	_idlist;
	string	_date;
	int		_mancount;
	char tempstr[200];
	CConsume tempcon;
	file.read((char*)&count,sizeof(count));
	for (i=0;i<count;i++)
	{
		//读取编号
		file.read((char *)&_id,sizeof(_id));
		tempcon.SetID(_id);
		//读取消费人数
		file.read((char *)&_mancount,sizeof(_mancount));
		tempcon.SetManCount(_mancount);
		//读取消费编号名单表
		file.read((char *)&len,sizeof(len));
		file.read(tempstr,len);
		tempstr[len]=0;
		tempcon.SetIDList(tempstr);
		//读取日期
		file.read((char *)&len,sizeof(len));
		file.read(tempstr,len);
		tempstr[len]=0;
		tempcon.SetDate(tempstr);
		//读取消费值额
		file.read((char *)&_money,sizeof(_money));
		tempcon.SetMoney(_money);
		//读取备注
		file.read((char *)&len,sizeof(len));
		file.read(tempstr,len);
		tempstr[len]=0;
		tempcon.SetComment(tempstr);
		//临时账户添加到向量容器
		VecConsume.push_back(tempcon);
	}
	file.close();
	return true;
}

⌨️ 快捷键说明

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