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

📄 stu.cpp

📁 模拟银行ATM提款机系统(单线程)
💻 CPP
字号:
/**Author: Xu Zhengyu  2001HDC(3)  413
Project: RAD Report---Project: RAD Report---Imitating ATM System based on C/S and DOS
Title: Imitating ATM System based on C/S and DOS
Function:  1 Inquire lacking money of account
           2 Modify code
		   3 Draw money from account
		   4 Login & Register
		   5 washing money
		   6 safeguard file of Server & Client (include modify IP address)
Date:2003/04/12  **/
/*safeguard program*/
#define LEN sizeof(struct bank)
#define KEN sizeof(struct moneyCou)
#define NULL 0


/*Formal program beginning*/
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"
#include "io.h"
#include "conio.h"
#include "dos.h"
#include "math.h"
#include "stdlib.h"
#include "passive.h"
#include "windef.h"
#include "winsock.h"
#include "memory.h"
#include "stdio.h"
#include "windef.h"
#include "fcntl.h"
#include "signal.h"
#include "sys/types.h"
#include "stdio.h"
#include "stdarg.h"
#include "io.h"
#include "conio.h"
#include "dos.h"
#include "math.h"

#include "stdlib.h"
#define bufsize 130
#define BUFSIZE  130
#define QLEN  5
extern int t_errno;
struct bank//bank.dat
{
 
 char name[5];//name of user
 char account[5];
 char money[5];//04000,40000
 char code[5];//code of user
 long crash;
 
} user[5]={
	{"xuzy","ad01","2500","2341",0},
{"chen","ad11","8600","1241",0},
{"suli","ad21","6000","2041",0},
{"lujh","ad32","7000","1234",0},
{"maol","ad22","5000","3457",0}
};
struct moneyCou{//date.dat
	char host[16];
	long money;//store money
	char username[5];
	char account[5];
	long lockmoney;//lock of account of user
} A[5];
void clrstr(){
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");//20 line
//printf("\n\n\n\n\n\n\n\n\n\n");//10 line
}
void main(int argc,char *argv[]){
	FILE *fp;
  struct bank *p;
  FILE *in;
  struct moneyCou *p1;
 char accountM[5];char codeM[5];
int fno,t,flen;long len=LEN;
lk:
 clrstr();
 printf("   0 Append Host and storeMoney to Date\n");
 printf("   1 Append account to bank\n");
 printf("   2 Modify IP address\n");
 printf("   3 Inquire account and code\n");
 printf("   4 Inquire IP address\n");
 printf("   5 Inquire username\n");
 printf("   6 Modify username\n");
 printf("   7 Exit\n");
 int e,j;
 printf("\n\n\n");
 printf("Please input number:");
 scanf("%d",&e);
	 if(e<0||e>7)goto lk;
	 switch(e){
	 case 0:{
		if((in=fopen("date.dat","a+"))==NULL){printf("File not exist!Press any key to exit!\n");getch();exit(0);}
       for(p1=A,j=0;1;p1++,j++){/*write a list record*/
        clrstr();
          printf("Please input  Host:");
      scanf("%s",p1->host);printf("\n");
       printf("Please input money:");
        scanf("%d",p1->money);printf("\n");
        p1->lockmoney=0;
          strcpy(p1->username,"nnou");
		strcpy(p1->account,"1000");
        
         fwrite(p1,KEN,1,in);
          L11: printf("Please input 0 (Y)or 8(N): ");

         scanf("%d",&e);
          if(e==0){continue;}
       else if(e==8){fclose(in);break;}
       else{goto L11;}
	   
		 }/*end of for*/	
			break;
			}
	 case 1:
		 {
		clrstr();	 
	  if((fp=fopen("bank.dat","a+"))==NULL){printf("File not exist!Press any key to exit!\n");getch();exit(0);}
       for(p=user,j=0;j<5;p++,j++){/*write a list record*/
        /**Author: Xu Zhengyu  2001HDC(3)  413
Project: RAD Report---Project: RAD Report---Imitating ATM System based on C/S and DOS
Title: Imitating ATM System based on C/S and DOS
Function:  1 Inquire lacking money of account
           2 Modify code
		   3 Draw money from account
		   4 Login & Register
		   5 washing money
		   6 safeguard file of Server & Client (include modify IP address)
Date:2003/04/12  **/
		printf("*");
         
         fwrite(p,LEN,1,fp);
          
	   
		 }/*end of for*/
	   
	 
		 break;
		 }
	 case 2:{
		 char adr[16];long money;//char ac[5];
		 
		 clrstr();
		 printf("Please input host:");
		 scanf("%s",adr);printf("\n");
         printf("Please input money:");
		 scanf("%d",&money);printf("\n");
          // printf("Please input account:");
		// scanf("%s",ac);printf("\n");
	if((in=(fopen("date.dat","r+w")))==NULL)printf("File not exist!\n");
 	fno=fileno(in);flen=filelength(fno); t=(flen/LEN);
	       p1=A;
     	  fread(p1,KEN,1,in);
	      strcpy(p1->host,adr);
		  p1->money=money;
          p1->lockmoney=0;
	//	strcpy(p1->account,ac);
         strcpy(p1->username,"1000");
           fseek(in,-len,1);
           fwrite(p1,LEN,1,in);
	    	 fclose(in);		
			break;
			}
	 case 3:{
                          clrstr();
                      printf("                    Please input your account:");
                        scanf("%s",accountM);printf("\n\n");
                      printf("                    Please input your code:");
                  scanf("%s",codeM);printf("\n\n");
			 if((fp=fopen("bank.dat","r"))==NULL){printf("File not exist!Press any key to exit!\n");getchar();exit(0);}
       for(p=user,j=0;j<5;p++,j++){/*write a list record*/
        
          fread(p,LEN,1,fp);
          if((!strcmp(p->account,accountM))&&(!strcmp(p->code,codeM))){
             clrstr();
           printf("  name:%s ",p->name);
          printf("       |  ");
          printf("  account:%s ",p->account);
          printf("       |  ");
        printf(" code: %s",p->code);
           printf("       |  ");
         printf(" Money: %s",p->money);
              printf("       |  ");
                printf(" crash: %d",p->crash);
                    printf("\n");
		             getchar();
                 fclose(fp);
                      getchar();
                     break;
		  }
		  
          
		 }/*end of for*/
		 
		 break;
			}
	 case 4:{
if((in=(fopen("date.dat","r+w")))==NULL)printf("File not exist!\n");
 	fno=fileno(in);flen=filelength(fno); t=(flen/LEN);
	       p1=A;
     	  fread(p1,KEN,1,in);
	      printf(" Host: %s \n",p1->host);
            printf(" Money: %d \n",p1->money);
          printf(" userName: %s \n",p1->username);
              printf(" account: %s \n",p1->account);

            printf(" lockmoney: %d \n",p1->lockmoney);
			getchar();
	    	 fclose(in);
			 getchar();
			break;
			
			}

	 case 5:{
		          clrstr();
                     
			 if((fp=fopen("bank.dat","r"))==NULL){printf("File not exist!Press any key to exit!\n");getchar();exit(0);}
       for(p=user,j=0;j<5;p++,j++){/*write a list record*/
        
          fread(p,LEN,1,fp);
          
             //clrstr();
           printf("  name:%s ",p->name);
          printf("       |  ");
          printf("  account:%s ",p->account);
          printf("       |  ");
        printf(" code: %s",p->code);
           printf("       |  ");
         printf(" Money: %s",p->money);
             
                    printf("\n");
		             getchar();
                 fclose(fp);
                     
		  
          
		 }/*end of for*/    
            
			break;
		             
			
			}
	 case 6:{
		    clrstr();
                      printf("                    Please input your account:");
                        scanf("%s",accountM);printf("\n\n");
                      printf("                    Please input your code:");
                  scanf("%s",codeM);printf("\n\n");
			 if((fp=fopen("bank.dat","r+w"))==NULL){printf("File not exist!Press any key to exit!\n");getchar();exit(0);}
       for(p=user,j=0;j<5;p++,j++){/*write a list record*/
        
          fread(p,LEN,1,fp);
          if((!strcmp(p->account,accountM))){
            strcpy(p->code,codeM);
    fseek(fp,-len,1);
    fwrite(p,LEN,1,fp);
     fclose(fp);break;
		  }
		  
          
		 }/*end of for*/
		 
		 
		 }
	 case 7:{
			exit(1);
			break;
			}
	 
	 
	 }

}


  

⌨️ 快捷键说明

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