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

📄 function.h

📁 atm老师的作业
💻 H
📖 第 1 页 / 共 2 页
字号:
#include "account.h"


   
	bool checkpassword1(int state);          // 核对密码
	bool checkpassword2();          //////////////////////////////////////////////
	bool passwordlen(char pwd[]);   //察看查看密码的长度

	void changepassword();          // 修改密码
	void fetchmoney();	            // 取款
	void depositmoney();            //存款
    void lookaccount();             //查看一个帐户信息

	void information1(float money1); //查询createaccount的信息
	void exitsystem();              // 退出系统
	void createaccount();           //创建一个用户//写道文件就要的了
	int lookallaccount();           //查看所以的帐户信息
	int lookaccount_note(char num[]); //查看一个帐户日志
	int lookallaccount_note();       //查看所以的帐户日志

	void functionshow1();             // 功能界面1
	void functionshow2();             // 功能界面2
    void welcome();                 // 登陆界面
	void sleep1(int time1);           // 如果出现可疑才操作那么计算机睡觉三分钟
 
	int file1(int state);            //从account文件里面得到信息并,验证用户的信息
	int file2 ();                    //验证管理员
    int file3();                     //每操作完成后用来保存数据,,,,,;                
	int create_note();               //创建日志文件
    int add_note(char information1[],char method1[],float money1); //添加日志消息  

void exitsystem()
{
    cout<<endl<<"感谢你对我的支持,欢迎下次光临!"<<endl;
    cout<<"请取卡……"<<endl;
    exit(0);
}

 void sleep1(int time1)// 如果出现可疑才操作那么计算机睡觉三分钟
{
	time_t a,b;
	a=time(NULL);
	while(b-a<=time1)
	{b=time(NULL);}
 } 

 bool passwordlen(char pwd[])//察看查看密码的长度
 {
	 if(strlen(pwd)==6)return true ;
	  else return false;
 } 

 /*bool checkpassword2()
 {
	 char pwd1[7];int time=0;
	 for(;;)
	 { cout<<"请输入密码:";
       cin>>pwd1;
	   if(passwordlen(pwd1))  break;
	   else cout<<"密码不足六位"<<endl;
	   time++;
	   if(time>=3) {cout<<"三次没有成功计算机休眠三分钟:"<<endl;getchar();sleep1(1800);}
	 }
	 if(strcmp(pwd1,system1.password)==0)
		return true;
	else return false;
 }*/

bool checkpassword1(int state)//state=0 表示核对account的密码,为1表示核对system的密码
{
	char pwd[7];
    int time=0;
    for(;;)
   {
	   cout<<"请输入密码:";
       cin>>pwd;
	   if(passwordlen(pwd))  break;
	   else cout<<"密码不足六位"<<endl;
	   time++;
	   if(time>=3) {cout<<"三次没有成功计算机休眠三分钟:"<<endl;getchar();sleep1(1800);}
   }
   if(state==0)
   { 
	   if(strcmp(pwd,account1.password)==0)
            return true;
       else return false;
   }

   else 
   {
	   if(strcmp(pwd,system1.password)==0)
	    	return true;
     	else return false;
   }
}


void welcome()
{
	char c;
	cout<<endl<<endl;
	cout<<"####################################################"<<endl;
  	cout<<"##            欢迎来到我的ATM银行!               ##"<<endl;
 	cout<<"####################################################"<<endl;
	cout<<endl<<endl;
	cout<<"1.管理员。"<<endl;
	cout<<"2.用户。"<<endl;
	cout<<"0.退出。"<<endl;
	cout<<"<0-2>"<<endl;
		cin>>c;
	while(c!='1'&& c!='2'&& c!='3')
	{
		cout<<"请输入合法的数据〈0到2〉"<<endl;
	    cin>>c;	  
	}
	switch(c)
	{
	case '1' :
	   file2 ();checkpassword1(1);functionshow1();break;
	case '2':
		if(file1(0))
			welcome();functionshow2();break;
	case '0':
       exitsystem();
	}

}

void functionshow2()
{
	char c;
    cout<<"1.存款业务"<<endl;
	cout<<"2.取款业务"<<endl; 
	cout<<"3.查询余额"<<endl;
	cout<<"4.修改密码"<<endl;   
	cout<<"0.退出"<<endl;
	cout<<"<0-4>"<<endl;
	cin>>c;
	while(c!='1' && c!='2' && c!='3' && c!='4' && c!='0')
	{
		cout<<"请输入合法的数据."<<endl;
		cin>>c;
	}
	switch (c)
	{
	case '1':
	    depositmoney();break;
	case '2':
		fetchmoney();	break;
	case '3':
	    information1(0.0);functionshow2(); break;
	case '4':
	    changepassword();break;
	case '0':
		welcome();
	}
}

void changepassword()
{ 
	int times=0; 
	float money1=0.0;
	char pwd1[7];
	char pwd2[7];
	char c;
	for(;;)
	{
		cout<<"请输入你的老密码:"<<endl;
		cin>>pwd1;
		if(strcmp(pwd1,account1.password)==0)
		{
			for(;;)
			{
				cout<<"请输入新的密码:"<<endl;
			    cin>>pwd1;
			    cout<<"请确认你的密码:"<<endl;
			    cin>>pwd2;
			    if(strcmp(pwd1,pwd2)==0 && strlen(pwd1)==6 && strlen(pwd2)==6)//验证密码的合法性
				{strcpy(pwd2,account1.password);
					strcpy(account1.password,pwd1);
				if(file3() )
				{ char information[80];char method[20];

				strcpy(method,"修改密码:" );
				  strcpy(information,"老密码 ");
				  strcat(information,pwd2);
				  strcat(information,"修改为 ");
				  strcat(information,pwd1);			

					if(add_note(information,method,money1))//保存操作记录
					{cout<<"操作成功:"<<endl<<"请牢记你的密码:"<<endl;}
					else {cout<<"不能够保存东东:"<<endl;cout<<"计算机错误!"<<endl;}
					getchar();
					 
				}functionshow2();} 
				else
				{
                if(strlen(pwd1)!=6) cout<<"密码要6位<0.放弃>,<enter,继续>"<<endl;
				else 
			     	cout<<"俩次输入的密码不同<0.放弃>,<enter,继续>:"<<endl;
				  	flushall();
				    c=getchar();
				 if(c=='0') functionshow2();
				 else break;
				}
			}
		}
		else
		{times++;
		if(times>=3) 
		{cout<<"对不起,三次没有操作成功,计算机休眠3分钟"<<endl;sleep1(1800);functionshow2();}
		 cout<<"非法:<0.返回>,<enter.继续>"<<endl;
		 c=getchar();
		 if(c=='0') functionshow2();
		}
	}
}

/*void information()
{char c;
 cout<<"**********************************"<<endl;
 cout<<"*"<<endl; 
 cout<<"*     用户姓名:"<<account1.name<<endl;
 cout<<"*     卡号:    "<<account1.num<<endl;
 cout<<"*     余额:     "<<account1.money<<endl;
 cout<<"**********************************"<<endl;
 cout<<endl<<endl;
 cout<<"任意键退出:"<<endl;
 c=getchar();
 functionshow2();
}*/

void information1(float money1)
{
	char c;
	time_t tm=time(NULL);
    cout<<"**********************************"<<endl;
    cout<<"*"<<endl; 
    cout<<"*     卡号:    "<<account1.num<<endl;
    cout<<"*     用户姓名:"<<account1.name<<endl;
    cout<<"*     余额:     "<<account1.money<<endl;
    if(money1!=0.0)//没有money的操作那么就不打印交易金额
	{cout<<"*     交易金额:"<<money1<<endl;
    cout<<"*     交易时间:"<<ctime(&tm)<<endl;}
    cout<<"**********************************"<<endl;
    cout<<endl<<endl;
    c=getchar();

}
void  depositmoney() //存款
{
	float money1=0.0;
	char c;
    char information[80];
	char method[20];
	while(1)
	{
		cout<<"请输入你的金额:";
	    cout<<"<输入0取消>";
     	cout<<"操作金额是:";
	    flushall();
     	cin>>money1;
		while(1)
		{
			if(money1<0.0) 
			{  
				cout<<money1<<"小于0:"<<endl<<"请输入合法的数据:"<<endl;
			    cout<<":"<<endl;
				cin>>money1;
			}
			else 
			{  
				strcpy(information,"存款操作 ");
			    strcpy(method,"存款: ");
			    account1.money+=money1;
			
			    if(file3()&&add_note(information,method,money1))//保存日志消息
				   cout<<"操作完成:"<<endl;
			   else cout<<"不能够保存,和管理员联系"<<endl;
			    cout<<"是否要求打印交易单?"<<endl;
				cout<<"<0.back:><enter.打印>"<<endl;
				c=getchar();
			    if(c!='0') information1(money1);	
				 functionshow2();
			}			
		}
	}


}

void fetchmoney()
{
	char information[80];
    char method[20];
	float mn;
	char c;

  for(;;)
  {
	while(1)
	{
	cout<<"<输入0取消>";
	cout<<"操作金额:";
	cin>>mn;
	if (mn<0.0) cout<<"输入错误,重新输入"<<endl;
	     else if(mn>account1.money) cout<<"余额不足!"<<endl; 
		   else break;
	}
	strcpy(information,"取款操作: ");
	strcpy(method,"取款:");
	account1.money=account1.money-mn;

	if(file3()&&add_note(information,method,mn))//保存日志消息
	cout<<"操作成功"<<endl<<"要打印交易单吗?<0.exit>,<enter,打印>"<<endl;
	else cout<<"不能够保存,和管理员联系"<<endl;
	flushall();
	c=getchar();
	if (c=='0') functionshow2();
	information1(mn); 
  }
}

void functionshow1()
{
	char num[20];
	char ch;
	char c;

	cout<<"1.创建一个用户。"<<endl;
	cout<<"2.查看一个帐户。"<<endl;
	cout<<"3.查看所有的帐户。"<<endl;
	cout<<"4.查看一个日志:"<<endl;
	cout<<"5.查看所以日志:"<<endl;
	cout<<"0.返回。"<<endl;
	cin>>c;
	while(c!='1' && c!='2' && c!='3' && c!='4' && c!='0' && c!='5')
	{

		cout<<"	请输入合法的数据!<0-5>"<<endl;
		cin>>c;
	}
	switch(c)
	{
	case '1':
		createaccount();break;
	case '2':
		lookaccount();break;
	case '3':
		if(lookallaccount()) functionshow1();break;
	case '4':
		if(!file1(1))
		{
			if(lookaccount_note(account1.num))
				while(1)
				{
					cout<<"<0退出><enter,继续>";
				    flushall();
					ch=getchar();
					if(ch=='0')functionshow1();	
					else 
					{cout<<"卡号:"<<endl;cin>>num;lookaccount_note(num);}
				}
		}
		else functionshow1(); break;
    case '5':
          lookallaccount_note();functionshow1();
	case '0':
		welcome();
	}
}

void lookaccount()
{
	char card[20];
	char c1,c;
	FILE *fp;
	if((fp=fopen("account","rb"))==0)
	{cout<<"can't open this file! any key to continue ";cin>>c;exit(0);}

	for(;;)
	{ 
		rewind(fp);
	    cout<<"请输入要查询的帐户号码:"<<endl;
	    cin>>card;
		for(;!feof(fp);)
		{ 
	    	fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
			//从文件中得到用户信息,如果和卡号相同,就打印出来
	    	if(strcmp(card,account1.num)==0)
			{
		    	cout<<"ID号码:"<<account1.num<<endl;
		    	cout<<"用户名:"<<account1.name<<endl;
				cout<<"余额:   "<<account1.money<<endl;
				cout<<"<0.退出>?<enter,继续>"<<endl;
				flushall();
			    c=getchar();
				 if (c=='0') {fclose(fp);functionshow1();}
			    	else {rewind(fp);break;}
			}
		
		}	
	      if(feof(fp)) 
		  {cout<<"没有这个帐户!!!";
		    cout<<"<0.退出>?<enter,继续>"<<endl;
			cout<<endl;
			flushall();
			c1=getchar();
		    if (c1=='0') {fclose(fp);functionshow1();}
			}
	}
}


int lookallaccount() //查询所以的帐户信息
{
	char c;
	int i=0;//用户个数
	float money1=0.0;//为information 着准备
	FILE *fp;
	if((fp=fopen("account","rb"))==NULL)
	{cout<<"can't open this file "<<endl;cin>>c;functionshow1();}
	for(;!feof(fp);i++)
	{
		fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
	        cout<<"ID号码:"<<account1.num<<"  ";
			cout<<"用户名:"<<account1.name<<"  ";
			cout<<"余额:   "<<account1.money<<"  ";
			money1+=account1.money;
			cout<<endl;
	}
    cout<<"一共有"<<i<<"个用户"<<endl;
	cout<<"总金额、为:"<<money1<<endl;
	cout<<"<0.eixt>"<<endl;
	cin>>c;
    functionshow1();
	return 1;
}

void createaccount()    //添加一个用户,把信息加到account文件的末尾,,同时创建日志文件
{
	int i;
	int j;
	float money1,money2;
	char c;
	FILE *fp;//account 文件
	FILE *fp0;//account.bak文件
	char pwd1[7],pwd2[7];	
	money1=0.0;//为information 着准备

	if((fp0=fopen("account.bak","ab+"))==NULL)
	{cout<<"can't opent this file account.bak!"<<endl;getchar();functionshow1();}
	if((fp=fopen("account","ab+"))==NULL)
	{cout<<"can't open this file "<<endl;getchar();functionshow1();}
	else 
	{
		for(;!feof(fp);)	
		{fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);}		
   	}

	i=atoi(account1.num);
	i++;
	itoa(i,account1.num,10);
	cout<<"输入用户名:"<<endl;
	cin>>account1.name;//获得最后的一个id号码,为添加id着准备
	 for(;;)
	{
	    cout<<"输入密码:";
	    cin>>pwd1;
		cout<<"确认密码:";
		cin>>pwd2;
		cout<<"现在要存钱?<0.否>,<enter,是>"<<endl;
		c=getchar();
		if(c!='0')
		while(1)
		{
			cout<<"请输入你要操作的金额:"<<endl;
			cin>>money1;
			cout<<"你要存入"<<money1<<"元.请确认:"<<endl;
			cin>>money2;
			if(money1!=money2)  {cout<<"俩次输入不同重新来."<<endl;getchar();}
			else {account1.money=money1;break;}
		}
		
	if(strcmp(pwd1,pwd2)==0 && strlen(pwd1)==6 && strlen(pwd2)==6)//验证密码	
	{ 	//如果密码正确,打印到文件之中
		strcpy(account1.password,pwd2);
		fprintf(fp,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);
		fprintf(fp0,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);
	
	   if(create_note()) //创建note
		{fclose(fp);fclose(fp0);information1(money1);}		

		flushall();
		functionshow1();
	}
	else		
	{ if (strlen(pwd1)!=6) cout<<"密码要六位"<<endl;
	  else	cout<<"密码确认错误重新来!"<<endl;
	    cout<<"<0.退出>"<<endl;
		flushall();c=getchar();
		if(c=='0') functionshow1();
	}
	}
}

int lookaccount_note(char num[])
{
	char information[80];
	float money1;
	FILE * fp;
	time_t tm;

	if((fp=fopen(num,"rb"))==NULL)
	{cout<<"can't open this file "<<endl;getchar();return 0;}

	for(;!feof(fp);)
	{
		fscanf(fp,"%s %f %d\n",information,&money1,&tm);
		cout<<information<<" "<<money1<<" "<<ctime(&tm)<<endl;//tiem 是用long 来保存的所以读出来了用ctime(&tm);
	}
	fclose(fp);
	cout<<"any keys to continue !"<<endl;
	getchar();
	return 1;
}

int lookallaccount_note()
{ 
	account account2;//临时的变量,保证全局变量不受影响
	char num[20];

⌨️ 快捷键说明

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