數(shù)據(jù)結(jié)構(gòu)課程設(shè)計活期儲蓄賬目管理_第1頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計活期儲蓄賬目管理_第2頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計活期儲蓄賬目管理_第3頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計活期儲蓄賬目管理_第4頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計活期儲蓄賬目管理_第5頁
已閱讀5頁,還剩28頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、活期儲蓄賬目管理一 目的滿足活期儲蓄處理中,儲戶開戶、銷戶、存入、支出活動頻繁,系統(tǒng)設(shè)計要求。能比較迅速地找到儲戶的帳戶進而顯示儲戶信息,以實現(xiàn)存款、取款記賬;能比較簡單,迅速地實現(xiàn)插入和刪除,以實現(xiàn)開戶和銷戶的需要;熟練使用 C 語言編寫程序,解決實際問題;學會編制結(jié)構(gòu)清晰、風格良好、數(shù)據(jù)結(jié)構(gòu)適當?shù)腃語言程序,從而具備利用計算機編程分析解決綜合性實際問題的初步能力。二 需求分析1、數(shù)據(jù)需求1.需先進行儲戶開戶才可進行之后的所有的操作。2.開戶時需要的數(shù)據(jù)有姓名、身份證號碼、聯(lián)系電話、密碼、賬號會自動生成。3.銷戶時,需用輸入賬號與密碼(兩者都正確后)方可銷戶;存取款時,也需進行賬號及密碼驗證

2、后方可進行交易。2、基本功能需求基本的功能有新建儲戶(開戶)、刪除儲戶(銷戶)、存取款、查詢儲戶信息(此步也可看見交易后的信息)、顯示所有儲戶信息。3、 非功能性需求 系統(tǒng)以菜單界面方式工作,運行界面友好,演示程序以用戶和計算機的對話方式進行。三 概要設(shè)計1、數(shù)據(jù)結(jié)構(gòu)設(shè)計用結(jié)構(gòu)體來定義其數(shù)據(jù)類型,然后將數(shù)據(jù)按照該數(shù)據(jù)結(jié)構(gòu)存儲,之后運用文件的相關(guān)知識將更改的數(shù)據(jù)寫入文件中,采用數(shù)組類型的存儲結(jié)構(gòu)。2、儲存結(jié)構(gòu)體設(shè)計本系統(tǒng)主要用線性表表結(jié)構(gòu)類型來存儲在“活期儲蓄賬目管理系統(tǒng)”中的信息。其中,結(jié)構(gòu)體由5個分量構(gòu)成:用戶賬號、用戶姓名、用戶身份證號碼、用戶密碼、開戶金額。3、 模塊設(shè)計活期儲蓄賬目管理

3、顯示菜單選擇功能 1.新建儲戶 2.查詢儲戶信息3.顯示所有儲戶信息4.刪除儲戶5.存款 6.取款 7.退出賬目管理。void add()函數(shù)實現(xiàn)新建儲戶功能void select_id()函數(shù)實現(xiàn)查詢儲戶信息功能void display()函數(shù)實現(xiàn)顯示所有儲戶信息功能void del()函數(shù)實現(xiàn)刪除儲戶功能void save_money() 函數(shù)實現(xiàn)存款功能void get_money()函數(shù)實現(xiàn)取款功能void print()函數(shù)用于顯示菜單void main()函數(shù)用于實現(xiàn)菜單中的功能四 詳細設(shè)計1、結(jié)構(gòu)體的詳細定義struct user /用戶類型(賬號,姓名,身份證號,存款)int

4、id;char name20;char person_num19;char password6;double money;2、系統(tǒng)函數(shù)詳細介紹void add()函數(shù)實現(xiàn)新建儲戶功能void add() /添加用戶printf(%45sn,*新建儲戶*);printf(-nn);struct user getuser();struct user temp;int count(); /函數(shù)目的:計算文件中的記錄數(shù)目 以生成自動賬號FILE *fp;int number;if(fp=fopen(file,ab)=NULL)printf(Can not open file!n);exit(1);te

5、mp=getuser(); /讀取用戶名number=count();temp.id=number+1; /生成自動賬號fwrite(&temp,sizeof(struct user),1,fp);printf(添加用戶成功!n);fclose(fp);void select_id()函數(shù)實現(xiàn)查詢儲戶信息功能void select_id() /查詢儲戶信息int count();void getpassword(char *password);printf(%45sn,*查詢儲戶信息*);printf(-n);printf(%s %15s %15s %15sn,編號,用戶姓名,身份證號碼,存款

6、余額);printf(-nn);FILE *fp;struct user temp;int i,maxnum;char password8;bool flag=false;if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);maxnum=count();printf(輸入要查詢賬號:); scanf(%d,&i);if(imaxnum)printf(你要查詢的賬號不存在!);return;printf(輸入賬號密碼:);scanf(%s,&password);while(fread(&temp,sizeof(struct u

7、ser),1,fp) /循環(huán)讀取每一條記錄 判斷是否為要查看的記錄if(temp.id=i&strcmp(temp.password,password)=0)printf(NO.%d %8s %25s %.2fn,temp.id,,temp.person_num,temp.money);flag=true;break;if(flag=false) /判斷密碼是否正確printf(您輸入的密碼不正確!n);return;fclose(fp);void display()函數(shù)實現(xiàn)顯示所有儲戶信息功能void display() /顯示所有儲戶信息printf(%45sn,*顯示所

8、有儲戶信息*);printf(-n);printf(%s %15s %15s %15sn,賬號,用戶姓名,身份證號碼,存款余額);printf(-n);FILE *fp;struct user temp;if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);while(fread(&temp,sizeof(struct user),1,fp)printf(NO.%d %10s %23s %.2fn,temp.id,,temp.person_num,temp.money);fclose(fp);void del

9、()函數(shù)實現(xiàn)刪除儲戶功能void del() /刪除儲戶printf(%45sn,*刪除儲戶*);printf(-n);printf(%s %15s %15s %10sn,賬號,用戶姓名,身份證號碼,存款余額);printf(-n);int count();void getname(char *name);void getperson_num(char *person_num);void getpassword(char *password);FILE *fp;int i,num,mark;char password6;bool flag=false;struct user *temp;num

10、=count();/根據(jù)記錄數(shù)申請空間temp=(struct user *)malloc(num*sizeof(struct user);if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);for(i=0;inum;i+)/讀取文件內(nèi)容fread(&tempi,sizeof(struct user),1,fp);fclose(fp);printf(輸入要需要注銷的賬號:);scanf(%d,&mark);if(inum)printf(你要注銷的賬號不存在!);return;printf(輸入賬號密碼: );scanf(%s

11、,&password);if(fp=fopen(file,wb)=NULL) /寫方式打開文件,覆蓋原文件中的內(nèi)容printf(cannot open file!n);exit(1);for(i=0;inum;i+) /無效賬戶信息全部置為0if(tempi.id=mark&strcmp(tempi.password,password)=0&tempi.money=0.00) strcpy(tempi.person_num,0);strcpy(,0);strcpy(tempi.password,0);flag=true;fwrite(&tempi,sizeof(struct

12、 user),1,fp);fclose(fp);free(temp);if(flag=false)printf(您輸入的密碼不正確或是余額不為零!n);elseprintf(儲戶注銷成功!n);void save_money() 函數(shù)實現(xiàn)存款功能void save_money() /函數(shù)功能:存款printf(%45sn,*用戶存款業(yè)務*);printf(-nn);int count();void getpassword(char *password);FILE *fp;int i,num,mark;bool flag=false;struct user *temp;char password

13、6;num=count(); temp=(struct user *)malloc(num*sizeof(struct user); /根據(jù)記錄數(shù)申請空間if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);for(i=0;inum;i+) /將文件內(nèi)容存入數(shù)組fread(&tempi,sizeof(struct user),1,fp);fclose(fp);printf(輸入要存款賬號:); /讀取存款賬號scanf(%d,&mark);if(inum)printf(你要查詢的賬號不存在!);return;printf(輸入

14、賬號密碼: );scanf(%s,&password);if(fp=fopen(file,wb)=NULL) /寫方式打開文件,覆蓋原文件中的內(nèi)容printf(cannot open file!n);exit(1);for(i=0;inum;i+)if(tempi.id=mark&strcmp(tempi.password,password)=0)double money=0;printf(輸入要存入的金額:);scanf(%lf,&money);while(1)if(money=0)printf(只能為正數(shù)!n);money=0;printf(輸入要存入的金額:);scanf(%lf,&mo

15、ney);elsebreak;tempi.money +=money; flag=true;fwrite(&tempi,sizeof(struct user),1,fp); /修改該用戶的信息fclose(fp);free(temp);if(flag=false)printf(您輸入的密碼不正確!n);elseprintf(你存款業(yè)務已辦妥!n);void get_money()函數(shù)實現(xiàn)取款功能void get_money() /函數(shù)功能:用戶取款printf(%45sn,*用戶取款業(yè)務*);printf(-nn);int count();FILE *fp;int i,num,mark;cha

16、r password6;bool flag=false;struct user *temp;num=count();/根據(jù)記錄數(shù)申請空間temp=(struct user *)malloc(num*sizeof(struct user);if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);for(i=0;inum;i+)/讀取文件內(nèi)容fread(&tempi,sizeof(struct user),1,fp);fclose(fp);printf(輸入要取款賬號:);scanf(%d,&mark);if(inum)printf

17、(你要查詢的賬號不存在!);return;printf(輸入賬號密碼: );scanf(%s,&password);if(fp=fopen(file,wb)=NULL) /寫方式打開文件,覆蓋原文件中的內(nèi)容printf(cannot open file!n);exit(1);for(i=0;inum;i+) if(tempi.id=mark&strcmp(tempi.password,password)=0) double money=0;printf(輸入要取出的金額:);scanf(%lf,&money);if(moneytempi.money)printf(你的余額不足!n);money

18、=0;tempi.money -=money;flag=true;fwrite(&tempi,sizeof(struct user),1,fp);fclose(fp);free(temp);if(flag=false)printf(您輸入的密碼不正確!n);elseprintf(你取款業(yè)務已辦妥!n);void print()函數(shù)用于顯示菜單void print()/函數(shù)功能:輸出界面printf(%48sn,*活期儲蓄帳目管理系統(tǒng)*);printf(-nn);printf(%8s,%-20sn,1,新建儲戶);printf(%8s,%-20sn,2,查詢儲戶信息);printf(%8s,%-

19、20sn,3,顯示所有儲戶信息);printf(%8s,%-20sn,4,刪除儲戶);printf(%8s,%-20sn,5,存款);printf(%8s,%-20sn,6,取款);printf(%8s,%-20sn,7,退出);printf(n請選擇功能(17):);void main()函數(shù)用于實現(xiàn)菜單中的功能,主函數(shù)void main()char choose;doprint();scanf( %c,&choose);/讀取功能標號,根據(jù)標號選擇不同的函數(shù)fflush(stdin);system(cls);switch(choose)case 1:add();break;case 2:s

20、elect_id();break;case 3:display();break;case 4:del();break;case 5:save_money();break;case 6:get_money();break;case 7:exit(1);default:printf(對不起,你所選擇的功能不存在!n); getch();/暫停功能(讀取任意鍵繼續(xù))(conio.h) system(cls);/清除屏幕顯示(stdlib.h)while(1);五 調(diào)試分析 系統(tǒng)運行主界面如圖所示,各子功能測試運行結(jié)果如下: 每個方面實現(xiàn)一個功能。定義一個包含有五個變量的結(jié)構(gòu)體數(shù)組,并存入文件中。定義

21、一個計數(shù)函數(shù),貫穿整個程序。然后每個函數(shù)實現(xiàn)一個功能,共有六個功能。添加用戶時會使用到錄入姓名和錄入身份證號碼兩個函數(shù)。查詢只需要比較字符串,然后輸出即可實現(xiàn)。顯示全部儲戶信息只需將結(jié)構(gòu)體數(shù)組依次輸出即可實現(xiàn)。儲戶的存款和取款按找賬號依次從文件中查找到匹配的賬號,然后加上或減去存取的金額即可實現(xiàn)。銷戶時將儲戶除賬號外信息全部置0即可。六 測試結(jié)果1.主界面截圖 2.新建儲戶 3.查詢儲戶信息 4.顯示所有儲戶信息 5.存款 6.取款 7.刪除儲戶七 用戶使用說明 (1) 本程序執(zhí)行文件為”活期儲蓄.exe”. (2) 進入本系統(tǒng)后,隨即顯示系統(tǒng)主菜單頁面,用戶可在該界面下輸入各子菜單前對應的數(shù)

22、字并按回車鍵,執(zhí)行相應子菜單命令。 (3) 賬號或密碼輸入不正確時,會出現(xiàn)提示信息,然后按任意鍵退出。八 課程設(shè)計總結(jié)這次課程設(shè)計中遇到了一些問題與同學一起討論解決,從其他人身上學到了很多。 這個課程設(shè)計并不完美,還有很多要改善的地方,在刪除儲戶時不能將儲戶信息從文件中刪除,只能將儲戶信息全部置0了。還有一些沒想到的細節(jié)。雖然不是很完美,但發(fā)現(xiàn)不足之處并在以后的設(shè)計中注意這些細節(jié),對于將來的實踐還是很有幫助,我們可以不斷發(fā)現(xiàn)我們的不完美,并想辦法去改進這些不完美。通過這次課程設(shè)計學到了很多東西包括以前在課本上沒有學到的知識,還使我懂得了理論和時間結(jié)合是很重要的。讓我進一步了解了C+程序設(shè)計方法

23、,并且對這門課產(chǎn)生了濃厚的興趣。更重要的是培養(yǎng)了自己耐心、細心、用心的良好品質(zhì)。同時也非常感謝同學的幫助及老師的建議與指導。源程序:#include#include#include#include#define file temp.txt /數(shù)據(jù)儲存文件名struct user /用戶類型(賬號,姓名,身份證號,存款)int id;char name20;char person_num19;char password6;double money;void add() /添加用戶printf(%45sn,*新建儲戶*);printf(-nn);struct user getuser();stru

24、ct user temp;int count(); /函數(shù)目的:計算文件中的記錄數(shù)目 以生成自動賬號FILE *fp;int number;if(fp=fopen(file,ab)=NULL)printf(Can not open file!n);exit(1);temp=getuser(); /讀取用戶名number=count();temp.id=number+1; /生成自動賬號fwrite(&temp,sizeof(struct user),1,fp);printf(添加用戶成功!n);fclose(fp);int count() /函數(shù)目的:計算文件中的記錄總數(shù)FILE *fp;in

25、t num;struct user temp;num=0;if(fp=fopen(file,rb)=NULL)printf(Can not open file!n);exit(1);while(fread(&temp,sizeof(struct user),1,fp)num+;fclose(fp);return num;struct user getuser()void getname(char *name);void getperson_num(char *person_num);void getpassword(char *password);struct user temp;printf

26、(請輸入用戶姓名(字符數(shù)=100)doscanf(%lf,&temp.money);fflush(stdin);if(temp.money100.00)printf(開戶金額不能小于100n);elsebreak;printf(重新輸入開戶金額: );while(1);return temp;void getname(char *name) /函數(shù)功能:讀取用戶姓名(字數(shù)=20)printf(姓名不能超過20個字符!n);else break;printf(重新輸入姓名: ); /while循環(huán),直到姓名輸入有效while(1);void getperson_num(char *person_

27、num)doint i,mark;char ch;for(i=0,mark=0;i+)if(ch=getchar()!=n)if(ch=0)person_numi=ch;elseprintf(身份證號碼只能是數(shù)字!n);mark=1;break;elsebreak;person_numi=0;if(mark=1)continue;if(strlen(person_num)!=18)printf(身份證號碼只能是18位!n);elsebreak;printf(重新輸入身份證號碼: );while(1);void getpassword(char *password) do int i,j; ch

28、ar ch; for(i=0,j=0; i+) if(ch=getchar()!=n) if(ch=0) passwordi=ch; else printf(密碼只能是數(shù)字!n); j=1; break; else break; passwordi=0; if(j=1) continue; if(strlen(password)!=6) printf(密碼只能是6位!n); else break; printf(重新輸入密碼: ); while(1);void select_id() /查詢儲戶信息int count();void getpassword(char *password);pri

29、ntf(%45sn,*查詢儲戶信息*);printf(-n);printf(%s %15s %15s %15sn,編號,用戶姓名,身份證號碼,存款余額);printf(-nn);FILE *fp;struct user temp;int i,maxnum;char password8;bool flag=false;if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);maxnum=count();printf(輸入要查詢賬號:); scanf(%d,&i);if(imaxnum)printf(你要查詢的賬號不存在!);ret

30、urn;printf(輸入賬號密碼:);scanf(%s,&password);while(fread(&temp,sizeof(struct user),1,fp) /循環(huán)讀取每一條記錄 判斷是否為要查看的記錄if(temp.id=i&strcmp(temp.password,password)=0)printf(NO.%d %8s %25s %.2fn,temp.id,,temp.person_num,temp.money);flag=true;break;if(flag=false) /判斷密碼是否正確printf(您輸入的密碼不正確!n);return;fclose(

31、fp);void display() /顯示所有儲戶信息printf(%45sn,*顯示所有儲戶信息*);printf(-n);printf(%s %15s %15s %15sn,賬號,用戶姓名,身份證號碼,存款余額);printf(-n);FILE *fp;struct user temp;if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);while(fread(&temp,sizeof(struct user),1,fp)printf(NO.%d %10s %23s %.2fn,temp.id,,te

32、mp.person_num,temp.money);fclose(fp);void save_money() /函數(shù)功能:存款printf(%45sn,*用戶存款業(yè)務*);printf(-nn);int count();void getpassword(char *password);FILE *fp;int i,num,mark;bool flag=false;struct user *temp;char password6;num=count(); temp=(struct user *)malloc(num*sizeof(struct user); /根據(jù)記錄數(shù)申請空間if(fp=fop

33、en(file,rb)=NULL)printf(cannot open file!n);exit(1);for(i=0;inum;i+) /將文件內(nèi)容存入數(shù)組fread(&tempi,sizeof(struct user),1,fp);fclose(fp);printf(輸入要存款賬號:); /讀取存款賬號scanf(%d,&mark);if(inum)printf(你要查詢的賬號不存在!);return;printf(輸入賬號密碼: );scanf(%s,&password);if(fp=fopen(file,wb)=NULL) /寫方式打開文件,覆蓋原文件中的內(nèi)容printf(cannot

34、 open file!n);exit(1);for(i=0;inum;i+)if(tempi.id=mark&strcmp(tempi.password,password)=0)double money=0;printf(輸入要存入的金額:);scanf(%lf,&money);while(1)if(money=0)printf(只能為正數(shù)!n);money=0;printf(輸入要存入的金額:);scanf(%lf,&money);elsebreak;tempi.money +=money; flag=true;fwrite(&tempi,sizeof(struct user),1,fp);

35、 /修改該用戶的信息fclose(fp);free(temp);if(flag=false)printf(您輸入的密碼不正確!n);elseprintf(你存款業(yè)務已辦妥!n);void get_money() /函數(shù)功能:用戶取款printf(%45sn,*用戶取款業(yè)務*);printf(-nn);int count();FILE *fp;int i,num,mark;char password6;bool flag=false;struct user *temp;num=count();/根據(jù)記錄數(shù)申請空間temp=(struct user *)malloc(num*sizeof(stru

36、ct user);if(fp=fopen(file,rb)=NULL)printf(cannot open file!n);exit(1);for(i=0;inum;i+)/讀取文件內(nèi)容fread(&tempi,sizeof(struct user),1,fp);fclose(fp);printf(輸入要取款賬號:);scanf(%d,&mark);if(inum)printf(你要查詢的賬號不存在!);return;printf(輸入賬號密碼: );scanf(%s,&password);if(fp=fopen(file,wb)=NULL) /寫方式打開文件,覆蓋原文件中的內(nèi)容printf(cannot ope

溫馨提示

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

評論

0/150

提交評論