c語言課程設(shè)計(jì)報(bào)告會(huì)員卡計(jì)費(fèi)系統(tǒng)源代碼_第1頁
c語言課程設(shè)計(jì)報(bào)告會(huì)員卡計(jì)費(fèi)系統(tǒng)源代碼_第2頁
c語言課程設(shè)計(jì)報(bào)告會(huì)員卡計(jì)費(fèi)系統(tǒng)源代碼_第3頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、#i nclude /編譯預(yù)處理指令,引入頭文件#i nclude #in elude #in elude #defi ne MAX 10/#defi ne MENU_MAIN_COUNT 7 typedef struct member/char nameMAX;/char idMAX;/char sex2;/int age;float mon ey;char tel12;/struct member *n ext;/float cost;mem;/*void men u();/*void save(mem *p);/mem *head=NULL;/mem*get_last(mem *p)/指

2、針if(p- next = NULL)自定義符號(hào)常量/主菜單的選項(xiàng)個(gè)數(shù)定義結(jié)構(gòu)體類型member;采用鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)姓名卡號(hào)性別/年齡/余額電話 定義一個(gè)指針指向下一個(gè)會(huì)員信息/消費(fèi)金額定義結(jié)構(gòu)體變量 mem聲明函數(shù)*/聲明函數(shù),聲明菜單函數(shù) */聲明保存函數(shù)頭指針為NULL取得鏈表最后一個(gè)元素的節(jié)點(diǎn)指針并返回該return p;elseget_last(p- next);void creat_member(mem *pNew)會(huì)員登記函數(shù)的會(huì)員char s;printf( 卡號(hào):);入卡號(hào)/scan f(%s,pNew-id);/輸入信息操作,創(chuàng)建一個(gè)新運(yùn)用指針輸printf(”請(qǐng)輸入姓名:”

3、);scanf(%s,pNew-name); /運(yùn)用指針輸入姓名a:printf(請(qǐng)輸入性別(f-女m-男):);getchar();/輸入男女s = getchar();if(s=f|s=m)/判斷是男是女if (s = f | s = F) strcpy(pNew-sex,女);if (s = M | s = m) strcpy(pNew-sex,男);else/如果輸入錯(cuò)誤printf(輸入錯(cuò)誤,請(qǐng)重新輸入.n);goto a;/跳轉(zhuǎn)至 a,重新輸入iprintf(請(qǐng)輸入年齡:);scan f(%d, &(pNew-age); /運(yùn)用指針輸入年齡printf(請(qǐng)輸入繳費(fèi)金額:”);sca

4、n f(%f,&(pNew-mo ney); /運(yùn)用指針輸入余額printf(請(qǐng)輸入電話:);scan f(%s,pNew-tel);/運(yùn)用指針輸入電話pNew-cost=0;/運(yùn)用指針初始化消費(fèi)額為0printf(n創(chuàng)建完畢!n);會(huì)員登記添加會(huì)員按mem動(dòng)調(diào)用會(huì)員void n ewMember()/函數(shù) /信息char con=N;mem *pLast= NULL;mem *pNew=(mem *)malloc(sizeof(mem);/態(tài)分配內(nèi)存pNew- next=NULL;creat_member(pNew);/登記函數(shù)if(head = NULL)head = pNew;elsep

5、Last = get_last(head); pLast- next = pNew;printf(繼續(xù)輸入會(huì)員信息?(Y繼續(xù),N返回菜單);/判斷是否繼續(xù)登記getchar();con = getchar();if (con = n | con = N)save(pNew);menu();elsesave(pNew); n ewMember();/顯示信息操作void table_head()/定義表頭電話printf(|卡號(hào) |姓名|性別|年齡| 余額 |累計(jì)消費(fèi)|n);printf(+n) /定義底線定義中間void table_buttom()void table_row(mem *p)

6、 /部分prin tf(|%10s|%6s|%6s|%6d|%8.2f|%8.2f|%11s|n,p-id,p-n ame,p-sex,p-age,p- mon ey,p-cost,p-tel);void display(mem *p)p = head; table_head();/while(p != NULL)table_row(p); p = p_n ext; table_buttom();/顯示所有信息調(diào)用表頭調(diào)用中間部分調(diào)用底線void display_ on e(mem *p) / table_head(); table_row(p); table_buttom();只顯示一條信息

7、void table_sum()/定義總計(jì)printf(|III丨總計(jì)I 總計(jì) I|n);printf(+n)void table_r(float mon ey,float cost)/定義總計(jì)2prin tf(|III|n ”,m on ey,cost);%8.2f%8.2fIvoid save(mem *p)/保存函數(shù)FILE *fp;/定義一個(gè)指向文件的指針變量fp=fope n(member.dat, a);/將 fopen函數(shù)的返回值賦給指針變量 fp息函數(shù)/p = head;table_head();/while(p != NULL)table_row(p);/分p = p_n e

8、xt;p=head;table_sum();/table_r( mon ey,cost);/table_buttom();/作void display_statistics(mem *p,float money,float cost)顯示統(tǒng)計(jì)信調(diào)用表頭定義中間部定義總計(jì)定義總計(jì)2定義表尾 文件相關(guān)操while(p != NULL)fprintf(fp,%s %s %s %d %f %s %dn,p-id,p_name, p-sex, p-age,p- mon ey, p-tel,p-cost);p = p_n ext;fclose(fp);/關(guān)閉指針getchar();void modify_

9、file(mem *p)保存修改 / 會(huì)員信息函數(shù)FILE *fp;p= head;if(fp=fopen(member.dat, w)=NULL)/檢查打開文件的操作是否有錯(cuò)printf(文件不存在);getchar();menu();/調(diào)用菜單函數(shù)while(p != NULL)fprintf(fp,%s %s %s %d %f %s %fn,p-id,p-name, p-sex, p-age,p- mon ey, p_tel,p_cost);p = p_n ext;fclose(fp);getchar(); void load(mem *p) /FILE *fp;mem *pLast =

10、 NULL;head=NULL;if(fp=fope n(member.dat,r)=NULL) /操作是否有錯(cuò)prin tf(沒有會(huì)員信息,請(qǐng)錄入!);getch();menu();/ while(!feof(fp) /達(dá)末尾mem *pNew = (mem *)malloc(sizeof(mem);/內(nèi)存pNew- next = NULL;fscanf(fp, %s %s %s %d %f %s %fn,從文件加載信息檢查打開文件的調(diào)用菜單函數(shù)文件指針是否到按mem動(dòng)態(tài)分配pNew-id, pNew-name, pNew-sex, &(pNew-age), &(pNew-money),pN

11、ew-tel,&(pNew-cost); if(head = NULL) head = pNew;elsepLast = get_last(head); pLast-n ext = pNew;p = head;fclose(fp);/數(shù)mem* search_id(mem *p) /char idMAX;int i=0;p = head;scan f(%s,id);while(p&(strcmp(id, n)!=0) / if(strcmp(p-id,id)=0) /i=1; break;elsep=p-n ext;if(strcmp(id, n)=0) menu();if(p=NULL) /

12、 printf(您查找的卡號(hào)不存在,請(qǐng)重新輸入p=search_id(p);/elsereturn p;/通過卡號(hào)搜索信息函通過卡號(hào)搜索信息判斷id是否不為n找到/輸入n時(shí)返回菜單重新搜索卡號(hào)n);調(diào)用尋找函數(shù)返回p修改會(huì)員信息操作*/*void modify_m()/修改會(huì)員的信息char s,fu n=y:char pro=|n| 1 姓名n| 2 性別n| 3 年齡n| 4 電話n| 5 返回n|n;mem *p;load(p);display(p);/printf(”請(qǐng)輸入需要修改信息的會(huì)員卡號(hào)(p=search_id(p);/while(fu n=y|fu n=Y) / system

13、(cls);/display_ on e(p);printf( 請(qǐng)選擇修改的項(xiàng)目: prin tf(pro);/getchar();scan f(%c,&fun); switch(fu n) / case 1:prin tf(sca nf(%s,p-n ame);break;case 2:a:printf(/n);請(qǐng)輸入姓名請(qǐng)輸入性別調(diào)用顯示函數(shù)n返回菜單):”);調(diào)用按號(hào)尋找函數(shù)當(dāng)繼續(xù)尋找時(shí)清屏調(diào)用顯示一條函數(shù)輸出pro用switch語句選擇修改內(nèi)容:);(f-女 m-男):);getchar();s = getchar(); if(s=f|s=m) if (s = f | s = F) s

14、trcpy(p-sex,女);if (s = M | s = m) strcpy(p-sex,男);elseprin tf(輸入錯(cuò)誤,請(qǐng)重新輸入.n);goto a;break;case 3:printf(請(qǐng)輸入年齡:”);scan f(%d,&(p-age);break;case 4:printf(請(qǐng)輸入電話:”);default :break;prin tf(是否繼續(xù)修改 Y/N?);getchar();fun=getchar();modify_file(p);/數(shù)system(cls);/display_ on e(p);/prin tf(n修改成功,按任意鍵繼續(xù)!getchar();m

15、enu();/scan f(%s,p-tel); break;/判斷是否繼續(xù)尋找調(diào)用保存修改會(huì)員信息函清屏調(diào)用顯示一條函數(shù)調(diào)用菜單函數(shù)會(huì)員續(xù)費(fèi)函數(shù)void add() /float mon ey;mem *p;load(p);display(p);/prin tf(n);printf(”請(qǐng)輸入需要續(xù)費(fèi)的會(huì)員卡號(hào)(n返回菜單):”);會(huì)員續(xù)費(fèi)調(diào)用瀏覽函數(shù)p=search_id(p);/system(cls);/display_ on e(p);/printf(請(qǐng)輸入續(xù)費(fèi)金額:);scan f(%f, &mo ney);p- mon ey+=mon ey;/modify_file(p);/息函數(shù)s

16、ystem(cls);/display_ on e(p);/printf(”續(xù)費(fèi)成功,任意鍵繼續(xù)r?;getchar();menu();/調(diào)用按號(hào)尋找函數(shù)清屏調(diào)用顯示一條函數(shù)續(xù)費(fèi)調(diào)用保存修改會(huì)員信清屏調(diào)用顯示一條函數(shù)調(diào)用菜單函數(shù)/會(huì)員結(jié)算函數(shù)void con sume()mem *p;/會(huì)員結(jié)算float cost; load(p); display(p);/*調(diào)用瀏覽函數(shù)*/prin tf(n);prin tf(請(qǐng)輸入需要結(jié)算的會(huì)員卡-號(hào)(n返回采單):”);p=search_id(p);/調(diào)用按號(hào)尋找函數(shù)system(cls);/清屏display_ on e(p);/調(diào)用顯示一條函數(shù)pr

17、intf(請(qǐng)輸入花費(fèi)金額:);scan f(%f, &cost);if(p-cost=1000)/判斷是否升級(jí)為vipprintf(恭喜您已經(jīng)升級(jí)為VIP,本次消費(fèi)9折優(yōu)惠。n ”);printf(本次實(shí)際消費(fèi)%.2f元! ,cost*0.9);/升級(jí)為vip,消費(fèi)打9折cost*=0.9;if(p- mon ey-cost)cost+=cost;p- mon ey-=cost;/消費(fèi)getchar();elseif(p- mon ey-cost)cost+=cost;p- mon ey-=cost;modify_file(p);/息函數(shù)printf(結(jié)算成功,任意鍵繼續(xù)!”);getch()

18、;menu();/*system(cls);/display, on e(p);/void delete_m() /mem *p,*q=head,*thelast;float mon ey;load(p);display(p);/*prin tf(n);printf(”請(qǐng)輸入需要?jiǎng)h除的會(huì)員卡號(hào)(n返回菜單):”);p=search_id(p);/thelast=head;if(p=head) /head=p-n ext;mon ey=p- mon ey;free(p);elsewhile(thelast)if(thelast- next=p)break;elsethelast=thelast-

19、 n ext;thelast- n ext=p-n ext;mon ey=p- mon ey;free(p);modify_file(q);/調(diào)用保存修改會(huì)員信清屏調(diào)用顯示一條函數(shù)調(diào)用菜單函數(shù)會(huì)員退出函數(shù)*/刪除會(huì)員信息調(diào)用瀏覽函數(shù)*/調(diào)用按號(hào)尋找函數(shù)判斷指針調(diào)用保存函數(shù)printf( 退回余額 .2f 元! n”,money);printf(”刪除成功,按任意鍵繼續(xù)?。?/顯示退回的余額getch();menu();/調(diào)用菜單函數(shù) /*統(tǒng)計(jì)函數(shù)*/mem *sort_m() /mem *q,*tail,*p=(mem*)malloc(sizeof(mem);p-n ext=head;head

20、=p;tail=NULL;/while(tail!=head- next)p=head;q=p-n ext;while(q- next!=tail) /為空if(p-n ext- mon ey q-n ext- mon ey)p-n ext=q-n ext;/序q-n ext=q-n ext-n ext;p_n ext-n ext=q;p=p-n ext;q=p-n ext;tail=q;head=head-n ext;按繳費(fèi)總額排序定義tail判斷q是否比較大小,排free(p);retur n head;/返回值mem* sort_c()序/按消費(fèi)金額排mem *q,*tail,*p=(m

21、em*)malloc(sizeof(mem); p-n ext=head;head=p;tail=NULL;/定義tail返回值比較大小,排while(tail!=head- next)p=head;q=p-n ext;while(q- next!=tail)if(p-n ext-costq-n ext-cost) /序p_n ext=q _n ext;q-n ext=q-n ext-n ext;p_n ext-n ext=q;p=p-n ext;q=p-n ext;tail=q;head=head-n ext;free(p);return head;/float summ(mem *p) f

22、loat summ=0; p=head; while(p)/計(jì)算繳費(fèi)總額循環(huán),實(shí)現(xiàn)求總額summ+=p- money; p=p-n ext;return summ;/返回總額float sumc(mem *p) /float sumc=0;p=head;while(p) /計(jì)算消費(fèi)總額循環(huán),實(shí)現(xiàn)求總額sumc+=p-cost; p=p-n ext;return sumc;/返回總額void statistics。 int f=0; mem *p; load(p);/統(tǒng)計(jì)會(huì)員信息函數(shù)system(cls);prin tf(tt=ntt|ntt|1按繳費(fèi)總額排序ntt|2按消費(fèi)總額排序ntt|3返

23、回菜單ntt|ntt=n);prin tf( 請(qǐng)選擇功能:);scan f(%d,&f);switch(f) /case 1: p=sort_m(p);/display_statistics(p,summ(p),sumc(p); getch();menu();用switch語句選擇功能調(diào)用按繳費(fèi)總額排序/調(diào)用函數(shù)break;case 2: p=sort_c(p);/display_statistics(p,summ(p),sumc(p); /調(diào)用按消費(fèi)總額排序 調(diào)用函數(shù)getch();menu( );break; default : menu ();break;/*退出系統(tǒng)操作*/void clear(mem *p)/釋放鏈表空間void quit()clear(head

溫馨提示

  • 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)論