課程設(shè)計(jì)c語言版銀行取款機(jī)系統(tǒng)_第1頁
課程設(shè)計(jì)c語言版銀行取款機(jī)系統(tǒng)_第2頁
課程設(shè)計(jì)c語言版銀行取款機(jī)系統(tǒng)_第3頁
課程設(shè)計(jì)c語言版銀行取款機(jī)系統(tǒng)_第4頁
課程設(shè)計(jì)c語言版銀行取款機(jī)系統(tǒng)_第5頁
已閱讀5頁,還剩25頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、課程設(shè)計(jì) C 語言版銀行取款機(jī)系統(tǒng)#include<stdio.h> #include<string.h> #include<stdlib.h> #include <conio.h> #define bool int #define true 1 #define LEN sizeof(struct person) struct per/* 定義全局結(jié)構(gòu)體變量 */char name20; char ID20; int money; char mima6; struct per *next;typedef struct person struct

2、per kehu ; struct person *next;L;void chaxun(struct per *head); /* 函數(shù)聲明 */ void kaihu(struct per *head);void denglu(struct per *head); void display(struct per *head); void caidan(struct per *head); void qukuan(struct per *head); void xgmm(struct per *head); void cunkuan(struct per *head); void zhuan

3、gzhang(struct per *head); void tuichu(); void menu();void out(struct person *r); void del(struct person *r); void sort(struct person *r);void insert(struct person *r); void search1(struct person *r); void search2(struct person *r); void search3(struct person *r); void createlist(struct person *r);/*

4、 主函數(shù) */ void main()char x;char choose;int flag=1;struct person *r=NULL; struct per *head=NULL;/* 定義頭指針 */ /* 定義頭指針 */printf(" printf(" printf("*n");* 歡迎使用 ATM 自動(dòng)取款機(jī)系統(tǒng) *n");*nnnn");printf("n");printf("| 1 開戶 printf("n");printf("| 2 登錄|n"

5、;);|n");printf("n");printf("| 3 前臺(tái)客戶信息查詢中心 |n");printf("n");printf("|請(qǐng)選擇您的需求|n");printf("n");scanf("%s",&x);system("cls");switch(x)case '1':system("cls"); kaihu(head); break;/* 調(diào)用開戶函數(shù) */case '2':

6、system("cls"); denglu(head); break;case '3':system("cls"); menu(); break;/* 調(diào)用登陸函數(shù) */* 調(diào)用后臺(tái)菜單函數(shù) */while(flag)system("cls");menu();choose=getchar();switch(choose)case '1':createlist(&r);out(r); system("pause"); system("cls"); break

7、;case '2':search1(r); system("pause"); system("cls"); break;case '3':search2(r);break;case '4':search3(r);break;case '5':del(&r);break;case '6':insert(&r);break;case '7':sort(&r);out(r);break;case '8':out(r);brea

8、k;case '0':flag=0;printf("The end.n"); break;/* 調(diào)用后臺(tái)菜單函數(shù) */* 調(diào)用后臺(tái)輸出函數(shù) */* 調(diào)用后臺(tái)卡號(hào)查詢函數(shù) */* 調(diào)用后臺(tái)姓名查詢函數(shù) */* 調(diào)用后臺(tái)余額查詢函數(shù) */* 調(diào)用后臺(tái)刪除用戶函數(shù)函數(shù) */* 調(diào)用后臺(tái)增加用戶函數(shù) */* 調(diào)用后臺(tái)排序函數(shù)函數(shù) */ /* 調(diào)用后臺(tái)輸出函數(shù)函數(shù) */* 開戶函數(shù) */ / void kaihu(struct per *head) head=NULL;/* 定義文件指針 */FILE *fp;per *p1=NULL,*p2=NULL;p1=(per

9、*)malloc(sizeof(per); printf(" 請(qǐng)輸入您的姓名 :n");scanf("%s",p1->name );printf(" 請(qǐng)?jiān)O(shè)置您的卡號(hào) :n");scanf("%s",p1->ID);printf(" 請(qǐng)?jiān)O(shè)置您銀行卡密碼 :n");scanf("%s",p1->mima); p1->money=0; p1->next =NULL; if(NULL=head)head=(per *)malloc(sizeof(per)

10、;head->next =p1;else/* 定義鏈表指針 */* 開辟內(nèi)存單元 */* 為新增客戶開辟內(nèi)存單元 */* 為新增客戶開辟內(nèi)存單元 */for(p2=head;p2->next!=NULL;p2=p2->next);p2->next=p1;if(fp=fopen("save.txt","ab+")=NULL)/* 打開文件 */printf("cannot open filen");return;if(fwrite(p1,sizeof(per),1,fp)!=1) printf("fil

11、e write errorn"); fclose(fp);system("cls");printf(" 您的個(gè)人信息為 n"); display(head);/* 將鏈表信息寫入文件中 */* 調(diào)用鏈表輸出函數(shù) */* 登陸函數(shù) */void denglu(struct per *head)char d20;char mima20;int i,j;FILE *fp;per *p,*q=NULL;if(fp=fopen("save.txt","rb+")=NULL)/* 定義文件指針 */* 打開一個(gè)二進(jìn)制

12、文件,為讀方式 */printf(" 不能打開文件 n");/* 如不能打開,則結(jié)束程序 */p=(per*)malloc(sizeof(per); head=p;while(!feof(fp)/* 申請(qǐng)空間 */* 循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束 */p=p->next;q->next=NULL; fclose(fp);printf("printf("printf("for(j=1;j<4;j+)printf(" 請(qǐng)您輸入卡號(hào) n");*n");* 歡迎來到建設(shè)銀行 *n");*n"

13、;);/* 限制卡號(hào)輸入的次數(shù)的循環(huán) */ if(1!=fread(p,sizeof(per),1,fp) break;/* 如果沒讀到數(shù)據(jù),跳出循環(huán) */p->next=(per *)malloc(sizeof(per); /* 為下一個(gè)結(jié)點(diǎn)申請(qǐng)空間 */ q=p;/* 保存當(dāng)前結(jié)點(diǎn)的指針,作為下一結(jié)點(diǎn)的前驅(qū) */* 指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾 */* 最后一個(gè)結(jié)點(diǎn)的后繼指針為空 */scanf("%s",d);/* 便利鏈表 */* 核對(duì)賬號(hào) */for(q=head;q!=NULL;q=q->next) if(strcmp(q->ID,d)!=

14、0) continue;elsefor(i=1;i<4;i+) /* 限制密碼輸入的次數(shù)的循環(huán) */ printf("nn 請(qǐng)輸入您的密碼 n"); scanf("%s",mima);if(strcmp(q->mima,mima)!=0)/* 核對(duì)密碼 */printf(" 密碼不正確,請(qǐng)重新輸入密碼 n");system("pause");system("cls");continue;/* 若密碼不對(duì),跳出循環(huán) */elsesystem("cls");caida

15、n(head);/* 調(diào)用菜單函數(shù) */printf("nnn 您輸入密碼三次錯(cuò)誤,謝謝光臨 n"); system("pause");system("cls"); exit(0);printf("nnn 您輸入的卡號(hào)有誤,請(qǐng)重試 n");system("pause");system("cls");printf(" 您的卡號(hào)三次輸入錯(cuò)誤,謝謝使用 "); exit(0);/* 輸出函數(shù) */void display(struct per *head)FIL

16、E *fp;/* 打開一個(gè)二進(jìn)制文件,為讀方式 */* 如不能打開,則結(jié)束程序 */* 申請(qǐng)空間 */* 循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束 */* 如果沒讀到數(shù)據(jù),跳出循環(huán) */* 為下一個(gè)結(jié)點(diǎn)申請(qǐng)空間 */* 保存當(dāng)前結(jié)點(diǎn)的指針,作為下一per *p,*q=NULL; if(fp=fopen("save.txt","rb+")=NULL) printf(" 不能打開文件 n");p=(per*)malloc(sizeof(per);head=p;while(!feof(fp) if(1!=fread(p,sizeof(per),1,fp)

17、break;q=p;結(jié)點(diǎn)的前驅(qū) */p=p->next;p->next=(per *)malloc(sizeof(per);/*指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾 */printf(" 姓名: %s n 卡號(hào): %s n 余額: %4dn",q->name ,q->ID,q->money ); q->next=NULL;*/* 最后個(gè)結(jié)點(diǎn)的后繼指針為空fclose(fp);printf("n");printf(" 恭喜您開戶成功,請(qǐng)登錄 n");system("pause");sy

18、stem("cls");denglu(head);/* 銀行菜單函數(shù) */void caidan(struct per *head) head=NULL; int i;while(1)printf(" 請(qǐng)選擇您需要的業(yè)務(wù) n"); printf( "*n"); printf("* 1 取款 * 2 查詢 printf( "*n"); printf("*3 轉(zhuǎn)賬*4 修改密碼printf( "*n"); printf("*5 存款*6 退出printf( "

19、*nnn"); 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");/* 銀行業(yè)務(wù)菜單 */1 取款*n");*n");*n");/* 調(diào)用銀行取款函數(shù) */* 調(diào)用銀行查詢

20、函數(shù) */zhuangzhang(head); break;case 4:system("cls"); xgmm(head);函數(shù) */break;case 5:system("cls"); cunkuan(head); break;case 6:system("cls"); tuichu(); break;elseprintf(" 您的輸入有誤 n"); system("pause"); system("cls");/* 調(diào)用銀行轉(zhuǎn)賬函數(shù) */*調(diào)用銀行修改密碼/* 調(diào)用銀

21、行存款函數(shù) */* 調(diào)用銀行退出函數(shù) */* 銀行取款函數(shù)函數(shù) */void qukuan(struct per *head) head=NULL;per *p;int i;FILE *fp;fp=fopen("save.txt","rb+");/* 鏈表頭指針 */* 文件頭指針 */* 開辟空間 */p=(per*)malloc(sizeof(per);fread(p,sizeof(per),1,fp); fclose(fp);system("cls");printf( "*n"); printf("

22、* 1: 100 元 * 2: 200 元 printf( "*n");printf("* 3: 300 元*4: 400 元printf( "*n");printf("* 5: 500 元*6: 600 元*n");*n");*n");printf( "*printf(" 請(qǐng)按要求選擇您要取款的金額 n"); scanf("%d",&i);if(i>6|i<=0)printf(" 對(duì)不起,您的輸入有誤 nn");

23、return;elsei=100*i;if(i>p->money )printf(" 對(duì)不起,您的余額不足 n"); system("pause");system("cls");caidan(head);else p->money-=i; if(fp=fopen("save.txt","wb+")=NULL)printf("cannot open filen"); return; if(fwrite(p,sizeof(per),1,fp)!=1) 件*/pr

24、intf("file write errorn"); printf(" 您已成功走取 %d 元n",i); p->next=NULL;fclose(fp);/* 打開文件 */* 將修改的信息重新寫入文/* 關(guān)閉文件 */* 銀行轉(zhuǎn)賬函數(shù) */ / void zhuangzhang(struct per *head) head=NULL;FILE *fp;char i20,j20,k;per *p,*q=NULL;/* 鏈表頭指針 */* 文件頭指針 */if(fp=fopen("save.txt","rb+"

25、;)=NULL)/* 打開一個(gè)二進(jìn)制文件,為讀方式 */* 如不能打開,則結(jié)束程序 */* 申請(qǐng)空間 */* 循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束 */* 如果沒讀到數(shù)據(jù),跳出循環(huán) */ 為下一個(gè)結(jié)點(diǎn)申請(qǐng)空間 */* 保存當(dāng)前結(jié)點(diǎn)的指針,作為下一結(jié)點(diǎn)/* 指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾 */* 最后一個(gè)結(jié)點(diǎn)的后繼指針為空 */printf(" 不能打開文件 n");p=(per*)malloc(sizeof(per);head=p;while(!feof(fp) if(1!=fread(p,sizeof(per),1,fp) break;p->next=(per *)mallo

26、c(sizeof(per); /* q=p;的前驅(qū) */p=p->next;q->next=NULL;fclose(fp);printf(" 請(qǐng)輸入轉(zhuǎn)賬號(hào)碼 n");scanf("%s",i);p=head;for(p;p!=NULL;p->next)if(strcmp(i,p->ID)!=0)printf(" 請(qǐng)重新輸入 n");zhuangzhang(head);elsesystem("cls");printf( "*n"); printf("* 1: 10

27、0 元 * 2: 200 元 printf( "*n"); printf("* 3: 300 元*4: 400 元printf( "*n"); printf("* 5: 500 元*6: 600 元printf( "*n"); printf(" 請(qǐng)輸入轉(zhuǎn)賬金額 n"); scanf("%d",&k);if(k>6|k<=0)*n");*n");*n");/* 限制輸入范圍 */printf(" 對(duì)不起,您的輸入有誤

28、nn"); return;elsek=k*100;if(k>p->money )printf(" 對(duì)不起,您的余額不足 n");system("pause");system("cls");caidan(head);elseprintf(" 您已成功轉(zhuǎn)賬 %d 元n",k); p->money-=k;/* 打開文件 */* 將修改的信息重新寫入文if(fp=fopen("save.txt","wb+")=NULL)printf("canno

29、t open filen"); return; if(fwrite(p,sizeof(per),1,fp)!=1) 件*/printf("file write errorn");p->next=NULL;fclose(fp);p->next=NULL;system("pause");system("cls");/* 銀行查詢函數(shù) */void chaxun(struct per *head)head=NULL;per *p;FILE *fp;fp=fopen("save.txt","

30、rb+"); p=(per*)malloc(sizeof(per); fread(p,sizeof(per),1,fp);/* 鏈表頭指針 */* 文件頭指針 */* 打開文件 */* 將信息從文件中讀出來 */fclose(fp);printf(" 您卡上原有余額為 %d 元 nn",p->money); system("pause");system("cls");/* 銀行修改密碼函數(shù) */ / void xgmm(struct per *head) head=NULL;per *p;char mima20;FIL

31、E *fp; fp=fopen("save.txt","rb+"); p=(per*)malloc(sizeof(per); fread(p,sizeof(per),1,fp);fclose(fp); printf(" 請(qǐng)輸入您的原密碼 n");scanf("%s",mima); if(strcmp(p->mima,mima)=0) printf(" 密碼正確 n");printf(" 請(qǐng)輸入您的新密碼 :n"); scanf("%s",p->

32、mima); if(fp=fopen("save.txt","wb+")=NULL) printf("cannot open filen"); return; if(fwrite(p,sizeof(per),1,fp)!=1)*/printf("file write errorn"); fclose(fp);printf(" 密碼修改成功 nnnnn"); elseprintf(" 您輸入的密碼與原密碼不同 n"); return;system("pause&quo

33、t;);/* 鏈表頭指針 */* 文件頭指針 */* 開辟內(nèi)存 */* 打開文件 */* 將信息從文件中讀出來 */* 核對(duì)密碼 */* 文件頭指針 */* 將修改的密碼重新寫入文件p->next=NULL;/* 銀行存款函數(shù) */* 鏈表頭指針 */void cunkuan(struct per *head) head=NULL;per *p;int i;/* 文件頭指針 */FILE *fp; fp=fopen("save.txt","rb+"); p=(per*)malloc(sizeof(per); fread(p,sizeof(per),

34、1,fp); fclose(fp); system("cls");printf(" 您卡上原有余額為 %d 元 n",p->money );printf( "* printf("* 1: 100 元 printf( "* printf("* 3: 300 元 * 4: 400 元 printf( "* printf("* 5: 500 元2: 200 元6: 600 元*n");*n");*n");printf( "* printf(" 請(qǐng)

35、選擇您要存入的金額 ");scanf("%d",&i);if(i>6|i<=0)printf(" 對(duì)不起,您的輸入有誤 nn");return; else/* 打開文件 */ i=100*i; p->money+=i;if(fp=fopen("save.txt","wb+")=NULL)printf("cannot open filen"); return;if(fwrite(p,sizeof(per),1,fp)!=1)/* 將修改的密碼重新寫入文件 */p

36、rintf("file write errorn"); printf(" 您已成功存取 %d 元 n",i); p->next=NULL;fclose(fp);system("pause");system("cls");/* 退出銀行函數(shù) */ / void tuichu()printf(" 謝謝使用 n"); exit(0);/* 后臺(tái)運(yùn)行菜單函數(shù) */ / void menu()/ 菜單顯示函數(shù)歡迎來到建設(shè)銀行取款機(jī)系統(tǒng)printf( "*nnnn");printf

37、( "*n"); printf("* 1 建立信息并顯示 * 2 卡號(hào)查詢信息 printf( "*n");printf("*3 姓名查詢信息*4 余額查詢信息printf( "*n");printf("*5 刪除某卡號(hào)信息*6 增加新的可戶printf( "*n");printf("*7 按余額降序輸出*8 輸出printf( "*n");printf("*0 退出*謝謝光臨printf( "*n");printf(&quo

38、t; 請(qǐng)選擇您需要的業(yè)務(wù) nn");*n");*n");*n");*n");*n");/* 后臺(tái)運(yùn)行創(chuàng)建鏈表函數(shù) */ / void createlist(struct person *r)/ 創(chuàng)建鏈表函數(shù) struct person *p,*t; char n20;char a20;int s;if(*r) *r=NULL;printf(" 請(qǐng)輸入卡號(hào)(請(qǐng)按卡號(hào)升序排列) printf(" 請(qǐng)輸入卡號(hào) n");scanf("%s",n);printf(" 請(qǐng)輸入姓名 n&q

39、uot;);/ 輸入信息 scanf("%s",a);printf(" 請(qǐng)輸入預(yù)存金額 n"); scanf("%d",&s);if(s=0) return; p=(L *)malloc(sizeof(L); strcpy(p->kehu.ID,n); strcpy(p->,a); p->kehu.money=s;p->next=NULL;*r=p; printf(" 請(qǐng)輸入卡號(hào) n"); scanf("%s",n);printf("

40、請(qǐng)輸入姓名 n"); scanf("%s",a);printf(" 請(qǐng)輸入預(yù)存金額 n"); scanf("%d",&s);while(s)t=p;p=(L *)malloc(sizeof(L); strcpy(p->kehu.ID,n); strcpy(p->,a); p->kehu.money=s; p->next=NULL;t->next=p;printf(" 請(qǐng)輸入卡號(hào) n"); scanf("%s",n);printf(

41、" 請(qǐng)輸入姓名 n"); scanf("%s",a);printf(" 請(qǐng)輸入預(yù)存金額 n");姓名 金額 (若要結(jié)束請(qǐng)輸入三個(gè)為零)/將信息輸入鏈表中/* 開辟內(nèi)存 */n");scanf("%d",&s);/ 輸入信息,直到輸入三個(gè)零終止/* 后臺(tái)運(yùn)行輸出鏈表函數(shù) */void out(struct person *r)/ 輸出信息函數(shù)printf("nn");if(!r)printf(" 沒有客戶信息可輸出 !n");return ;while(r)p

42、rintf(" 卡號(hào) :%sn 姓名 :%sn 余額 :%dn",r->kehu.ID,r->,r->kehu.money); r=r->next; printf("nn");/* 后臺(tái)運(yùn)行卡號(hào)查詢函數(shù) */void search1(struct person *r) / 運(yùn)用姓名查詢信息char m20;if(!r)printf(" 沒有客戶信息可查詢 !n");return ;printf(" 請(qǐng)輸入要查詢的客戶卡號(hào) :n");scanf("%s",

43、m); while(r&&strcmp(r->kehu.ID,m) r=r->next;if(r=NULL)printf("Error! No such kehu!n");elseprintf(" 卡號(hào) :%sn 姓名 :%sn 余額 :%dn",r->kehu.ID,r->,r->kehu.money); /* 后臺(tái)運(yùn)行姓名查詢函數(shù) */ / void search2(struct person *r) / 運(yùn)用姓名查詢信息char m20;if(!r)printf(" 沒有客戶

44、信息可查詢 !n");return ;printf(" 請(qǐng)輸入要查詢的客戶姓名 :n");scanf("%s",m); while(r&&strcmp(r->,m) r=r->next;if(r=NULL)printf("Error! No such kehu!n");elseprintf(" 卡號(hào) :%sn 姓名 :%sn 余額 :%dn",r->kehu.ID,r->,r->kehu.money); /* 后臺(tái)運(yùn)行余額查

45、詢函數(shù) */void search3(struct person *r) / 運(yùn)用卡號(hào)查詢long x;if(!r)printf(" 沒有客戶信息可查詢 !n");return ;printf(" 請(qǐng)輸入要查詢的客戶信息的余額 :n");scanf("%ld",&x);while(r&&r->kehu.money!=x)r=r->next;if(r=NULL)printf(" 對(duì)不起,沒有該客戶 !n");elseprintf(" 該客戶的信息為 n");printf(" 卡號(hào) :%sn 姓名 :%sn 余額 :%dn",r->kehu.ID,r->kehu.n

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論