


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quá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)自定義符號常量/主菜單的選項個數(shù)定義結(jié)構(gòu)體類型member;采用鏈式存儲結(jié)構(gòu)姓名卡號性別/年齡/余額電話 定義一個指針指向下一個會員信息/消費金額定義結(jié)構(gòu)體變量 mem聲明函數(shù)*/聲明函數(shù),聲明菜單函數(shù) */聲明保存函數(shù)頭指針為NULL取得鏈表最后一個元素的節(jié)點指針并返回該return p;elseget_last(p- next);void creat_member(mem *pNew)會員登記函數(shù)的會員char s;printf( 卡號:);入卡號/scan f(%s,pNew-id);/輸入信息操作,創(chuàng)建一個新運用指針輸printf(”請輸入姓名:”
3、);scanf(%s,pNew-name); /運用指針輸入姓名a:printf(請輸入性別(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/如果輸入錯誤printf(輸入錯誤,請重新輸入.n);goto a;/跳轉(zhuǎn)至 a,重新輸入iprintf(請輸入年齡:);scan f(%d, &(pNew-age); /運用指針輸入年齡printf(請輸入繳費金額:”);sca
4、n f(%f,&(pNew-mo ney); /運用指針輸入余額printf(請輸入電話:);scan f(%s,pNew-tel);/運用指針輸入電話pNew-cost=0;/運用指針初始化消費額為0printf(n創(chuàng)建完畢!n);會員登記添加會員按mem動調(diào)用會員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ù)輸入會員信息?(Y繼續(xù),N返回菜單);/判斷是否繼續(xù)登記getchar();con = getchar();if (con = n | con = N)save(pNew);menu();elsesave(pNew); n ewMember();/顯示信息操作void table_head()/定義表頭電話printf(|卡號 |姓名|性別|年齡| 余額 |累計消費|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()/定義總計printf(|III丨總計I 總計 I|n);printf(+n)void table_r(float mon ey,float cost)/定義總計2prin tf(|III|n ”,m on ey,cost);%8.2f%8.2fIvoid save(mem *p)/保存函數(shù)FILE *fp;/定義一個指向文件的指針變量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)計信調(diào)用表頭定義中間部定義總計定義總計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)保存修改 / 會員信息函數(shù)FILE *fp;p= head;if(fp=fopen(member.dat, w)=NULL)/檢查打開文件的操作是否有錯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) /操作是否有錯prin tf(沒有會員信息,請錄入!);getch();menu();/ while(!feof(fp) /達末尾mem *pNew = (mem *)malloc(sizeof(mem);/內(nèi)存pNew- next = NULL;fscanf(fp, %s %s %s %d %f %s %fn,從文件加載信息檢查打開文件的調(diào)用菜單函數(shù)文件指針是否到按mem動態(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(您查找的卡號不存在,請重新輸入p=search_id(p);/elsereturn p;/通過卡號搜索信息函通過卡號搜索信息判斷id是否不為n找到/輸入n時返回菜單重新搜索卡號n);調(diào)用尋找函數(shù)返回p修改會員信息操作*/*void modify_m()/修改會員的信息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(”請輸入需要修改信息的會員卡號(p=search_id(p);/while(fu n=y|fu n=Y) / system
13、(cls);/display_ on e(p);printf( 請選擇修改的項目: 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);請輸入姓名請輸入性別調(diào)用顯示函數(shù)n返回菜單):”);調(diào)用按號尋找函數(shù)當繼續(xù)尋找時清屏調(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(輸入錯誤,請重新輸入.n);goto a;break;case 3:printf(請輸入年齡:”);scan f(%d,&(p-age);break;case 4:printf(請輸入電話:”);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)用保存修改會員信息函清屏調(diào)用顯示一條函數(shù)調(diào)用菜單函數(shù)會員續(xù)費函數(shù)void add() /float mon ey;mem *p;load(p);display(p);/prin tf(n);printf(”請輸入需要續(xù)費的會員卡號(n返回菜單):”);會員續(xù)費調(diào)用瀏覽函數(shù)p=search_id(p);/system(cls);/display_ on e(p);/printf(請輸入續(xù)費金額:);scan f(%f, &mo ney);p- mon ey+=mon ey;/modify_file(p);/息函數(shù)s
16、ystem(cls);/display_ on e(p);/printf(”續(xù)費成功,任意鍵繼續(xù)r?;getchar();menu();/調(diào)用按號尋找函數(shù)清屏調(diào)用顯示一條函數(shù)續(xù)費調(diào)用保存修改會員信清屏調(diào)用顯示一條函數(shù)調(diào)用菜單函數(shù)/會員結(jié)算函數(shù)void con sume()mem *p;/會員結(jié)算float cost; load(p); display(p);/*調(diào)用瀏覽函數(shù)*/prin tf(n);prin tf(請輸入需要結(jié)算的會員卡-號(n返回采單):”);p=search_id(p);/調(diào)用按號尋找函數(shù)system(cls);/清屏display_ on e(p);/調(diào)用顯示一條函數(shù)pr
17、intf(請輸入花費金額:);scan f(%f, &cost);if(p-cost=1000)/判斷是否升級為vipprintf(恭喜您已經(jīng)升級為VIP,本次消費9折優(yōu)惠。n ”);printf(本次實際消費%.2f元! ,cost*0.9);/升級為vip,消費打9折cost*=0.9;if(p- mon ey-cost)cost+=cost;p- mon ey-=cost;/消費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(”請輸入需要刪除的會員卡號(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)用保存修改會員信清屏調(diào)用顯示一條函數(shù)調(diào)用菜單函數(shù)會員退出函數(shù)*/刪除會員信息調(diào)用瀏覽函數(shù)*/調(diào)用按號尋找函數(shù)判斷指針調(diào)用保存函數(shù)printf( 退回余額 .2f 元! n”,money);printf(”刪除成功,按任意鍵繼續(xù)!);/顯示退回的余額getch();menu();/調(diào)用菜單函數(shù) /*統(tǒng)計函數(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;按繳費總額排序定義tail判斷q是否比較大小,排free(p);retur n head;/返回值mem* sort_c()序/按消費金額排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)/計算繳費總額循環(huán),實現(xiàn)求總額summ+=p- money; p=p-n ext;return summ;/返回總額float sumc(mem *p) /float sumc=0;p=head;while(p) /計算消費總額循環(huán),實現(xiàn)求總額sumc+=p-cost; p=p-n ext;return sumc;/返回總額void statistics。 int f=0; mem *p; load(p);/統(tǒng)計會員信息函數(shù)system(cls);prin tf(tt=ntt|ntt|1按繳費總額排序ntt|2按消費總額排序ntt|3返
23、回菜單ntt|ntt=n);prin tf( 請選擇功能:);scan f(%d,&f);switch(f) /case 1: p=sort_m(p);/display_statistics(p,summ(p),sumc(p); getch();menu();用switch語句選擇功能調(diào)用按繳費總額排序/調(diào)用函數(shù)break;case 2: p=sort_c(p);/display_statistics(p,summ(p),sumc(p); /調(diào)用按消費總額排序 調(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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 紡紗工藝參數(shù)優(yōu)化與調(diào)整考核試卷
- 幼兒園活動設(shè)計要點
- 自行車配件市場供需分析考核試卷
- 網(wǎng)絡(luò)安全風險識別與防范考核試卷
- 《卓越發(fā)展》:課件展示
- 刀具的設(shè)計與性能評估方法考核試卷
- 電力設(shè)備中低壓配電柜設(shè)計與選型考核試卷
- 收藏品市場調(diào)研報告撰寫技巧考核試卷
- 航運企業(yè)競爭力評價考核試卷
- 節(jié)能環(huán)保與健康城市考核試卷
- 《肺結(jié)核的診斷與治療》課件
- 陜西省咸陽市2025屆高三下學(xué)期高考模擬檢測(三)物理試題(含答案)
- 浙江省溫州市2023-2024學(xué)年高一下學(xué)期期末考試語文試卷(含答案)
- (高清版)DB3301∕T 0411-2023 公共汽電車維修車間建設(shè)與管理規(guī)范
- 激光應(yīng)用技術(shù)發(fā)展路徑試題及答案
- 期權(quán)開戶考試題及答案
- 國家職業(yè)技能標準-(糧油)倉儲管理員
- 無人駕駛技術(shù)在旅游景區(qū)的自動駕駛巴士的創(chuàng)新實踐
- 人教版八下道德與法治教學(xué)設(shè)計:2.2加強憲法監(jiān)督
- 血透患者的血壓管理
- 《自動化生產(chǎn)線集成與應(yīng)用- Integration》課件-項目一 自動化生產(chǎn)線概述
評論
0/150
提交評論