zoukankan      html  css  js  c++  java
  • 个人作业三-

    一:作业信息

    博客班级 https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18
    作业要求 https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/homework/11478
    作业目标 编写一个简单的ATM机管理系统
    学号 3180701323

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

    三:代码提交与运行截图
    1:源代码
    主函数

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    struct per           //定义结构体
    {
    	char name[20];
    		char ID[20];
    		int money;
    		char mima[6];
    		struct per * next;
    };
    typedef struct person    //定义另一结构体
    {
    	struct per kehu;
    	struct person *next;
    }L;
    void kaihu(struct per *head);
    void denglu(struct per *head);
    void caidan(struct per *head);
    void qukuan(struct per *head);
    void cunkuan(struct per *head);
    void zhuanzhang(struct per *head);
    void chuangjian(struct person **Phead);
    void shanchu(struct person **Phead);
    void chaxun(struct per *head);
    void tuichu();
    void menu();
    /*主函数*/
    void main()
    {
    	char x;
    	char choose;
    	int flag=1;
    	struct person *Phead=NULL;
    	struct per *head=NULL;
    	printf("*****************************
    ");
    	printf("**欢迎使用ATM管理系统**
    ");
    	printf("*****************************
    ");
    	printf("——————————————
    ");
    	printf("|    1  开户               |
    ");
        printf("——————————————
    ");
    	printf("|    2  登陆                |
    ");
        printf("——————————————
    ");
    	printf("|    3  后台       (销户)|
    ");
        printf("——————————————
    ");
    	scanf("%s",&x);
    	system("cls");
    	switch(x)
    	{
    		case '1':system("cls");
    	         kaihu(head);
    			 break;
    		case '2':system("cls");
    			denglu(head);
    			break;
    		case '3':system("cls");
    			menu();
    			break;
    	}
    	while(flag)
    	{
    		system("cls");
    		menu();
    		choose=getchar();
    		switch(choose)
    		{ 
        	case '1':shanchu(&Phead);
    				 system("pause");
    				 system("cls");
    				 break;
        	case '0':flag=0;
    			     printf("The end.
    ");
    				 break;
    		}
    	}
    }
    

    查询:

    void chaxun(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 kaihu(struct per *head)
    {
    	head=NULL;
    	FILE *fp;
    	struct per *p1=NULL,*p2=NULL;
    	p1=(struct per*)malloc(sizeof(struct per));
    	      printf("请输入您的姓名:
    ");
    		  scanf("%s",p1->name);
    		  printf("请设置您的卡号:
    ");
    		  scanf("%s",p1->ID);
    		  printf("请设置您银行卡密码:
    ");
    		  scanf("%s",p1->mima);
    		  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");
    			  denglu(head);
    }
    

    登录

    void denglu(struct per *head)
    {
    	char d[20];
    	char mima[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("  ***欢迎使用ATM管理系统***
    ");
    	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)
    				break;
    			else		
    			{			
    				for(i=1;i<4;i++)
    				{				
    					printf("
    
    请输入您的密码
    ");				
    					scanf("%s",mima);
    					if(strcmp(q->mima,mima)!=0)
    					{				
    						printf("密码不正确。请重新输入密码
    ");				
    						system("pause");				
    						system("cls");				
    						continue;
    					}			
    					else				
    					{			
    						system("cls");				
    						caidan(head);
    					}		
    				}		
    				printf("
    
    
    您输入密码三次错误,谢谢光临
    ");		
    				system("pause");		
    				system("cls");		
    				exit(0);	
    			}
    		}		
    		printf("
    
    
    您输入的卡号有误,请重试
    ");
    		system("pause");
    		system("cls");
    	}
    	exit(0);
    }
    

    菜单

    void caidan(struct per *head)
    {
    	head=NULL;
    	int i;
    	while(1)
    	{
    		printf("请选择您需要的业务
    ");
    		printf("*********************************
    ");
    		printf("**  1 取款   *****   2 查询    **
    ");
    		printf("*********************************
    ");
    		printf("**  3 转账   *****   4存款**
    ");
    		printf("*********************************
    ");
    		printf("**  0  退出    **
    ");
    		printf("*********************************
    ");
    		scanf("%d",&i);
    		if(i<6||i>0)
    		{
    			switch(i)
    			{
    			case 1:qukuan(head);
    			       system("pause");
    				   system("cls");
    				   break;
    			case 2:system("cls");
    				   chaxun(head);
    				   break;
                case 3:system("cls");
    				   zhuanzhang(head);
    				   break;
                case 4:system("cls");
    				   cunkuan(head);
    				   break;
                case 0:system("cls");
    				   tuichu();
    				   break;
    			}
    		}
    		else
    		{
    			printf("您的输入有误
    ");
    			system("pause");
    			system("cls");
    		}
    	}
    }
    

    取款

    void qukuan(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("请按要求选择您要取款的金额
    ");
    	scanf("%d",&i);
    	if(i>q->money)
    	{
    		printf("对不起,您的金额不足
    ");
    		system("pause");
    		system("cls");
    		caidan(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 cunkuan(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("请选择您要存入的余额
    ");
    	scanf("%d",&i);
    	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 chaxun(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 zhuanzhang(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("两次账号不同,请重新输入
    ");
    		zhuanzhang(head);
    	}
    	else
    	{
    		system("cls");
    		printf("请输入转账金额
    ");
    		scanf("%d",&k);
    		if(k>q->money)
    		{				
    			printf("对不起,您的余额不足
    ");
    			system("pause");
    			system("cls");
    			caidan(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 shanchu(struct person **Phead)
    {
    	char k[20];
    	struct person *p=*Phead,*t;
    	if(NULL==(*Phead))
    	{
    		printf("没有客户信息可删除!
    ");
    		return;
    	}
    	printf("请输入要删除的客户卡号:
    ");
    	scanf("%s",k);
    	if(p->kehu.ID==k)
    		*Phead=(*Phead)->next,free(p);
    	else
    	{
    		while(NULL==p->next&&p->next->kehu.ID!=k)
    			p=p->next;
    		if(p->next==NULL)
    			printf("对不起,没有该客户!
    ");
    		else
    		{
    			t=p->next;
    			p->next=p->next->next;
    			printf("销户成功
    ");
    		}
    	}
    }
    

    运行截图:







    四:个人小结
    本次的任务是做一个简单的ATM机管理系统,它有基本的存款、取款等功能,但系统对于文件的读写还有一定的问题,文件读入后会存在乱码,然后销户的功能不够完善。但对于博客园的功能有了更加完善的了解,也对软件工程这门课有了更加清晰的认识。
    PSP:

    psp3.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
    Planning 计划 15 12
    Estimate 估计这个任务需要多少时间,并规划大致工作步骤 8 8
    Development 开发 120 130
    Analysis 需求分析(包括学习新技术) 12 15
    Design Spec 生成设计文档 5 6
    Design Review 设计复审 5 5
    Coding Standard 代码规范 3 4
    Design 具体设计 12 16
    Coding 具体编码 35 40
    Code Review 代码复审 5 6
    Test 测试(自我测试,修改代码,提交修改) 10 15
    Reporting 报告 10 12
    Test Report 测试报告 6 12
    Size Measurement 计算工作量 20 25
    Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 5 5
  • 相关阅读:
    windows下设置sublime
    sublime编辑器快捷键
    Navicat Premium 12.1.8.0安装与激活
    Win查找弹窗广告来源
    canvas-绘制时钟
    H5标签-canvas实现颜色拾取功能
    第一次Sprint团队贡献分
    Sprint第一个冲刺(第十一天)
    Sprint第一个冲刺(第十天)
    Sprint第一个冲刺(第九天)
  • 原文地址:https://www.cnblogs.com/hjh12138/p/13987233.html
Copyright © 2011-2022 走看看