您好,登錄后才能下訂單哦!
本文為大家分享了C語言銀行儲(chǔ)蓄系統(tǒng)源碼,實(shí)現(xiàn)銀行的各項(xiàng)功能,供大家參考,具體內(nèi)容如下
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> void openaccount();//開戶 void save();//存款 void withdraw();//取款 void showAccount();//查詢 void transferAccounts();//轉(zhuǎn)賬 void reportLoss(); //掛失 void cancelLoss(); //解除掛失 void cancelAccount(); //注銷賬戶 void updatePassword(); //更改密碼 int load();//登陸賬號 int accountnum=0;//定義全局變量,用來計(jì)算賬戶數(shù)目 int nowaccount=0;//登錄成功是的賬戶 struct Bank { char account[20]; //賬號 char password[10]; //密碼 char name[20]; //用戶名 int balance;//賬戶余額 int state;//狀態(tài) }; //結(jié)構(gòu)體 struct Bank banks[100]; int load() { int right=0,i=0,j; int r1,r2; char ch; char account1[20]= {0}; char password1[10]= {0}; printf("登陸\n請輸入賬號:\n"); scanf("%s",account1); printf("請輸入密碼:\n"); while((ch=getch())!='\r') { password1[i++]=ch; putchar('*'); } for(j=0; j<accountnum; j++) { r1=strcmp(account1,banks[j].account); r2=strcmp(password1,banks[j].password); if(r1==0&&r2==0) { nowaccount=j; if(banks[j].state==0) { printf("登錄成功!\n");//登錄成功 right=1; } else if(banks[j].state==1) { printf("您的賬戶處于掛失狀態(tài),請解掛\n"); right=3; } else if(banks[j].state==2) { printf("賬戶已經(jīng)銷戶\n"); right=2; } break; } } if(right==0) printf("登陸失?。n"); return right; } int main() { int i=0,num; char a[100]; FILE *fp; if((fp=fopen("account.txt","r"))==NULL) { if((fp=fopen("account.txt","w"))==NULL) { printf("失?。n"); exit(1); } } while(fscanf(fp,"%s%s%s%d%d",banks[i].account,banks[i].name,banks[i].password,&banks[i].balance,&banks[i].state)!=EOF) { accountnum++; i++; } fclose(fp); printf("歡迎來到我的銀行\(zhòng)n"); while(1) { printf("請選擇業(yè)務(wù):\n"); printf("1.開戶 2.存款 3.取款\n"); printf("4.查詢 5.轉(zhuǎn)賬 6.掛失\n"); printf("7.解掛 8.銷戶 9.改密\n"); printf("-1.退出\n"); scanf("%s",a); num=atoi(a); if(num==1) openaccount();//開戶 else if(num==2) save();//存款 else if(num==3) withdraw();//取款 else if(num==4) showAccount();//查詢 else if(num==5) transferAccounts();//轉(zhuǎn)賬 else if(num==6) reportLoss(); //掛失 else if(num==7) cancelLoss(); //解掛 else if(num==8) cancelAccount(); //注銷賬戶 else if(num==9) updatePassword(); //更改密碼 else if(num==-1) { printf("歡迎下次再來\n"); break; } else printf("抱歉,沒有此業(yè)務(wù)\n"); } if((fp=fopen("account.txt","w"))==NULL) { printf("失?。n"); exit(1); } for(i=0; i<accountnum; i++) { fprintf(fp,"%s\t%s\t%s\t%d\t%d\n",banks[i].account,banks[i].name,banks[i].password,banks[i].balance,banks[i].state); } fclose(fp); return 0; } void openaccount() { int i=0,j=0; int r; char ch; char password1[10]= {0}; printf("賬戶(十位數(shù)):\n"); scanf("%s",banks[accountnum].account); while(banks[accountnum].account[i]!='\0') i++; if(i!=10) { printf("輸入賬號有誤\n"); return; } i=0; printf("姓名:\n"); scanf("%s",banks[accountnum].name); printf("密碼:\n"); while((ch=getch())!='\r') { banks[accountnum].password[i++]=ch; putchar('*'); } printf("\n"); printf("再次輸入密碼:\n"); while((ch=getch())!='\r') { password1[j++]=ch; putchar('*'); } printf("\n"); r=strcmp(banks[accountnum].password,password1); if(r!=0) { printf("兩次密碼不相同,開戶失??!\n"); return; } banks[accountnum].balance=0; banks[accountnum].state=0; accountnum++; printf("開戶成功\n"); } void save() { if(load()!=1) return; char addmoney[10];//存入金額 int money;//將字符型轉(zhuǎn)化為int型 int i=0; printf("存入金額:\n"); scanf("%s",addmoney); while(addmoney[i]!='\0') { if(addmoney[i]<'0'||addmoney[i]>'9') { printf("輸入格式錯(cuò)誤!\n"); return; } i++; } while(addmoney[i]!='\0') { if(i>9) { printf("金額超限\n"); return; } i++; } money=atoi(addmoney); if(money==0) { printf("存款失敗\n"); return; } else { banks[nowaccount].balance+=money; printf("存款成功\n"); } } void withdraw() { if(load()!=1) return; char reducemoney[10];//取款金額 int money,i=0; printf("請輸入取款金額\n"); scanf("%s",reducemoney); while(reducemoney[i]!='\0') { if(reducemoney[i]<'0'||reducemoney[i]>'9') { printf("輸入格式錯(cuò)誤!\n"); return; } i++; } while(reducemoney[i]!='\0') { if(i>9) { printf("金額超限\n"); return; } i++; } money=atoi(reducemoney); if(money==0) { printf("取款失敗\n"); return; } else { if(money>banks[nowaccount].balance) printf("您的賬戶沒有這么多余額,取款失敗!\n"); else { banks[nowaccount].balance-=money; printf("取款成功\n"); } } } void showAccount() { if(load()!=1&&load()!=2) return; printf("您的賬戶信息如下:\n"); printf("賬號:%s\t余額:%d\n",banks[nowaccount].account,banks[nowaccount].balance); } void transferAccounts() { if(load()!=1) return; char account1[20]; int i,judge=0,money,a; char tramoney[10]; printf("請輸入您轉(zhuǎn)入的賬戶\n"); scanf("%s",account1); for(i=0; i<accountnum; i++) { if(strcmp(account1,banks[i].account)==0) { a=i; judge=1; break; } } if(judge!=1) { printf("沒有發(fā)現(xiàn)此賬戶\n"); return; } printf("請輸入轉(zhuǎn)賬金額\n"); scanf("%s",tramoney); while(tramoney[i]!='\0') { if(tramoney[i]<'0'||tramoney[i]>'9') { printf("輸入格式錯(cuò)誤!\n"); return; } i++; } while(tramoney[i]!='\0') { if(i>9) { printf("金額超限\n"); return; } i++; } money=atoi(tramoney); if(money==0) { printf("轉(zhuǎn)賬失敗\n"); return; } else { if(money>banks[nowaccount].balance) printf("您的賬戶沒有這么多余額,轉(zhuǎn)賬失敗!\n"); else { banks[nowaccount].balance-=money; banks[a].balance+=money; printf("轉(zhuǎn)賬成功\n"); } } } void reportLoss() { if(load()!=1) return; banks[nowaccount].state=1; printf("掛失成功\n"); } void cancelLoss() { int judge=0; if(load()==3) { printf("立即解掛請按1,退出請按0\n"); scanf("%d",&judge); if(judge==1) { banks[nowaccount].state=0; printf("解掛成功\n"); } } else if(load()==1) printf("賬戶正常\n"); } void cancelAccount() { int r; r=load(); if(r==2) { printf("賬戶已經(jīng)銷戶\n"); return; } else if(r==3||r==0) return; else if(r==1) { printf("請將您的賬戶余額取完\n"); banks[nowaccount].state=2; banks[nowaccount].balance=0; printf("注銷成功\n"); } } void updatePassword() { char newpassword1[10]= {0},newpassword2[10]= {0}; int i=0,j=0,r; char ch; if(load()!=1) return; printf("請輸入新密碼\n"); while((ch=getch())!='\r') { newpassword1[i++]=ch; putchar('*'); } printf("\n"); printf("再次輸入密碼:\n"); while((ch=getch())!='\r') { newpassword2[j++]=ch; putchar('*'); } printf("\n"); r=strcmp(newpassword1,newpassword2); printf("r:%d",r); if(r!=0) { printf("兩次密碼不相同,改密失敗!\n"); return; } i=0; while(newpassword1[i]!='\0') { banks[nowaccount].password[i]=newpassword1[i]; i++; } printf("改密成功\n"); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。