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

📄 function.h

📁 atm老师的作业
💻 H
📖 第 1 页 / 共 2 页
字号:
	int time=0;
	FILE * fp1;char c;
	if((fp1=fopen("account","rb"))==NULL)
	{cout<<"can't open this file account:"<<endl;getchar();return 0;}
    for(;!feof(fp1);)
	{ //cout<<"o\k"<<endl;
		fscanf(fp1,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		strcpy(num,account2.num);
		lookaccount_note(num);
		time++;
		if(time%10==0)//每页最多有10个用户信息
		{cout<<"any keys to continue !"<<endl;c=getchar();}
	}
	fclose(fp1);
	return 1;
}


///###############
//文件操作函数####
//################
int file1(int state) //用来实现对身份的验证,对就返回0;
{   char card[20];
	char c;FILE *fp;
	if ((fp=fopen("account","rb"))==NULL)
	{cout<<"不能够打开文件!"<<endl;c=getchar();exit(0);}
	for(;;){
		rewind(fp);
	cout<<"请输入你的卡号:";
	cin>>card;
	//cout<<"输入你的密码:";
	//cin>>pwd;
	while(!feof(fp))
	{
		fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
		if(state==0)
		{if(strcmp(card,account1.num)==0 && checkpassword1(0))
		{fclose(fp);return 0;}				}
		else
		{if(strcmp(card,account1.num)==0)
		{fclose(fp);return 0;}
		}
	}
	cout<<"atm不接受你的卡号或密码:"<<endl;
	cout<<"<0.返回><enter.重来>"<<endl;
	flushall();c=getchar();
	if(c=='0') return 1;
	}
	
}

int file2 ()//验证管理员
{
	char card[20];
	char c;FILE *fp;
	if((fp=fopen("system","rb"))==NULL)
	{cout<<"不能够打开文件!"<<endl;c=getchar();exit(0);}
	for(;;)
	{  rewind(fp);
		cout<<"请输入你的卡号:";
	    cin>>card;
		while(!feof(fp))
		{
			fscanf(fp,"%s %s ",system1.num,system1.password);
			if(strcmp(card,system1.num)==0)
			{fclose(fp);return 1;}
		}
	cout<<"atm不接受你的卡号:"<<endl;
	cout<<"<0.返回><enter.重来>"<<endl;
	c=getchar();
	if(c=='0') welcome();
	flushall();//getchar();//
	}
}

int file3()//保存数据,并将其备份;
{
	FILE* fp1;//bak文件指针
	FILE* fp2;//account文件指针
	char c;	account account2;

	if((fp1=fopen("account.bak","rb+"))==NULL)
	{cout<<"can't open this file account.bak"<<endl;getchar();return(0);}

	if((fp2=fopen("account","wb+"))==NULL)
	{cout<<"can't open this file account"<<endl;getchar();return(0);}

	for(;!feof(fp1);)
	{ 
		fscanf(fp1,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		if(strcmp(account1.num,account2.num)==0)
		{fprintf(fp2,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);}
		else
		fprintf(fp2,"%s %f %s %s ",account2.num,account2.money,account2.name,account2.password);
	}
	fclose(fp1);
		fclose(fp2);

  	if((fp1=fopen("account.bak","wb"))==NULL)
	{cout<<"can't open this file account.bak"<<endl;getchar();return(0);}
	if((fp2=fopen("account","rb"))==NULL)
	{cout<<"can't open this file account"<<endl;getchar();return(0);}

	for(;!feof(fp2);)
	{
		fscanf(fp2,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		fprintf(fp1,"%s %f %s %s ",account2.num,account2.money,account2.name,account2.password);
	}
		fclose(fp1);
		fclose(fp2);
		return 1;
}

int create_note()
{time_t  tm;char information[80];
	FILE* fp;char c;
	char name[20];

	strcpy(name,account1.num);
	strcpy(information,account1.num);
	strcat(information,"开户 ");
	tm=time(NULL);

	if((fp=fopen(name,"wb+"))==NULL)
	{cout<<"can't open this file:"<<endl;getchar();return 0;}
	fprintf(fp,"%s %f %d\n",information,account1.money,tm);
	fclose(fp);
	strcat(name,".bak");
	if((fp=fopen(name,"wb+"))==NULL)
	{cout<<"can't open this file :"<<endl;getchar();return 0;}
	fprintf(fp,"%s %f %d\n",information,account1.money,tm);
	fclose(fp);
	return 1;
} 

int add_note(char information1[],char method1[],float money1)
{
	FILE* fp1,* fp2;
	int i=0;
	float money2=money1;
	char c[80];
	time_t tm1,tm2;
	char name2[30];
	char name1[30];
    cout<<"ok1"<<endl;

	strcpy(name2,account1.num);
	strcat(name2,".bak");
	strcpy(name1,account1.num);
	strcat(information1,method1);
	tm2=time(NULL);

 cout<<"ok2"<<endl;
	if((fp1=fopen(name1,"wb+"))==NULL)
	{cout<<"can't open this file"<<endl;getchar();return 0;}

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

	for(;!feof(fp2);)
	{ cout<<"ok3"<<endl;
		fscanf(fp2,"%s %f %d\n",c,&money1,&tm1);
		if(i=0){i++;fprintf(fp1,"%s %f %d\n",c,money1,tm1); cout<<"ok4"<<endl;}
	   else	if(tm2-tm1>=129600) continue ;
		else 
		{fprintf(fp1,"%s %f %d\n",c,money1,tm1); cout<<"ok4"<<endl;}
	}
	fprintf(fp1,"%s %f %d\n",information1,money2,tm2); cout<<"ok5"<<endl;
	fclose (fp1);
	fclose(fp2);

	fp1=fopen(name1,"rb");
	fp2=fopen(name2,"wb+");
	for(;!feof(fp1);)
	{
		fscanf(fp1,"%s %f %d\n",c,&money1,&tm1); cout<<"ok61"<<endl;
		fprintf(fp2,"%s %f %d\n",c,money1,tm1); cout<<"ok7"<<endl;
	}
	fclose(fp1);
	fclose(fp2);
	return 1;
}

int file1(int state)   //用来实现对身份的验证,state=0为account验证,否则为system验证,
{  
	char card[20];
	char c;FILE *fp;
	if ((fp=fopen("account","rb"))==NULL)
	{cout<<"不能够打开文件!"<<endl;c=getchar();exit(0);}
	for(;;)
	{
		rewind(fp);
		cout<<"请输入你的卡号:";
		cin>>card;
	
		while(!feof(fp))
		{
			fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
			if(state==0)
			{if(strcmp(card,account1.num)==0 && checkpassword1(0))
			{fclose(fp);return 0;}				}
			else
			{if(strcmp(card,account1.num)==0)
			{fclose(fp);return 0;}
		}
	}
	cout<<"atm不接受你的卡号或密码:"<<endl;
	cout<<"<0.返回><enter.重来>"<<endl;
	flushall();c=getchar();
	if(c=='0') return 1;
	}
	
}

int file2 ()//验证管理员
{
	char card[20];
	char c;FILE *fp;
	if((fp=fopen("system","rb"))==NULL)
	{cout<<"不能够打开文件!"<<endl;c=getchar();exit(0);}
	for(;;)
	{  rewind(fp);
		cout<<"请输入你的卡号:";
	    cin>>card;
		while(!feof(fp))
		{
			fscanf(fp,"%s %s ",system1.num,system1.password);
			if(strcmp(card,system1.num)==0)
			{fclose(fp);return 1;}
		}
	cout<<"atm不接受你的卡号:"<<endl;
	cout<<"<0.返回><enter.重来>"<<endl;
	c=getchar();
	if(c=='0') welcome();
	flushall();//getchar();//
	}
}

int file3()        //每操作完成就保存数据,并将其备份;保存成功返回1
{
	FILE* fp1;  //bak文件指针
	FILE* fp2;       //account文件指针
	char c;	
	account account2;//临时的变量

	if((fp1=fopen("account.bak","rb+"))==NULL)
	{cout<<"can't open this file account.bak"<<endl;getchar();return(0);}

	if((fp2=fopen("account","wb+"))==NULL)
	{cout<<"can't open this file account"<<endl;getchar();return(0);}

	for(;!feof(fp1);)
	{ 
		fscanf(fp1,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		if(strcmp(account1.num,account2.num)==0)
		{fprintf(fp2,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);}
		else
		fprintf(fp2,"%s %f %s %s ",account2.num,account2.money,account2.name,account2.password);
	}
	fclose(fp1);
		fclose(fp2);

  	if((fp1=fopen("account.bak","wb"))==NULL)
	{cout<<"can't open this file account.bak"<<endl;getchar();return(0);}
	if((fp2=fopen("account","rb"))==NULL)
	{cout<<"can't open this file account"<<endl;getchar();return(0);}

	for(;!feof(fp2);)
	{
		fscanf(fp2,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		fprintf(fp1,"%s %f %s %s ",account2.num,account2.money,account2.name,account2.password);
	}
		fclose(fp1);
		fclose(fp2);
		return 1;
}

int create_note()//创建note并写入开户信息
{
	char c;
	time_t  tm;
	char information[80];
	FILE* fp;
	char name[20];

	strcpy(name,account1.num);
	strcpy(information,account1.num);
	strcat(information,"开户 ");
	tm=time(NULL);

	if((fp=fopen(name,"wb+"))==NULL)
	{cout<<"can't open this file:"<<endl;getchar();return 0;}
	fprintf(fp,"%s %f %d\n",information,account1.money,tm);
	fclose(fp);

	strcat(name,".bak");  //.bak
	if((fp=fopen(name,"wb+"))==NULL)
	{cout<<"can't open this file :"<<endl;getchar();return 0;}
	fprintf(fp,"%s %f %d\n",information,account1.money,tm);
	fclose(fp);
	return 1;
} 

int add_note(char information1[],char method1[],float money1)
{ //添加日志消息,包括时间操作的金额,操作的id等等
	//日志操过三个月就自动删除掉
	//开户的日志永远不变
	FILE* fp1,* fp2;//fp1,对应的日志文件,fp2,是对应的日志文件的bak文件
	int i=0;
	float money2=money1;
	char c[80];
	time_t tm1,tm2;
	char name2[30];
	char name1[30];
    cout<<"ok1"<<endl;

	strcpy(name2,account1.num);
	strcat(name2,".bak");
	strcpy(name1,account1.num);
	strcat(information1,method1);
	tm2=time(NULL);

 cout<<"ok2"<<endl;
	if((fp1=fopen(name1,"wb+"))==NULL)
	{cout<<"can't open this file"<<endl;getchar();return 0;}

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

	for(;!feof(fp2);)
	{ cout<<"ok3"<<endl;
		fscanf(fp2,"%s %f %d\n",c,&money1,&tm1);
		if(i=0){i++;fprintf(fp1,"%s %f %d\n",c,money1,tm1); cout<<"ok4"<<endl;}
	   else	if(tm2-tm1>=129600) continue ;//判断日志的时间,
		else 
		{fprintf(fp1,"%s %f %d\n",c,money1,tm1); 
	}
	fprintf(fp1,"%s %f %d\n",information1,money2,tm2); 
	fclose (fp1);
	fclose(fp2);

	fp1=fopen(name1,"rb");
	fp2=fopen(name2,"wb+");
	for(;!feof(fp1);)
	{
		fscanf(fp1,"%s %f %d\n",c,&money1,&tm1); 
		fprintf(fp2,"%s %f %d\n",c,money1,tm1); 
	}
	fclose(fp1);
	fclose(fp2);
	return 1;
}





	int file1(int state)   //用来实现对身份的验证,state=0为account验证,否则为system验证,
{  
	char card[20];
	char c;FILE *fp;
	if ((fp=fopen("account","rb"))==NULL)
	{cout<<"不能够打开文件!"<<endl;c=getchar();exit(0);}
	for(;;)
	{
		rewind(fp);
		cout<<"请输入你的卡号:";
		cin>>card;
	
		while(!feof(fp))
		{
			fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
			if(state==0)
			{if(strcmp(card,account1.num)==0 && checkpassword1(0))
			{fclose(fp);return 0;}				}
			else
			{if(strcmp(card,account1.num)==0)
			{fclose(fp);return 0;}
		}
	}
	cout<<"atm不接受你的卡号或密码:"<<endl;
	cout<<"<0.返回><enter.重来>"<<endl;
	flushall();c=getchar();
	if(c=='0') return 1;
	}
	
}

int file2 ()//验证管理员
{
	char card[20];
	char c;FILE *fp;
	if((fp=fopen("system","rb"))==NULL)
	{cout<<"不能够打开文件!"<<endl;c=getchar();exit(0);}
	for(;;)
	{  rewind(fp);
		cout<<"请输入你的卡号:";
	    cin>>card;
		while(!feof(fp))
		{
			fscanf(fp,"%s %s ",system1.num,system1.password);
			if(strcmp(card,system1.num)==0)
			{fclose(fp);return 1;}
		}
	cout<<"atm不接受你的卡号:"<<endl;
	cout<<"<0.返回><enter.重来>"<<endl;
	c=getchar();
	if(c=='0') welcome();
	flushall();//getchar();//
	}
}

int file3()        //每操作完成就保存数据,并将其备份;保存成功返回1
{
	FILE* fp1;  //bak文件指针
	FILE* fp2;       //account文件指针
	char c;	
	account account2;//临时的变量

	if((fp1=fopen("account.bak","rb+"))==NULL)
	{cout<<"can't open this file account.bak"<<endl;getchar();return(0);}

	if((fp2=fopen("account","wb+"))==NULL)
	{cout<<"can't open this file account"<<endl;getchar();return(0);}

	for(;!feof(fp1);)
	{ 
		fscanf(fp1,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		if(strcmp(account1.num,account2.num)==0)
		{fprintf(fp2,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);}
		else
		fprintf(fp2,"%s %f %s %s ",account2.num,account2.money,account2.name,account2.password);
	}
	fclose(fp1);
		fclose(fp2);

  	if((fp1=fopen("account.bak","wb"))==NULL)
	{cout<<"can't open this file account.bak"<<endl;getchar();return(0);}
	if((fp2=fopen("account","rb"))==NULL)
	{cout<<"can't open this file account"<<endl;getchar();return(0);}

	for(;!feof(fp2);)
	{
		fscanf(fp2,"%s %f %s %s ",account2.num,&account2.money,account2.name,account2.password);
		fprintf(fp1,"%s %f %s %s ",account2.num,account2.money,account2.name,account2.password);
	}
		fclose(fp1);
		fclose(fp2);
		return 1;
}

int create_note()//创建note并写入开户信息
{
	char c;
	time_t  tm;
	char information[80];
	FILE* fp;
	char name[20];

	strcpy(name,account1.num);
	strcpy(information,account1.num);
	strcat(information,"开户 ");
	tm=time(NULL);

	if((fp=fopen(name,"wb+"))==NULL)
	{cout<<"can't open this file:"<<endl;getchar();return 0;}
	fprintf(fp,"%s %f %d\n",information,account1.money,tm);
	fclose(fp);

	strcat(name,".bak");  //.bak
	if((fp=fopen(name,"wb+"))==NULL)
	{cout<<"can't open this file :"<<endl;getchar();return 0;}
	fprintf(fp,"%s %f %d\n",information,account1.money,tm);
	fclose(fp);
	return 1;
} 

int add_note(char information1[],char method1[],float money1)
{ //添加日志消息,包括时间操作的金额,操作的id等等
	//日志操过三个月就自动删除掉
	//开户的日志永远不变
	FILE* fp1,* fp2;//fp1,对应的日志文件,fp2,是对应的日志文件的bak文件
	int i=0;
	float money2=money1;
	char c[80];
	time_t tm1,tm2;
	char name2[30];
	char name1[30];
    cout<<"ok1"<<endl;

	strcpy(name2,account1.num);
	strcat(name2,".bak");
	strcpy(name1,account1.num);
	strcat(information1,method1);
	tm2=time(NULL);

 cout<<"ok2"<<endl;
	if((fp1=fopen(name1,"wb+"))==NULL)
	{cout<<"can't open this file"<<endl;getchar();return 0;}

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

	for(;!feof(fp2);)
	{ cout<<"ok3"<<endl;
		fscanf(fp2,"%s %f %d\n",c,&money1,&tm1);
		if(i=0){i++;fprintf(fp1,"%s %f %d\n",c,money1,tm1); cout<<"ok4"<<endl;}
	   else	if(tm2-tm1>=129600) continue ;//判断日志的时间,
		else 
		{fprintf(fp1,"%s %f %d\n",c,money1,tm1); 
	}
	fprintf(fp1,"%s %f %d\n",information1,money2,tm2); 
	fclose (fp1);
	fclose(fp2);

	fp1=fopen(name1,"rb");
	fp2=fopen(name2,"wb+");
	for(;!feof(fp1);)
	{
		fscanf(fp1,"%s %f %d\n",c,&money1,&tm1); 
		fprintf(fp2,"%s %f %d\n",c,money1,tm1); 
	}
	fclose(fp1);
	fclose(fp2);
	return 1;
}



⌨️ 快捷键说明

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