ATM管理系统 作业目标 代码 运行截图 作业小结


博客班级 AHPU软件工程
作业要求 编写一个ATM管理系统
作业目标
学号 3180701126

编写一个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("请输入您的姓名:
");  
		  scanf("%s",p1->name);
		  printf("请输入您的卡号:
");
		  scanf("%s",p1->ID);
		  printf("请设置您银行卡密码:
");
		  scanf("%s",p1->code);
		  p1->money=0;
		  p1->next=NULL;
		  printf("您的个人信息为");
		     printf("姓名:%s 
卡号:%s 
余额:%4d
",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
");
			  return;
		  }
		  if(fwrite(p1,sizeof(struct per),1,fp)!=1)  //将链表信息写入文件中
			  printf("file write error
");
		      fclose(fp);
			  printf("
");
			  printf("恭喜您开户成功,请登录
");
			  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("不能打开文件
");   
	}
	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("  **********************
");
	printf("  ***欢迎来到建设银行***
");
	printf("  **********************
");
	for(j=1;j<4;j++)      //限制卡号输入的次数的循环
	{
		printf("请输入您的卡号
");
		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("

请输入您的密码
");
				scanf("%s",code);
				if(strcmp(q->code,code)!=0)      //核对密码
				{
					printf("密码不正确。请重新输入密码
");
					system("pause");
					system("cls");
					continue;    //若密码不对,跳出循环
				}
				else
				{
					system("cls");
					menu(head);  
				}
			}
			printf("


您输入密码三次错误
");
			system("pause");
			system("cls");
			exit(0);
		}
	}
		
	
	printf("


您输入的卡号有误,请重试
");
	system("pause");
	system("cls");
}
printf("您的卡号三次输入错误,谢谢使用
");
exit(0);
}
 

菜单

void menu(struct per *head)
{
	head=NULL;
	int i;      //i为客户选择输入的变量
	while(1)
	{
		printf("请选择您需要办理的业务
");     
		printf("*********************************
");
		printf("**  1 取款   *****   2 查询    **
");
		printf("*********************************
");
		printf("**  3 转账   *****   4 修改密码**
");
		printf("*********************************
");
		printf("**  5 存款   *****   6 退出    **
");
		printf("*********************************
");
		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("您的输入有误
");
			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("不能打开文件
");  
	}
	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元
",q->money);   
	printf("************************************
");
    printf("**  1: 100元    *****    2:200元  **
");
	printf("************************************
");
    printf("**  3: 300元    *****    4:400元  **
");
	printf("************************************
");
    printf("**  5: 500元    *****    6:600元  **
");
	printf("************************************
");
    printf("请选择您要存入的金额
");
	scanf("%d",&i);
	if(i>6||i<=0)
	{
		printf("对不起,您的输入有误

");
		return;
	}
	else
	{
		i=100*i;
		q->money+=i;
		if((fp=fopen("save.txt","wb+"))==NULL)  
		{
			printf("cannot open file
");
		}
		if(fwrite(q,sizeof(struct per),1,fp)!=1)  //将修改的密码重新写入文件
			printf("file write error
");
	    	printf("您已经成功存取%d元
",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("不能打开文件
");  
	}
	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("************************************
");
    printf("**  1: 100元    *****    2:200元  **
");
	printf("************************************
");
    printf("**  3: 300元    *****    4:400元  **
");
	printf("************************************
");
    printf("**  5: 500元    *****    6:600元  **
");
	printf("************************************
");
    printf("请按要求选择您要取款的金额
");
	scanf("%d",&i);
	if(i>6||i<=0)    //限制输入范围
	{
		printf("对不起,您的输入有误

");
		return;
	}
	else
	{
		i=100*i;  //对应选项乘以一百为取款金额
		if(i>q->money)
		{
			printf("对不起,您的金额不足
");
			system("pause");
			system("cls");
			menu(head);  
		}
		else
		{
			q->money-=i;  //对金额进行处理
			if((fp=fopen("save.txt","wb+"))==NULL)  
			{
				printf("cannot open file
");
				return;
			}
			if(fwrite(q,sizeof(struct per),1,fp)!=1) //将修改的信息重新写入文件
				printf("file write error
");
			printf("您已经成功取走%d元
");
			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("不能打开文件
");  
	}
	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("请输入帐号号码
");
	scanf("%d",&i);
	printf("请再次输入帐号号码
");   //核对卡号
	scanf("%d",&j);
	if(i!=j)
	{
		printf("两次账号不同,请重新输入
");
		taccount(head);
	}
	else
	{
		system("cls");
	printf("************************************
");
    printf("**  1: 100元    *****    2:200元  **
");
	printf("************************************
");
    printf("**  3: 300元    *****    4:400元  **
");
	printf("************************************
");
    printf("**  5: 500元    *****    6:600元  **
");
	printf("************************************
");
    printf("请输入转账金额
");
	scanf("%d",&k);
	if(k>6||k<=0)
	{
		printf("对不起,您的输入有误

");
		return;
	}
	else
	{
		k=k*100;
		if(k>q->money)    //对余额进行判断
		{
			printf("对不起,您的余额不足
");
			system("pause");
			system("cls");
			menu(head);
		}
		else
		{
			printf("您已成功转账%d元
",k);
			q->money-=k;
			if((fp=fopen("save.txt","wb+"))==NULL)
			{
				printf("cannot open file
");
				return;
			}
			if(fwrite(q,sizeof(per),1,fp)!=1)  //将数据重新写入文件
				printf("file write error
");
			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("不能打开文件
");  
	}
	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元

",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("不能打开文件
");  
	}
	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("请输入您的原密码
");
	scanf("%s",code);
	if(strcmp(q->code,code)==0)   //核对密码
	{
		{
			printf("密码正确
");
			printf("请输入您的新密码:
");
			scanf("%s",q->code);
			if((fp=fopen("save.txt","wb+"))==NULL)  
			{
				printf("cannot open file
");
			}
			if(fwrite(q,sizeof(struct per),1,fp)!=1)    
				printf("file write error
");
			fclose(fp);
			printf("修改密码成功




");
		}
	}
	else
	{
		printf("您输入的密码与原密码不同
");
		return;
		system("pause");
	}
	q->next=NULL;
}

销户

void close(struct person **Phead)   
{
	char k[20];   
	struct person *p=*Phead,*t;
	if(NULL==(*Phead))    
	{
		printf("没有客户信息可删除!
");
		return;
	}
	printf("请输入要删除的客户卡号:
");
	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("对不起,没有该客户!
");
		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自动取款机系统**
");
    printf("——————————————
");
	printf("|   1  开户                 |
");
    printf("——————————————
");
	printf("|   2  登陆                 |
");
    printf("——————————————
");
	printf("|   3  前台客户信息查询中心 |
");
    printf("——————————————
");
	printf("|   请选择您的需求         |
");
    printf("———————————————
");
	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.
");
				 break;
		}
	}
}

运行截图

ATM管理系统
作业目标
代码
运行截图
作业小结
ATM管理系统
作业目标
代码
运行截图
作业小结
ATM管理系统
作业目标
代码
运行截图
作业小结
ATM管理系统
作业目标
代码
运行截图
作业小结
ATM管理系统
作业目标
代码
运行截图
作业小结
ATM管理系统
作业目标
代码
运行截图
作业小结

作业小结

psp表格

psp2.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
Planning 计划 240 10
Development 开发 110 150
Analysis 需求分析(包括学习新技术) 10 10
Design Spec 生成设计文档 30 40
Design Review 设计复审 5 10
Coding Standard 代码规范 5 5
Design 具体设计 10 12
Coding 具体编码 40 30
Code Review 代码复审 5 7
Test 测试(自我测试,修改代码,提交修改) 20 30
Reporting 报告 20 12
Test Report 测试报告 5 5
Size Measurement 计算工作量 3 1
Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 3 3

心得和经验

对于这次作业,用c语言编写代码,由于编码时链表的使用,我对链表有了更深的了解和掌握,编程能力得到了提升。