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

📄 normaluserlist.cpp

📁 呵呵 就是大学二年级的我的课程设计啦
💻 CPP
字号:
#include"NormalUserList.h"
/////////////////////////////////////////////////////////////
NormalUserList::Iterator NormalUserList::finduser(int type,char pattern[],Iterator from)//查找银行用户函数
{//功能:根据不同的信息查找链表中指定的节点
 //参数:查找类型type 查找关键字 pattern 查找的起始位置from
 //返回:查找到的节点的指针
	Iterator it;
	Iterator it_end = userlist.end();
	it=from;
	while(it!=it_end)
	{
		if((type == 1 && pattern == (*it)->account) || 
		   (type == 2 && pattern == (*it)->name) ||
		   (type == 3 && (*it)->tobedeleted == true) ||
		   (type == 4 && (*it)->tobedopsited == true) ||
		   (type == 5 && (*it)->tobefreezed == true) ||
		   (type == 6 && (*it)->activation == false) )
		{
			break;	
		}
		it++;
	}
	return it;
}
/////////////////////////////////////////////////////////////
void NormalUserList::adduser(User* rec)//添加一个银行用户信息到链表中
{//功能:添加一个银行用户信息到链表中
 //参数:指向一个用户结构体的指针
	if(rec!=NULL)
		userlist.push_back(rec);

}
/////////////////////////////////////////////////////////////
void NormalUserList::saveuserlist(ostream& os)//保存银行用户链表信息到文件
{//功能:保存银行用户链表信息到文件
 //参数:文件输出流os
	os << userlist;
}
/////////////////////////////////////////////////////////////
void NormalUserList::loaduserlist(istream& is)//读取文件中银行用户信息到链表
{//功能:读取银行用户链表信息到文件
 //参数:文件输入流is
	cout << "userlist.txt文件载入成功!"<<endl;
	is >> userlist;
}
/////////////////////////////////////////////////////////////
void NormalUserList::modifycipher(Iterator it)//修改指定节点的密码
{//功能:修改指定用户的密码
 //参数:指向指定节点的指针
	cout<< "请输入你的原始密码:";
	char c,cipher[20];
	int k=0,i=0;
    for(k=0;k<20;k++)
	{
	    cipher[k]='\0';
	}
    c=getch();   
    while(c != '\r')
    {  
		if(i >= 0)
		{
			if (c == '\b')
			{
                cout<<"\b \b";
                i = i - 1;                 
			}
            else
			{
				cout<<"*";
                cipher[i] = c;          
			}              
		}
        c = getch();
        if(c != '\b')
			i = i + 1;
    }
	if((*it)->cipher != cipher)
		cout << "密码输入错误\n";
	else 
	{
		cout<< "请输入你的新密码:";
	    char c,cipher[20];
	    int k=0,i=0;
        for(k=0;k<20;k++)
		{
			cipher[k]='\0';
		}
        c=getch();   
        while(c != '\r')
		{  
		    if(i >= 0)
		{
			if (c == '\b')
			{
                cout<<"\b \b";
                i = i - 1;                 
			}
            else
			{
				cout<<"*";
                cipher[i] = c;          
			}              
		}
        c = getch();
        if(c != '\b')
			i = i + 1;
		}
		(*it)->cipher = cipher;
		cout << "\n你的银行密码修改成功\n你的新密码为"<<cipher;
	}
}
/////////////////////////////////////////////////////////////
void NormalUserList::markectdeleteduser(Iterator it)//标记指定节点的待删除标记
{//功能:将指定节点的删除标记 标记为 true
 //参数:指向指定节点的指针
	if((*it)->tobedeleted = true)
		cout<<"删除标记成功\n";
	else (*it)->tobedeleted = true;
}
/////////////////////////////////////////////////////////////
void NormalUserList::pushmoney(Iterator it,double money)//修改指定节点的存钱数目
{//功能:用户进行存钱时 并且标记为存钱标记为true
 //参数:指向指定节点的指针
	(*it)->depositmoney = money;
	(*it)->tobedopsited = true;
}
/////////////////////////////////////////////////////////////
void NormalUserList::popmoney(Iterator it,double money)//修改指定节点的取钱数目
{//功能:用户取钱
	if((*it)->remainingmoney >0 && (*it)->remainingmoney > money)
		(*it)->remainingmoney = (*it)->remainingmoney - money;
	else
		cout<<"你的余额不够!\n";
	
}
/////////////////////////////////////////////////////////////
void NormalUserList::outputuser(Iterator it)//输出节点信息
{//功能:输出指定节点的信息
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	cout << setiosflags(ios::left)
		 <<setw(16)<<"银行账号"<<setw(16)<<"用户姓名"<<setw(16)<<"用户密码"<<setw(16)<<"总金额"<<setw(16)<<"欲存钱数";
	cout <<setw(16)<<(*it)->account<<setw(16)<<(*it)->name<<setw(16)<<(*it)->cipher<<setw(16)<<(*it)->remainingmoney<<setw(16)<<(*it)->depositmoney;
	cout <<setw(16)<<" "<<setw(16)<<"删除状态"<<setw(16)<<"冻结状态"<<setw(16)<<"激活状态"<<setw(16)<<"开户时间";
	cout <<setw(16)<<" ";

	if((*it)->tobedeleted == true)
		cout <<setw(16)<< "等待删除";
	else 
		cout <<setw(16)<< "正常";
	if((*it)->tobefreezed == true)
		cout <<setw(16)<< "已经冻结";
	else
		cout <<setw(16)<< "正常";
	if((*it)->activation == true)
		cout <<setw(16)<< "已激活";
	else
		cout <<setw(16)<< "等待激活";
	cout <<setw(16)<<(*it)->time;
	cout <<"________________________________________________________________________________";
}
/////////////////////////////////////////////////////////////
ostream& operator << (ostream& os,const list<User*>& r1)//重载输出流〈〈
{//重载输出流〈〈
	list<User*>::const_iterator it;
	list<User*>::const_iterator it_end = r1.end();
	os<<r1.size()<<endl;
	for (it=r1.begin(); it!=it_end; it++)
	{
		os << setiosflags(ios::left)
		   << setw(16) << (*it)->account
		   << setw(16) << (*it)->cipher
		   << setw(16) << (*it)->name 
		   << setw(16) << (*it)->remainingmoney 
		   << setw(16) << (*it)->depositmoney 
		   << setw(4) << (*it)->tobedeleted 
		   << setw(4) << (*it)->tobedopsited 
		   << setw(4) << (*it)->tobefreezed 
		   << setw(4) << (*it)->activation
		   << setw(16) << (*it)->time
		   <<endl;
	}
	return os;
}
/////////////////////////////////////////////////////////////
istream& operator >> (istream& is,list<User*>& c_r2)//重载输入流〉〉
{//重载输入流〉〉
	User* rec;
	string account;
	int size;
	is >>  size;
	while(!is.eof() && size!=0)
	{
		rec=new User;
		is >> setiosflags(ios::left)
		   >> setw(16) >> rec->account
		   >> setw(16) >> rec->cipher
		   >> setw(16) >> rec->name 
		   >> setw(16) >> rec->remainingmoney 
		   >> setw(16) >> rec->depositmoney  
		   >> setw(4) >> rec->tobedeleted 
		   >> setw(4) >> rec->tobedopsited 
		   >> setw(4) >> rec->tobefreezed
		   >> setw(4) >> rec->activation
		   >> setw(16) >> rec->time;
		c_r2.push_back(rec);
		size--;
	}
	return is;	
}
/////////////////////////////////////////////////////////////
bool NormalUserList::nouser(char pattern[])//验证银行账号是否存在
{//功能:验证用户账号是否存在
 //参数:输入的用户名称
 //返回:存在返回true 不存在结返回false
	list<User*>::iterator it = userlist.begin();
	list<User*>::iterator it_end = userlist.end();
	int i=0;
	while(it!=it_end)
	{
		if( !(pattern == (*it)->account))
		{
			i++;
		}
		it++;
	}
	if(i==size())
		return true;
	else
		return false;
}
/////////////////////////////////////////////////////////////////
bool NormalUserList::checked(char account[])//验证用户密码是否正确的函数
{//功能:验证用户密码是否正确
 //参数:输入的用户名称
 //返回:正确返回true 不正确结返回false
	 Iterator it;
     it = finduser(1,account,userlist.begin());
	 cout<<"请输入密码:";
	 char c,cipher[20];
	 int k=0,i=0;
     for(k=0;k<20;k++)
	 {
	     cipher[k]='\0';
	 }
     c=getch();   
     while(c != '\r')
     {  
		 if(i >= 0)
		 {
			 if (c == '\b')
			 {
                 cout<<"\b \b";
                 i = i - 1;                 
			 }
             else
			 {
				 cout<<"*";
                 cipher[i] = c;          
			 }              
		 }
        c = getch();
        if(c != '\b')
            i = i + 1;
	 }
	 if((*it)->cipher==cipher)
		 return true;
	 else
		 return false;
}
//////////////////////////////////////////////////////////
bool NormalUserList::freezed(char account[])//验证用户是否被冻结
{//功能:验证用户是否被冻结
 //参数:输入的用户名称
 //返回:冻结返回true 未被冻结返回false
	Iterator it;
    it = finduser(1,account,userlist.begin());
	if((*it)->tobefreezed == true)
	    return true;
	else
		return false;
}
/////////////////////////////////////////////////////////
bool NormalUserList::activation(char account[])//验证用户是否被激活
{//功能:验证用户是否被激活
 //参数:输入的用户名称
 //返回:激活返回true 未被激活返回false
	Iterator it;
    it = finduser(1,account,userlist.begin());
	if((*it)->activation == true)
	    return true;
	else
		return false;
}

⌨️ 快捷键说明

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