ATM管理系统

一、作业信息

这个作业属于哪个课程https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/
这个作业要求在哪里 https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/homework/11478
这个作业的目标 编写一个ATM管理系统
学号 3180701237

二、题目要求

编写一个ATM管理系统,语言不限,要求应包括以下主要功能:
(1)开户,销户
(2)查询账户余额
(3)存款
(4)取款
(5)转账(一个账户转到另一个账户)等...

三、代码提

开户

void oaa(struct per *head)
{
	head=NULL;
	FILE *fp;   //定义文件指针
	struct per *p1=NULL,*p2=NULL;   //p1,p2为定义链表指针
	p1=(struct per*)malloc(sizeof(struct per));  
	      printf("请输入您的姓名:\n");  
		  scanf("%s",p1->name);
		  printf("请输入您的卡号:\n");
		  scanf("%s",p1->ID);
		  printf("请设置您银行卡密码:\n");
		  scanf("%s",p1->code);
		  p1->money=0;
		  p1->next=NULL;
		  printf("您的个人信息为");
		     printf("姓名:%s \n卡号:%s \n余额:%4d\n",p1->name,p1->ID,p1->money);
          if(NULL==head)           
		  {
			  head=(struct per *)malloc(sizeof(struct per));
			  head->next=p1;    //头插法
		  }
		  else    //为新增客户开辟内存单元
		  {
			  for(p2=head;p2->next!=NULL;p2=p2->next); //尾插法
			  p2->next=p1;
		  }
		  if((fp=fopen("save.txt","ab+"))==NULL)
		  {
			  printf("cannot poen file\n");
			  return;
		  }
		  if(fwrite(p1,sizeof(struct per),1,fp)!=1)  //将链表信息写入文件中
			  printf("file write error\n");
		      fclose(fp);
			  printf("\n");
			  printf("恭喜您开户成功,请登录\n");
			  system("pause");
			  system("cls");
			  login(head);
}

登录

void login(struct per *head)
{
	char d[20];
	char code[20];
	int i,j;
	FILE *fp;     
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)   //打开一个二进制文件,为读方式
	{
		printf("不能打开文件\n");   
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))       
 
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;   //如果没读到数据,跳出循环
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p; 
		p=p->next; 
		
	}
	q->next=NULL;  //最后一个结点的后继指针为空
	fclose(fp);
	printf("  **********************\n");
	printf("  ***欢迎来到建设银行***\n");
	printf("  **********************\n");
	for(j=1;j<4;j++)      //限制卡号输入的次数的循环
	{
		printf("请输入您的卡号\n");
		scanf("%s",d);
		for(q=head;q!=NULL;q=q->next)   
		{
			if(strcmp(q->ID,d)!=0)  
			{
			continue;  
			}
					else
		{
			for(i=1;i<4;i++)   
			{
				printf("\n\n请输入您的密码\n");
				scanf("%s",code);
				if(strcmp(q->code,code)!=0)      //核对密码
				{
					printf("密码不正确。请重新输入密码\n");
					system("pause");
					system("cls");
					continue;    //若密码不对,跳出循环
				}
				else
				{
					system("cls");
					menu(head);  
				}
			}
			printf("\n\n\n您输入密码三次错误\n");
			system("pause");
			system("cls");
			exit(0);
		}
	}
		
	
	printf("\n\n\n您输入的卡号有误,请重试\n");
	system("pause");
	system("cls");
}
printf("您的卡号三次输入错误,谢谢使用\n");
exit(0);
}
 

菜单

void menu(struct per *head)
{
	head=NULL;
	int i;      //i为客户选择输入的变量
	while(1)
	{
		printf("请选择您需要办理的业务\n");     
		printf("*********************************\n");
		printf("**  1 取款   *****   2 查询    **\n");
		printf("*********************************\n");
		printf("**  3 转账   *****   4 修改密码**\n");
		printf("*********************************\n");
		printf("**  5 存款   *****   6 退出    **\n");
		printf("*********************************\n");
		scanf("%d",&i);
		if(i<6||i>0)
		{
			switch(i)
			{
			case 1:withdrawal(head);       
			       system("pause");
				   system("cls");
				   break;
			case 2:system("cls");
				   query(head);  
				   break;
            case 3:system("cls");
				   taccount(head);  
				   break;
            case 4:system("cls");
				   cpassword(head);  
				   break;
            case 5:system("cls");
				   deposit(head);  
				   break;
            case 6:system("cls");
				   tuichu();  
				   break;
			}
		}
		else
		{
			printf("您的输入有误\n");
			system("pause");
			system("cls");
		}
	}
}

存款

void deposit(struct per *head)
{
	int i;
	head=NULL;   
	FILE *fp;  
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  //打开一个二进制文件,为读方式
	{
		printf("不能打开文件\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))   
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;   
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;   
		p=p->next;   
	}
	q->next=NULL;   
	fclose(fp);
	system("cls");
	printf("您卡上余额%d元\n",q->money);   
	printf("************************************\n");
    printf("**  1: 100元    *****    2:200元  **\n");
	printf("************************************\n");
    printf("**  3: 300元    *****    4:400元  **\n");
	printf("************************************\n");
    printf("**  5: 500元    *****    6:600元  **\n");
	printf("************************************\n");
    printf("请选择您要存入的金额\n");
	scanf("%d",&i);
	if(i>6||i<=0)
	{
		printf("对不起,您的输入有误\n\n");
		return;
	}
	else
	{
		i=100*i;
		q->money+=i;
		if((fp=fopen("save.txt","wb+"))==NULL)  
		{
			printf("cannot open file\n");
		}
		if(fwrite(q,sizeof(struct per),1,fp)!=1)  //将修改的密码重新写入文件
			printf("file write error\n");
	    	printf("您已经成功存取%d元\n",i);
			q->next=NULL;
			fclose(fp);
			system("pause");
			system("cls");
	}
}

取款

void withdrawal(struct per *head)
{
	head=NULL;   
	int i;
	FILE *fp;         
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL) //打开一个二进制文件,为读方式
	{
		printf("不能打开文件\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));  
	head=p;
	while(!feof(fp))   
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;  
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;  
		p=p->next; 
	}
	q->next=NULL; 
	fclose(fp);
	system("cls");
	printf("************************************\n");
    printf("**  1: 100元    *****    2:200元  **\n");
	printf("************************************\n");
    printf("**  3: 300元    *****    4:400元  **\n");
	printf("************************************\n");
    printf("**  5: 500元    *****    6:600元  **\n");
	printf("************************************\n");
    printf("请按要求选择您要取款的金额\n");
	scanf("%d",&i);
	if(i>6||i<=0)    //限制输入范围
	{
		printf("对不起,您的输入有误\n\n");
		return;
	}
	else
	{
		i=100*i;  //对应选项乘以一百为取款金额
		if(i>q->money)
		{
			printf("对不起,您的金额不足\n");
			system("pause");
			system("cls");
			menu(head);  
		}
		else
		{
			q->money-=i;  //对金额进行处理
			if((fp=fopen("save.txt","wb+"))==NULL)  
			{
				printf("cannot open file\n");
				return;
			}
			if(fwrite(q,sizeof(struct per),1,fp)!=1) //将修改的信息重新写入文件
				printf("file write error\n");
			printf("您已经成功取走%d元\n");
			q->next=NULL;
			fclose(fp);   
		}
		
	}
}

转账

void taccount(struct per *head)
{
	head=NULL;
	FILE *fp;  
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  
	{
		printf("不能打开文件\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));  
	head=p;
	while(!feof(fp))    
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;   
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;   
		p=p->next;   
	}
	q->next=NULL;  
	fclose(fp);
	int i,j,k;
	printf("请输入帐号号码\n");
	scanf("%d",&i);
	printf("请再次输入帐号号码\n");   //核对卡号
	scanf("%d",&j);
	if(i!=j)
	{
		printf("两次账号不同,请重新输入\n");
		taccount(head);
	}
	else
	{
		system("cls");
	printf("************************************\n");
    printf("**  1: 100元    *****    2:200元  **\n");
	printf("************************************\n");
    printf("**  3: 300元    *****    4:400元  **\n");
	printf("************************************\n");
    printf("**  5: 500元    *****    6:600元  **\n");
	printf("************************************\n");
    printf("请输入转账金额\n");
	scanf("%d",&k);
	if(k>6||k<=0)
	{
		printf("对不起,您的输入有误\n\n");
		return;
	}
	else
	{
		k=k*100;
		if(k>q->money)    //对余额进行判断
		{
			printf("对不起,您的余额不足\n");
			system("pause");
			system("cls");
			menu(head);
		}
		else
		{
			printf("您已成功转账%d元\n",k);
			q->money-=k;
			if((fp=fopen("save.txt","wb+"))==NULL)
			{
				printf("cannot open file\n");
				return;
			}
			if(fwrite(q,sizeof(per),1,fp)!=1)  //将数据重新写入文件
				printf("file write error\n");
			q->next=NULL;
			fclose(fp);
			system("pause");
			system("cls");
		}
	}
	}
}

查询

void query(struct per *head)
{
	head=NULL;  
	FILE *fp;  
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  
	{
		printf("不能打开文件\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))   
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;    
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;   
		p=p->next;   
	}
	q->next=NULL;  
	fclose(fp);
	printf("您卡上余额%d元\n\n",q->money);
	system("pause");
	system("cls");
}
 

修改密码

void cpassword(struct per *head)
{
	head=NULL;         
	char code[20];
	FILE *fp; 
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  //打开一个二进制文件,为读方式
	{
		printf("不能打开文件\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))    
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;    
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;  
		p=p->next;  
	}
	q->next=NULL;  
	fclose(fp);
	printf("请输入您的原密码\n");
	scanf("%s",code);
	if(strcmp(q->code,code)==0)   //核对密码
	{
		{
			printf("密码正确\n");
			printf("请输入您的新密码:\n");
			scanf("%s",q->code);
			if((fp=fopen("save.txt","wb+"))==NULL)  
			{
				printf("cannot open file\n");
			}
			if(fwrite(q,sizeof(struct per),1,fp)!=1)    
				printf("file write error\n");
			fclose(fp);
			printf("修改密码成功\n\n\n\n\n");
		}
	}
	else
	{
		printf("您输入的密码与原密码不同\n");
		return;
		system("pause");
	}
	q->next=NULL;
}

销户

void close(struct person **Phead)   
{
	char k[20];   
	struct person *p=*Phead,*t;
	if(NULL==(*Phead))    
	{
		printf("没有客户信息可删除!\n");
		return;
	}
	printf("请输入要删除的客户卡号:\n");
	scanf("%s",k);
	if(p->client.ID==k) 
		*Phead=(*Phead)->next,free(p);
	else
	{
		while(NULL==p->next&&p->next->client.ID!=k)   
			p=p->next;  
		if(p->next==NULL)
			printf("对不起,没有该客户!\n");
		else
		{
			t=p->next;  
			p->next=p->next->next;
		}
	}
}

主函数

 
int main()
{
	char x;
	char choose; //choose为定义输入选择的变量
	int flag=1;
	struct person *Phead=NULL; 
	struct per *head=NULL;   
	printf("**欢迎使用ATM自动取款机系统**\n");
    printf("——————————————\n");
	printf("|   1  开户                 |\n");
    printf("——————————————\n");
	printf("|   2  登陆                 |\n");
    printf("——————————————\n");
	printf("|   3  前台客户信息查询中心 |\n");
    printf("——————————————\n");
	printf("|   请选择您的需求         |\n");
    printf("———————————————\n");
	scanf("%s",&x);
	system("cls");
 
	switch(x)
	{
	case '1':system("cls");
	         oaa(head);   //调用开户函数
			 break;
 
	case '2':system("cls");
	         login(head);   //调用登陆函数
			 break;
 
	case '3':system("cls");
	         menu();   //调用后台菜单函数
			 break;
	}
	while(flag)
	{
		system("cls");
		menu();       //调用后台菜单函数
		choose=getchar();
		switch(choose)
		{
		case '1':setup(&Phead);
			     output(Phead); //调用后台输出函数
				 system("pause");
				 system("cls");
				 break;
    	case '2':query1(Phead); //调用后台卡号查询函数
				 system("pause");
				 system("cls");
				 break;
    	case '3':query2(Phead); //调用后台姓名查询函数
				 system("pause");
				 system("cls");
				 break;
    	case '4':
			     query3(Phead); //调用后台余额查询函数
				 system("pause");
				 system("cls");
				 break;
    	case '5':close(&Phead); //调用后台删除用户函数
				 system("pause");
				 system("cls");
				 break;
	    case '6':
			     add(&Phead); //调用后台增加用户函数
				 system("pause");
				 system("cls");
				 break;
	    case '7':output(Phead); //调用后台输出函数函数
				 system("pause");
				 system("cls");
				 break;
	    case '8':output(Phead); 
				 system("pause");
				 system("cls");
				 break;
    	case '0':flag=0;
			     printf("The end.\n");
				 break;
		}
	}
}
四、运行截图

 

 

 

 

 

 

 

 

 

五、个人小结
1.psp
psp2.1任务内容计划完成需要的时间(min)实际完成需要的时间(min)
Planning 计划 30 60
Estimate 估计这个任务需要多少时间,并规划大致工作步骤 6 6
Development 开发 120 120
Analysis 需求分析(包括学习新技术) 10 10
Design Spec 生成设计文档 20 20
Design Review 设计复审 5 10
Coding Standard 代码规范 5 8
Design 具体设计 15 22
Coding 具体编码 40 35
Code Review 代码复审 5 4
Test 测试(自我测试,修改代码,提交修改) 20 15
Reporting 报告 10 10
Test Report 测试报告 2 3
Size Measurement 计算工作量 3 3
Postmortem & Process improvement Plan 事后总结,并提出过程改进计划 4 4
2.作业心得
通过这次学习,我对c语言编程有了更深刻的理解。

 













posted @ 2020-11-18 20:45  chengkangs  阅读(295)  评论(0编辑  收藏  举报