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

📄 menufunc.cpp

📁 银行仿真系统 简单易行的银行系统 具有用户登录 利率查询 转帐等功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	double dMoney;
	Date nowday;
	dperson->UpdatePro();						//更新存款(加利息)
	cout << "请输入要储蓄的金额(单位:元)  " ;
	cin >> dMoney;
	dperson->ChaMon(dperson->GetMon() + dMoney);
	cout << "存款成功!" << endl;
	cout << "您的余额还有:  " << dperson->GetMon() << endl;
	return dperson;
}

void UpdateRate()				//利率更新
{
	double urate;
	cout << "请输入要更新的年利率(0.***):  ";
	cin >> urate;
	ofstream ofile("rate.txt");
	ofile<<urate<<endl;
	ofile.close();
	cout << "年利率更新成功!" <<endl;
}

double rate()   //将利率写入文件
{
  double rat;
  ifstream file("rate.txt");  //将利率写入文件
  file>>rat;
  return rat; //返回利率
}

Account * Adjust(Account * newP)						//修改帐户密码
{  Account *p=NULL;
Date date;
    int y,m,d;
	 char NewPass[7],Pass[7];
     cout<<"请输入当前日期";
	 cin>>y>>m>>d;
     if(!protect(newP))						//三次输入密码均不正确,quit
		return NULL;
	cout << "请输入新密码: ";
	cin >> NewPass;
	for(int i=0;i<6;i++)                         //判断输入是否为六位数字
	{
		if((NewPass[i]<48)||(NewPass[i]>57))
		{
			cout<<"应输入六位数字,请重新输入"<<endl;
			cin>>NewPass;
			i=0;
		}
	}
	cout << "请再次输入新密码: ";
	cin >> Pass;
	while(strcmp(NewPass , Pass) != 0)
	{
		cout << "密码输入不一致!" << endl
			<< "请输入新密码: ";
		cin >> NewPass;
		cout <<"请再次输入新密码: ";
		cin >> Pass;
	}
	cout<<"密码更改需要7天时间,请七天后再来"<<endl;
	newP->ChaPass(NewPass);
	Date a(y,m,d);
	newP->ChaDate(a);
	FileCustomer1(newP,ReadFile2());    //将修改过密码的用户写入文件
	cout <<  endl;
	return newP;
}

bool Adjust(Enter * newP)						//修改管理员密码
{
	char NewPass[7],Pass[7];
	//密码保护
	if(!protect(newP))						//三次输入密码均不正确,quit
		return 0;
	cout << "请输入新密码: ";
	cin >> NewPass;
	for(int i=0;i<6;i++)                         //判断输入是否为六位数字
	{
		if((NewPass[i]<48)||(NewPass[i]>57))
		{
			cout<<"应输入六位数字,请重新输入"<<endl;
			cin>>NewPass;
			i=0;
		}
	}
	cout << "请再次输入新密码: ";
	cin >> Pass;
	while(strcmp(NewPass , Pass) != 0)
	{
		cout << "密码输入不一致!" << endl
			<< "请输入新密码: ";
		cin >> NewPass;
		cout <<"请再次输入新密码: ";
		cin >> Pass;
	}
	newP->Change(NewPass);
	cout << "密码修改成功!" << endl;
	return 1;
}

bool DisplayAcc(Account * newP)					//帐户查询
{	//密码保护
	if(!protect(newP))						//三次输入密码均不正确,quit
		return 0;
	cout <<endl<< "帐户:" << newP->GetName() << "的基础资料如下:" << endl 
		<< "银行卡号或者存折号码:       " << newP->GetID() << endl
		<< "帐户余额:       " << newP->GetMon() << endl
		<< "最后存取款日期: " << newP->GetDay() << endl 
		<<"手机号码是"<<newP->Tel.TelNum()<< endl
		<<"手机帐号余额是"<<newP->Tel.Getremain()<< endl<< endl;
    return 1;
}

void DisplayRate()				//利率查询
{
	cout<<"当前年利率为:"<<rate()<<endl;
}

void withdraw(Account * person,int x)					//帐户取款
{
	while( x > person->GetMon() )
	{
		cout << "取款金额超出存款金额!" << endl << "请重新输入提取金额(单位:元)  " ;
		cin >> x;
	}
	person->ChaMon(person->GetMon() - x);
	cout << "您的银行账号余额还有:  "<<person->GetMon() << endl;	
}

Account * Charge(Account * dperson)                             //手机费用充值
{
	double aaa;
	dperson->UpdatePro();						//更新存款(加利息)
	if(!protect(dperson))						//三次输入密码均不正确,quit
		return NULL;
	cout<<"请输入您要充值的数额(单位:元)"<<endl;
	cin>>aaa;
	withdraw(dperson,aaa);  //账户取款
	dperson->Tel.add(aaa);
	return dperson;
}


void FileCustomer1(Account *pnewP,Account *head)  //将修改过密码的用户信息写入文件
{
	Account *p1=NULL,*p2=NULL,*p3=NULL,*p4=NULL;
   int i=0;
   p1=head;
 if(p1==NULL)
 {
	head=pnewP;
    pnewP->pointer=NULL;
 }
else 
{
	while(p1!=NULL)
	{
		p4=p1->pointer;
		if(p1==head)
		{ 
			if(strcmp(p1->GetID(),pnewP->GetID())==0)
			{  head=pnewP;
			   head->pointer=p4;
		       i++;
			   break;
			}
		}
		else 
		{
			  if(strcmp(p1->GetID(),pnewP->GetID())==0)
			  {
				 p3->pointer=pnewP;
				 pnewP->pointer=p4;
				 i++;
				 break;
			  }
		}
	   p3=p1;
	   p1=p1->pointer;
	}
    if(i==0)
	{
		p3->pointer=pnewP;
        pnewP->pointer=NULL;
	}
}
p2=head;
ofstream ofile("Customer(change password).txt");   //将修改过密码的用户信息写入文件
while(p2!=NULL)
{
   ofile<<p2->GetName()<<" "<<p2->GetMon()<<" "<<p2->GetID()<<" "<<p2->GetDay().year<<" "<<p2->GetDay().month<<" "<<p2->GetDay().day<<" "<<p2->GetPass()<<" "<<p2->Tel.TelNum()<<" "<<p2->Tel.Getremain()<<endl;
   p2=p2->pointer;
}  
ofile.close();
}



bool Delet(Account *  head)							//清除帐户
{
	Account * p , * q;
	char YorN;
	char dID[19];		//银行卡号或者存折号码
	if(head == NULL)
	{
		cout << "没有帐户入库!" << endl;
		return 0;		//quit
	}
	cout << "请输入要清空的帐户银行卡号或者存折号码:";
	cin >> dID;
	cout << "将要清空帐户 " << dID << " 确定请按'Y',退出请按其他键. ";	//再次确认
	cin >> YorN;
	if( !(YorN == 'Y' || YorN == 'y') )
	{
		return 0;					//quit
	}
	p = head;
	while(strcmp(dID ,p->GetID()) != 0 && p->pointer != NULL)	
	{													//p指向的不是所求,且后面还有节点
		q = p ;
		p = p->pointer;
	}
	if(strcmp(dID , p->GetID() )== 0)		//找到,p指向所要删除的节点
	{
		if(p == head)						//在头部
			head = p->pointer;
		else		
			q->pointer = p->pointer;		//中间或尾部
		delete p;							//释放
		cout << "成功清空帐户!" << endl;
        FileCustomer2(head);
		return 1;
	}
	else 
		cout << "帐户" << dID << "不存在!" << endl
		<< "请确认输入号码无误. " << endl;
	return 0;
}

bool Delet(Enter *  head)							//清除帐户
{
	Enter * p , * q;
	char YorN;
	char dID[19];		//管理员编号
	if(head == NULL)
	{
		cout << "没有管理员入库!" << endl;
		return 0;		//quit
	}
	cout << "请输入要清空管理员编号:" << endl;
	cin >> dID;
	cout << "将要清空帐户 " << dID << " 确定请按'Y',退出请按其他键. ";	//再次确认
	cin >> YorN;
	if( !(YorN == 'Y' || YorN == 'y') )
	{
		return 0;					//quit
	}
	p = head;
	while(strcmp(dID ,p->Getnum()) != 0 && p->pointer != NULL)	
	{													//p指向的不是所求,且后面还有节点
		q = p ;
		p = p->pointer;
	}
	if(strcmp(dID , p->Getnum() )== 0)		//找到,p指向所要删除的节点
	{
		if(p == head)						//在头部
			head = p->pointer;
		else		
			q->pointer = p->pointer;		//中间或尾部
		delete p;							//释放
		cout << "成功清空管理员!" << endl;
		FileClerk1(head);
		return 1;
	}
	else 
		cout << "管理员编号" << dID << "不存在!" << endl
		<< "请确认输入号码无误. " << endl;
	return 0;
}

Account * Transfer(Account * outper)		//用户转帐
{
	char YorN , Con;
	double tmoney;
	Account * getper = NULL;
	//密码保护
	if(!protect(outper))			//三次输入密码均不正确,quit
		return 0;	
	cout << "下面将输入受主的基本信息输入."<< endl ;
	getper = Find(ReadFile());
	while(getper == NULL) 
	{
		cout << "受主帐户不存在!"<<endl << "退出转帐请按'Q',继续请按其他键. ";
		cin >> Con;
		if(Con == 'Q' || Con == 'q')
			return NULL;
		cout << endl << "请重新输入,并确认输入无误."<<endl;
		getper = Find(ReadFile());
        
	}
	cout << "即将执行转帐业务,确认请按'Y',退出请按其他键.";
	cin >> YorN;
	if( YorN == 'Y' || YorN == 'y' )
	{
		getper->UpdatePro();		//先结算帐户的利润
		outper->UpdatePro();		
		cout << "请输入转移金额(单位:元)  ";
		cin >> tmoney;
		while(tmoney > outper->GetMon())				//转移金额不超过现有存款
		{
			cout << "转移金额超出存款金额!"<<endl
				<<"现有存款:  "<<outper->GetMon() << endl
				<<"请重新输入:  ";
			cin >> tmoney;
		}
		outper->ChaMon(outper->GetMon() - tmoney);
		FileCustomer(outper,ReadFile());		  //将最新用户信息写入文件
		getper->ChaMon(getper->GetMon() + tmoney);
		return getper;
	}
	return NULL;
}


bool show(Account *  head)    //显示所有帐户信息
{
	Account * p ;
	char YorN;
	if(head == NULL)				//链表为空
	{
		cout << "尚且不存在任何帐户." << endl << "添加帐户请按'Y',以后添加请按其他键." << endl;
		cin >> YorN;
		if(YorN == 'Y' || YorN == 'y')
		{
			head = Add();			//添加首个帐户
            FileCustomer(head,ReadFile());   //将最新用户信息写入文件
		}
		else  
			return 0;
	}
	p = head;
	cout << endl <<"所有帐户信息如下:" <<endl;
	while(p)
	{
		cout << "帐户名:  " << p->GetName() <<endl
			<<"银行卡号或者存折号码:  " << p->GetID() <<endl
			<<"上次存取款日期:  " << p->GetDay()<<endl
			<<"帐户余额(单位:元)  " << p->GetMon() <<endl
			<<"手机号码是"<< p->Tel.TelNum()<<endl
		    <<"手机费余额是"<<p->Tel.Getremain()<<endl
			<< endl;
		p = p ->pointer;
	}
	return 1;
}

Enter * ChangeEnter(Enter * & cpass)									//修改管理员进入密码
{
	int i = 0;
	char cPassword[7] , NewPass[7];
	cout <<"请输入管理员6位旧密码:  ";
	cin >> cPassword;
	while(strcmp(cPassword,cpass->Getpass()) != 0) 
	{
		if( i > 1) return NULL; //输入3次密码均错误,退出
		cout << "密码输入有误! 请重新输入密码:  ";
		cin >> cPassword;
		i ++;
	}
	cout << "请输入新密码: ";
	cin >> cPassword;
	cout << "请再次输入新密码: ";
	cin >> NewPass;
	while(strcmp(NewPass , cPassword) != 0)
	{
		cout << "密码输入不一致!" << endl
			<< "请输入新密码: ";
		cin >> cPassword;
		cout <<"请再次输入新密码: ";
		cin >> NewPass;
	}
	cpass->Change(NewPass);
	cout << "密码修改成功!" << endl<< endl;
	return cpass;

}

bool  Changemanager()									//修改经理进入密码
{
	int i = 0;
	char cPassword[7] , NewPass[7];
	cout <<"请输入经理6位旧密码:  ";
	cin >> cPassword;
	while(strcmp(cPassword,Password()) != 0) 
	{
		if( i > 1) return 0; //输入3次密码均错误,退出
		cout << "密码输入有误! 请重新输入密码:  ";
		cin >> cPassword;
		i ++;
	}
	cout << "请输入新密码: ";
	cin >> cPassword;
	cout << "请再次输入新密码: ";
	cin >> NewPass;
	while(strcmp(NewPass , cPassword) != 0)
	{
		cout << "密码输入不一致!" << endl
			<< "请输入新密码: ";
		cin >> cPassword;
		cout <<"请再次输入新密码: ";
		cin >> NewPass;
	}
	ofstream ofile("Password.txt");   //将修改后的密码写入文件
	ofile<<cPassword<<endl;
	cout << "密码修改成功!" << endl<< endl;
	return 1;
}

char * Password()      //读取存有经理密码的文件并返回密码
{
	char  pass[7];
	ifstream file("Password.txt");   //读取存有经理密码的文件
	file>>pass;
	return pass;    //返回密码
}

void FileClerk1(Enter *head)        //将删除后的管理员信息写入文件
{  Enter *p2;
   p2=head;
   ofstream ofile("Clerk.txt");       //将删除后的管理员信息写入文件
   while(p2!=NULL)
   {
     ofile<<p2->Getnum()<<" "<<p2->Getpass()<<endl;
     p2=p2->pointer;
   }  
   ofile.close();
   cout << "管理员信息已更新!" << endl;
}

void FileCustomer2(Account *p2)       //将删除后的用户信息写入文件
{
  ofstream ofile("Customer.txt");     //将删除后的用户信息写入文件
  while(p2!=NULL)
  {
   ofile<<p2->GetName()<<" "<<p2->GetMon()<<" "<<p2->GetID()<<" "<<p2->GetDay().year<<" "<<p2->GetDay().month<<" "<<p2->GetDay().day<<" "<<p2->GetPass()<<" "<<p2->Tel.TelNum()<<" "<<p2->Tel.Getremain()<<endl;
   p2=p2->pointer;
  }  
  ofile.close();
  cout<<"帐户已更新"<<endl;
}

⌨️ 快捷键说明

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