C语言如何实现银行ATM存取款系统
C语言如何实现银行ATM存取款系统
这篇文章给大家分享的是有关C语言如何实现银行ATM存取款系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
一、课程设计的目的
掌握C语言程序设计的基础知识、基本理论、原理和实现技术。
二、课程设计的题目
银行ATM存取款系统
三、设计内容
(主要技术关键的分析、解决思路和方案比较等)
银行ATM存取款系统
银行ATM存取款系统业务描述如下:
银行ATM存取款系统能为用户提供存款、取款、查询、转账和修改密码的功能。
为了模拟真实的ATM业务环境,本系统必须实现存款、取款、查询、转账、修改密码以及开户的功能。
用户通过开户业务在本系统开立银行账户,之后可以通过该银行账户登陆ATM系统,在系统中实现存款、取款、查询账户信息、修改密码的操作。
本系统各个业务有如下注意点:
(1)登陆系统
用户登陆之前,必须在登陆界面输入其银行账户,通过其正确输入的银行账户登陆系统。
(2)开户业务
要使用本系统必须首先执行开户业务开立新的银行账户,并且将此新开的银行存储于文件当中。同时,系统以身份证号码作为开户的充分条件,即一个身份证号码只能开立一次银行账户。
(3)存款业务
客户登陆系统后,选择存款业务,即可以将输入的存款金额存入相应的账户。
(4)取款业务
客户登陆系统后,选择取款业务,即可以将输入的取款金额从相应的银行账户取出,但是取款金额必须大于目前的账户余额。
(5)查询业务
客户登陆系统后,可以选择查询业务,查询账户余额。
(6)转账业务
客户登陆系统后,可以选择转账业务,进行转账。注意的是转账的目的账户必须是本系统已经存在的银行账户。
(7)修改密码
客户登陆系统后,可以选择修改密码业务,进行密码修改。
实现的效果
源码
#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN1000#include<conio.h>structchuhu{charidnum[9];//账户charname[10];//姓名charidnumber[20];//省份证号charpassword[7];//密码doublecunkuan;//存款}hu[N];voiddate();//显示当前日期inta,a1;//主界面选择变量voidFlag1();//主界面voidFlag2();//用户界面voidFlag3();//用户功能选择界面voidzhuce();//注册intyanzheng();//验证存单号或密码//&&&&&&&&&&&&&&&&&&&&&&&voidqukaun();//取款voidcunkaun();//存款voiddisplay();//查询voidzhuan();//转账voidxiugai();//密码修改voiddisplay();//查找//&&&&&&&&&&&&&&&&&&&&&&&&&&intA,key;//开户人数inti;//控制密码循环charch='y';//是否继续注册doublejin;//存的钱intt;charid[11],password[7];intmain(){system("COLOR0A");intb;Flag1();//引入主界面do{printf("\n\n\t\t##请输入你的选择:");scanf("%d",&a);switch(a){case1:{zhuce();//zhuceFlag1();break;}case2:{b=yanzheng();fflush(stdin);///好东西,以防跳过数据Flag2();break;}case3:exit(0);break;default:printf("\n\n\n\t\t您输入的数据不符合要求!!!\n\n\n\n\n");}}while(1);}voidFlag1(){printf("\n#################################################################################\n");printf("\n▓*银行定期储蓄管理系统*▓\n");printf("\n#################################################################################\n");printf("\n◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆\n");printf("|◆|******|◆||◆|******|◆|\n");printf("|◆|******|◆|☆开户业务请按1|◆|******|◆|\n");printf("|◆|******|◆|☆登录系统请按2|◆|******|◆|\n");printf("|◆|******|◆|☆退出请按3|◆|******|◆|\n");printf("|◆|******|◆||◆|******|◆|\n");printf("◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆\n");printf("\n#################################################################################\n");}//********************************************************************************************************************//用户界面voidFlag2(){inta,b;//选择功能的变量do{printf("\n\n按ENTER键进入、返回主菜单");fflush(stdin);scanf("%c",&ch);system("cls");//清屏date();printf("\n#################################################################################\n");printf("\n▓*欢迎使用*▓\n");printf("\n#################################################################################\n");printf("\n◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆\n");printf("|◆|******|◆|☆存款业务请按1|◆|******|◆|\n");printf("|◆|******|◆|☆取款业务请按2|◆|******|◆|\n");printf("|◆|******|◆|☆查询业务请按3|◆|******|◆|\n");printf("|◆|******|◆|☆转账业务请按4|◆|******|◆|\n");printf("|◆|******|◆|☆修改密码请按5|◆|******|◆|\n");printf("|◆|******|◆|☆退出系统请按6|◆|******|◆|\n");printf("|◆|******|◆||◆|******|◆|\n");printf("◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆\n");printf("\n#################################################################################\n");printf("\n▓*******************************▓\n");printf("\n#################################################################################\n");printf("\n\n\t\t##请输入你的选择:");fflush(stdin);scanf("%d",&a);switch(a){//注册case1:{system("cls");fflush(stdin);cunkaun();break;//存款}case2:{system("cls");fflush(stdin);qukaun();break;//取款}case3:{display();//查询业务break;}case4:{system("cls");fflush(stdin);zhuan();break;//转账}case5:{system("cls");fflush(stdin);xiugai();break;//密码修改}case6:exit(0);default:printf("您输入的选择有误,请输入正确的选项:");}}while(1);}//********************************************************************************************************************//用户功能选择界面voidFlag3(){printf("\n\n\t\t##请输入你的选择:");scanf("%d",&a1);switch(a1){case1:printf("存款业务");break;case2:printf("取款业务");break;case3:printf("查询业务");break;case4:printf("转账业务");break;case5:printf("密码修改");break;case6:printf("退出");break;}}//********************************************************************************************************************//开户voidzhuce(){FILE*nchuhu=fopen("chuh.txt","r");FILE*fchuhu=fopen("chuh.txt","a");inti;if((nchuhu=fopen("chuh.txt","r"))==NULL)printf("文件无,系统创建\n");do{system("cls");date();//显示当前日期printf("\n\n\t\t请输入新储户的信息:");fscanf(nchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[A].idnum,&hu[A].name,&hu[A].idnumber,&hu[A].password,&hu[A].cunkuan);printf("\n\n\t\t储户存单:");fflush(stdin);gets(hu[A].idnum);printf("\n\t\t姓名:");fflush(stdin);gets(hu[A].name);printf("\n\t\t储户密码(6位):");for(i=0;i<6;i++){fflush(stdin);hu[A].password[i]=getch();printf("*");//scanf("%d",&hu[A].password[i]);}do{printf("请输入省份证号码(18位):");fflush(stdin);gets(hu[A].idnumber);if(strlen(hu[A].idnumber)!=18)//strlen代表的意思printf("\n\t\t输入错误!\n\t\t身份证请输入18位数字或者字母\n");for(i=0;i<A;i++)if(strcmp(hu[A].idnumber,hu[i].idnumber)==0&&strcmp(hu[A].name,hu[i].name)==0)break;if(i<A)printf("\n\n\t\t前面已经有人用此身份证注册过\n\n\t\t请重新输入省份证号:\n");}while((strlen(hu[A].idnumber)!=18)||(strcmp(hu[A].idnumber,hu[i].idnumber)==0)&&(strcmp(hu[A].name,hu[i].name)!=0));printf("输入存储的金额:");fflush(stdin);scanf("%lf",&hu[A].cunkuan);fprintf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[A].idnum,hu[A].name,hu[A].idnumber,hu[A].password,hu[A].cunkuan);A++;printf("是否继续是(y)/否(n)?");fflush(stdin);scanf("%c",&ch);}while(ch=='y'||ch=='Y');printf("存入成功!");//system("pause");system("cls");fclose(nchuhu);fclose(fchuhu);}//********************************************************************************************************************//验证存单号或密码intyanzheng(){FILE*fchuhu=fopen("chuh.txt","r");intcount=0;charid[9];for(i=0;i<=100;i++){fscanf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[i].idnum,&hu[i].name,&hu[i].idnumber,&hu[i].password,&hu[i].cunkuan);}do{system("cls");printf("\n\n\n\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");printf("\t\t|#||#|\n");printf("\t\t|#|☆☆☆☆☆☆☆☆☆☆|#|\n");printf("\t\t|#|☆☆|#|\n");printf("\t\t|#|☆存单号或者密码有误自动返回☆|#|\n");printf("\t\t|#|☆☆|#|\n");printf("\t\t|#|☆☆☆☆☆☆☆☆☆☆|#|\n");printf("\t\t|#||#|\n");printf("\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");printf("\n\n\n\t\t请输入您的存单号:");scanf("%s",&id);printf("\n\n\n\t\t请输入您的密码:");for(i=0;i<6;i++){fflush(stdin);password[i]=getch();printf("*");}password[6]='\0';fflush(stdin);scanf("c",&ch);printf("\n\n\t\t");for(i=0;i<99;i++){if(strcmp(id,hu[i].idnum)==0&&strcmp(password,hu[i].password)==0){fclose(fchuhu);return0;}}}while(count==0);fclose(fchuhu);returncount;}//********************************************************************************************************************//********************************************************************************************************************//存款voidcunkaun(){FILE*fchuhu=fopen("chuh.txt","r");FILE*achuhu=fopen("back.txt","w");charid[9];inti;if(!fchuhu)printf("不能打开文件:");if(!achuhu)printf("不能创建文件");for(i=0;i<=100;i++){fscanf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[i].idnum,&hu[i].name,&hu[i].idnumber,&hu[i].password,&hu[i].cunkuan);}//intx=0;date();printf("\n\n\t\t##请再次输入并确认存单:");scanf("%s",&id);for(i=0;i<=100;i++){if(strcmp(id,hu[i].idnum)==0){printf("\n\n");printf("\t\t||================================================================||\n");printf("\t\t||*存款金额*||\n");printf("\t\t||================================================================||\n");printf("\t\t||||\n");printf("\t\t||||\n");printf("\t\t||1、2002、4003、6004、800||\n");printf("\t\t||||\n");printf("\t\t||||\n");printf("\t\t||5、10006、20007、40008、6000||\n");printf("\t\t||||\n");printf("\t\t||================================================================||\n");printf("\t\t||================================================================||\n");printf("\n\n\t\t\t请输入你的取款金额:");scanf("%d",&a);switch(a){case1:{jin=200;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case2:{jin=400;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case3:{jin=600;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case4:{jin=800;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case5:{jin=1000;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case6:{jin=2000;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case7:{jin=4000;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case8:{jin=6000;printf("\t\t\t存款%lf元",jin);printf("\n\n\n\t\t\t^^^^存款成功^^^^");hu[i].cunkuan+=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}default:printf("\n\n\n\t\t\t您的选择金额不在服务范围内!!!\n\n\n\t\t\t请重新选择业务:");}fclose(fchuhu);fclose(achuhu);system("delchuh.txt");rename("back.txt","chuh.txt");//rename(旧的,新的)break;}}}//*******************************************************************************************************************//取款voidqukaun(){FILE*fchuhu=fopen("chuh.txt","r");FILE*achuhu=fopen("back.txt","w");inti;charid[9];if(!fchuhu)printf("不能打开文件:");if(!achuhu)printf("不能创建新文件:");for(i=0;i<=100;i++){fscanf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[i].idnum,&hu[i].name,&hu[i].idnumber,&hu[i].password,&hu[i].cunkuan);}date();printf("\n\n\t\t请再次输入并确认存单:");scanf("%s",&id);for(i=0;i<=99;i++){if(strcmp(id,hu[i].idnum)==0){printf("\n\n");printf("\t\t||================================================================||\n");printf("\t\t||*取款金额*||\n");printf("\t\t||================================================================||\n");printf("\t\t||||\n");printf("\t\t||||\n");printf("\t\t||1、2002、4003、6004、800||\n");printf("\t\t||||\n");printf("\t\t||||\n");printf("\t\t||5、10006、20007、40008、6000||\n");printf("\t\t||||\n");printf("\t\t||================================================================||\n");printf("\t\t||================================================================||\n");printf("\n\n\t\t\t请输入你的取款金额:");scanf("%d",&a);switch(a){case1:{jin=200;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case2:{jin=400;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case3:{jin=600;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case4:{jin=800;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case5:{jin=1000;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case6:{jin=2000;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case7:{jin=4000;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}case8:{jin=6000;printf("\t\t\t取出%lf元",jin);printf("\n\n\n\t\t\t^^^^取款成功^^^^");hu[i].cunkuan-=jin;printf("\n\n\t\t\t$您的余额为:%lf",hu[i].cunkuan);fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);break;}default:printf("\n\n\n\t\t\t您的选择金额不在服务范围内!!!\n\n\n\t\t\t请重新选择业务:");}fclose(fchuhu);fclose(achuhu);system("delchuh.txt");rename("back.txt","chuh.txt");break;}}}//********************************************************************************************************************//转账voidzhuan(){FILE*fchuhu=fopen("chuh.txt","r+");inti;charid[9];if(!fchuhu)printf("不能打开文件:");for(i=0;i<=100;i++){fscanf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[i].idnum,&hu[i].name,&hu[i].idnumber,&hu[i].password,&hu[i].cunkuan);}date();printf("\n\n\t\t请输入转账人的存单号:");scanf("%s",&id);for(i=0;i<=99;i++){if(strcmp(id,hu[i].idnum)==0){printf("\n\n\t\t请输入要转账的金额:");scanf("%lf",&jin);printf("\n\n\t\t请确认数目:%lf",jin);hu[i].cunkuan+=jin;printf("\n\n\n转账成功");fprintf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[A].idnum,hu[A].name,hu[A].idnumber,hu[A].password,hu[A].cunkuan);fclose(fchuhu);fclose(fchuhu);break;}}}//********************************************************************************************************************//********************************************************************************************************************voidxiugai(){FILE*fchuhu=fopen("chuh.txt","r");FILE*achuhu=fopen("back.txt","w");intj,i;charid[9];if(!fchuhu)printf("不能打开文件:");if(!achuhu)printf("不能创建新文件:");for(i=0;i<=100;i++){fscanf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[i].idnum,&hu[i].name,&hu[i].idnumber,&hu[i].password,&hu[i].cunkuan);}date();printf("\n\n\t\t请再次输入并确认存单:");scanf("%s",&id);for(i=0;i<=99;i++){if(strcmp(id,hu[i].idnum)==0){printf("请输入新的密码:\n");printf("\n\t\t储户密码(6位):");for(j=0;j<6;j++){fflush(stdin);hu[i].password[j]=getch();printf("*");}printf("\n\n\t\t新的密码:%s\n",hu[i].password);printf("\n\n\t\t修改成功");fprintf(achuhu,"%s\t%s\t%s\t%s\t%lf\n",hu[A].idnum,hu[A].name,hu[A].idnumber,hu[A].password,hu[A].cunkuan);fclose(fchuhu);fclose(achuhu);system("delchuh.txt");rename("back.txt","chuh.txt");break;}}}//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//查询信息voiddisplay(){FILE*fchuhu=fopen("chuh.txt","r");inti,n=0;charfnumb[9];system("cls");for(i=0;i<=100;i++){fscanf(fchuhu,"%s\t%s\t%s\t%s\t%lf\n",&hu[i].idnum,&hu[i].name,&hu[i].idnumber,&hu[i].password,&hu[i].cunkuan);}printf("\n\n●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●\n");printf("\n\n●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●\n");printf("\n\n●●●●●●●●●●●●●●●●●●●●●●●●●●\n");printf("\n\n\n\t\t\t\t\t请输入你的存单号:");scanf("%s",&fnumb);printf("\n\n\n");printf("\t\t\t\t\t您的个人信息如下:");printf("\n\n");for(i=0;i<=99;i++)if(strcmp(fnumb,hu[i].idnum)==0){printf("存单号:%s\t姓名:%s\t身份证:%s\t密码:%s\t存款金额:%lf\n",hu[i].idnum,hu[i].name,hu[i].idnumber,hu[i].password,hu[i].cunkuan);n=1;fclose(fchuhu);system("pause");break;}if(n==0)printf("此账单不存在!!!\n");fclose(fchuhu);}//********************************************************************************************************************voiddate(){//显示当前日期printf("当前日期:");system("date/t");printf("当前时间:");system("time/t");}
业务流程
1、用户开户
2、登录流程
3、密码修改
感谢各位的阅读!关于“C语言如何实现银行ATM存取款系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!