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

📄 atm.txt

📁 任务是开发一个模拟的ATM系统
💻 TXT
📖 第 1 页 / 共 2 页
字号:
#include <graphics.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <alloc.h>
#define NULL 0
#define LEN sizeof(struct yonghu)
#define X 0
#define Y 20
#define Z 5                                         
 struct yonghu
  {long zhang;
   char mi[6];
   long yu;
   int lei;
   struct yonghu *next;
  };
  struct yonghu *shumi(struct yonghu *p)     /*输入密码*/
  { int i;
    char k;
    gotoxy(Y,Z+4);printf("Please input the new user's password");
    gotoxy(Y+8,Z+6);
     for(i=0;i<6;i++)
       { k=getch();
       	 p->mi[i]=k;
       	 printf("*");
       }
    /* printf("\n"); */
    return(p);
  }
 struct yonghu *creat(void)            /* 创建新链表 */
   { FILE *fp; 
   	 struct yonghu *head;
     struct yonghu *p1,*p2;
     int n=0;
     p1=p2=(struct yonghu *)malloc(LEN);
     if((fp=fopen("d:\\sj.txt","r"))==NULL)
         printf("cannot open file\n");
     fscanf(fp,"%ld,%c,%c,%c,%c,%c,%c,%ld,%d,",&p1->zhang,&p1->mi[0],&p1->mi[1],&p1->mi[2],&p1->mi[3],&p1->mi[4],&p1->mi[5],&p1->yu,&p1->lei);
     /*scanf("%ld%ld%ld",&p1->zhang,&p1->mi,&p1->yu); */
     head=NULL;
     while(p1->zhang!=0)
       {n=n+1;
        if(n==1)  head=p1;
        else  p2->next=p1;
        p2=p1;
        p1=(struct yonghu *)malloc(LEN);
        fscanf(fp,"%ld,%c,%c,%c,%c,%c,%c,%ld,%d,",&p1->zhang,&p1->mi[0],&p1->mi[1],&p1->mi[2],&p1->mi[3],&p1->mi[4],&p1->mi[5],&p1->yu,&p1->lei); 
       }
     p2->next=NULL;
     fclose(fp);/*关闭文件*/
     return(head);
   }
 struct yonghu *creat1(struct yonghu *head)             /*构建新结点*/
   { struct yonghu *head1;
     struct yonghu *p1,*p2,*p0;
     p1=p2=(struct yonghu *)malloc(LEN);
 reinput:gotoxy(Y,Z);printf("please input the new user's name");  
         gotoxy(Y+8,Z+2);scanf("%ld",&p1->zhang);
         p0=head;                 /* 检查有没有相同的用户,如有则重新输入 */
         do
         { if(p0->zhang==p1->zhang) { clrscr();              /*清屏*/
         	                          gotoxy(Y+8,Z+4);printf("Sorry,The user had esixt!");
         	                          gotoxy(Y+6,Z+6);printf("Press any key and iuput again!");
         	                          getch();
         	                          clrscr();              /*清屏*/
     	                              goto reinput;
     	                            }
     	   p0=p0->next;                         
         }while(p0!=NULL);	                         
     p1=shumi(p1);          /*将光标移动到指定位置,并调用输入密码的函数*/
     gotoxy(Y,Z+8);printf("please input the new user's balance");
     gotoxy(Y+8,Z+10);scanf("%ld",&p1->yu);
     gotoxy(Y,Z+12);printf("please input the new user's type(User 1,administrator 2)");
     gotoxy(Y+8,Z+14);scanf("%d",&p1->lei);
     head1=p1;
     p2->next=NULL;
     return(head1);
   }
 void print(struct yonghu *head)           /*输出链表*/    /*调试用*/
   { struct yonghu *p;
     p=head;
     if(head!=NULL)
       do
         {printf("%ld,%c%c%c%c%c%c,%ld,%d\n",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);
           p=p->next;
         }while(p!=NULL);
     printf("\n");
   }
 struct yonghu *denglu(struct yonghu *p1,int r)          /*登陆函数,r为使用人员的类型*/
   { long zh;
   	 int i,j=0;
     char mi[6],k,h;
     if(p1->lei!=r) { gotoxy(Y,Z+5);printf("Sorry,you must choose right type!\n");
            	      getch();
            	      clrscr();
                      goto loop3;
                    }
            /* printf("%ld",p1->zhang);    调试用*/             
      loop2:gotoxy(Y,Z+6);printf("Please input your password\n");
            gotoxy(Y+8,Z+9);
            for(i=0;i<6;i++)   /*按一个键,就显示一个星号,而不显示密码的数值*/
              { k=getch();
       	        mi[i]=k;
       	        printf("*");
              } 
             for(i=0;i<6;i++)/*该处为密码检查.原来用的h=strcmp(p1->mi,mi);但不正确*/
               { if((mi[i]-p1->mi[i])!=0) { h=1;
               	                            break;
               	                          } 
               	 else h=0;
               }
            if(h!=0) { j++;
            	       clrscr(); /*清屏*/
            	       gotoxy(Y+6,Z+6);               /*将显示的字符移动到屏幕中间*/
            	       printf("Password error,Please enter again\n");
            	       getch();
            	       clrscr(); /*清屏*/
            	       if(j>=3)  { gotoxy(Y+5,Z+6);printf("You enter wrong password three times!");
            	       	           gotoxy(Y+6,Z+8);printf("Now,we'll goto the first interface!");
            	       	           getch();
            	       	           clrscr(); /*清屏*/
            	       	           goto loop3;/*如果输入三次密码都错误,则跳到起始界面*/
            	       	         }
                       goto loop2;
                     }
            clrscr(); /*登陆成功之后清屏*/
      loop3:return(j);
    }
 struct yonghu *gaimi(struct yonghu *head,struct yonghu *p)            /*修改密码的函数*/
   { FILE *fp; 
   	 long k; 
   	 int i,mi[6];
     gotoxy(Y,Z);printf("Please enter your new password\n");
     gotoxy(Y+8,Z+4);   	 
   	 for(i=0;i<6;i++)
              { k=getch();
       	        p->mi[i]=k;
       	        printf("*");
              }
     if((fp=fopen("d:\\sj.txt","w"))==NULL)     /*文件的正确存入-代码*/
      { clrscr(); /*清屏*/
        gotoxy(Y+6,Z+6);               /*将显示的字符移动到屏幕中间*/ 
      	printf("cannot open file \n");              /*文件的正确存入-代码*/
      	getch();
        clrscr();   /*清屏*/
        goto out;     /*如不能打开文件,则退出该子程序*/
      }
     p=head;                                     /*文件的正确存入-代码*/
       do                         /*文件的正确存入-代码*/
      {  /*printf("%ld,%c,%c,%c,%c,%c,%c,%ld,%d,\n",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei); 文件的正确存入-代码*/
        fprintf(fp,"%ld,%c,%c,%c,%c,%c,%c,%ld,%d,",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);  /*文件的正确存入-代码*/
        p=p->next;                                     /*文件的正确存入-代码*/
      } while(p!=NULL);   /*文件的正确存入-代码*/
      fclose(fp);/*关闭文件*/
              clrscr();              /*清屏*/
     gotoxy(Y,Z);printf("Modified password\n"); /*将该子函数的最后的输出到指定位置*/
     getch();
     /*print(head);  调试用*/
 out:return(p);
   }                                                        
 struct yonghu *chayu(struct yonghu *p)      /*查询余额*/
   { gotoxy(Y,Z);printf("Now your balance is:%ld yuan\n",p->yu);
     return(p);
   }
 struct yonghu *cun(struct yonghu *head,struct yonghu *p)        /*存款*/
   { FILE *fp;
   	 long a,m; 
     gotoxy(Y,Z);printf("Please enter money you want to store:\n");
     gotoxy(Y+8,Z+3);scanf("%ld",&a);
     p->yu=p->yu+a;
     m=p->yu;     
     if((fp=fopen("d:\\sj.txt","w"))==NULL)     /*文件的正确存入-代码*/
     printf("cannot open file \n");              /*文件的正确存入-代码*/
     p=head;                                     /*文件的正确存入-代码*/
       do                         /*文件的正确存入-代码*/
      {  /*printf("%ld,%c,%c,%c,%c,%c,%c,%ld,%d,\n",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei); 文件的正确存入-代码*/
        fprintf(fp,"%ld,%c,%c,%c,%c,%c,%c,%ld,%d,",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);  /*文件的正确存入-代码*/
        p=p->next;                                     /*文件的正确存入-代码*/
      } while(p!=NULL);/*文件的正确存入-代码*/
     fclose(fp);/*关闭文件*/
     clrscr();              /*清屏*/
     gotoxy(Y,Z);printf("Now your balance is:%ld yuan\n",m);    /*将该子函数的最后的输出到指定位置*/
     return(p);
   }
 struct yonghu *qu(struct yonghu *head,struct yonghu *p)       /*取款*/
   { FILE *fp;
   	 long a,m;
     gotoxy(Y,Z);printf("Please enter money you want to take:\n");
     gotoxy(Y+8,Z+3);scanf("%ld",&a);
     if(a>p->yu) {  gotoxy(Y,Z+6);printf("Sorry,your balance is not enough!\n");
                   goto end;
                 }
     p->yu=p->yu-a;
     m=p->yu;
      if((fp=fopen("d:\\sj.txt","w"))==NULL)     /*文件的正确存入-代码*/
     printf("cannot open file \n");              /*文件的正确存入-代码*/
     p=head;                                     /*文件的正确存入-代码*/
       do                         /*文件的正确存入-代码*/
      {/* printf("%ld,%c,%c,%c,%c,%c,%c,%ld,%d,\n",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);  文件的正确存入-代码*/
        fprintf(fp,"%ld,%c,%c,%c,%c,%c,%c,%ld,%d,",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);  /*文件的正确存入-代码*/
        p=p->next;                                     /*文件的正确存入-代码*/
      } while(p!=NULL);/*文件的正确存入-代码*/
      fclose(fp);/*关闭文件*/
       clrscr();  /*清屏*/
     gotoxy(Y,Z);printf("Now your balance is:%ld yuan",m);    /*将该子函数的最后的输出到指定位置*/
     end: return(p);
   }
 struct yonghu *tianjia(struct yonghu *head)  /*添加用户*/
   { FILE *fp;
   	 struct yonghu *p0,*p1,*p;
     p0=creat1(head);   /*调用构建结点的函数,多在链表后加结点*/
     p1=head;
     while(p1->next!=NULL)
        p1=p1->next;
     p1->next=p0;
     if((fp=fopen("d:\\sj.txt","w"))==NULL)     /*文件的正确存入-代码*/
     {  clrscr();  /*清屏*/
     	gotoxy(Y+8,Z+6);                           /*将显示的字符移动到屏幕中间*/
     	printf("cannot open file \n");              /*文件的正确存入-代码*/
     	getch();
        goto out;                                  /*如不能打开文件,则退出该子程序*/
     }
     p=head;                                     /*文件的正确存入-代码*/
       do                         /*文件的正确存入-代码*/
      {/* printf("%ld,%c,%c,%c,%c,%c,%c,%ld,%d,\n",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);  文件的正确存入-代码*/
        fprintf(fp,"%ld,%c,%c,%c,%c,%c,%c,%ld,%d,",p->zhang,p->mi[0],p->mi[1],p->mi[2],p->mi[3],p->mi[4],p->mi[5],p->yu,p->lei);  /*文件的正确存入-代码*/

⌨️ 快捷键说明

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