c語言圖書銷售系統(tǒng)(源代碼)--精選文檔_第1頁
c語言圖書銷售系統(tǒng)(源代碼)--精選文檔_第2頁
已閱讀5頁,還剩29頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、#include <stdio.h>#include <string.h>#include <malloc.h>#include <stdlib.h>#include <time.h>#include <conio.h>#define LEN sizeof(struct book)#define VLEN sizeof(struct vip)#define SLEN sizeof(struct sales)struct vip *vhead=NULL;struct vip *v1,*v2;struct sales *she

2、ad=NULL;struct sales *s1,*s2;int V,S;/*結(jié)構(gòu)體定義*/struct bookchar bnum 12;/*書號*/char bname 41;/*書名*/char author 20;/*作者*/float price;/*書價*/int acount;/*書存在本數(shù)*/struct book *next;struct salesfloat count;struct sales *snext;struct vipchar vnum12;char vname41;int level;float persum;float discount;struct vip

3、 *vnext;/*函數(shù)聲明*/void loadbook();/*自動讀入書庫信息*/void welcome();/*歡迎界面顯示*/void inputbook();/*增加書本信息*/void loadvip();void loadsales(); /*自動錄入銷售信息*/void daysales(); /*日銷售額*/void monthsales(); /*月銷售額*/void yearsales(); /*年銷售額*/void search();/*查詢書數(shù)量*/void search_by_bnum();/*通過書號查詢*/void search_by_bname();/*通

4、過書名查詢*/void search_by_author();/*通過作者查詢*/void buy();/*購買書籍*/void list();/*列出書庫信息*/void listvip();void listsales(); /*列出銷售信息*/void delet();/*刪除書目*/void delet_by_bnum();/*通過書號刪除*/void delet_by_bname();/*通過書名刪除*/void delet_by_author();/*通過作者刪除*/void save();/*保存記錄*/void redef();/*修改密碼*/void bover();/*顯示

5、已售完的書*/void buy_by_huiyuan(); /*會員買書*/void buy_by_feihuiyuan(); /*非會員買書*/void exit0();/*退出*/int menu();/*主菜單*/void print2();/*顯示查詢菜單*/void printdelete();/*顯示刪除菜單*/struct book *head=NULL,*head2=NULL;/*head和head2分別用于書庫的頭指針和已購書的頭指針*/struct book *p1,*p2,*p3,*p4,*p5,*p6;/*p1、p2、p3用于操作書庫圖書,p4、p5、p6用于操作已購書

6、*/int save_flag=0;/*圖書信息變動標志*/int buy_flag=0;/*買書時,是否調(diào)用過查詢功能標志*/int shan_flag=0;/*刪書時,是否調(diào)用過顯示已售完書功能標志*/int T=0;/*記錄導(dǎo)入的書本數(shù)*/char mima11="123456"/*初始密碼*/void bookmanage();void salesmanage(); /*銷售統(tǒng)計*/int main() /*主函數(shù)*/welcome();/*歡迎界面顯示*/loadbook();loadsales();loadvip();/*自動導(dǎo)入書庫信息*/while(1)sw

7、itch(menu()case 1:system("cls");bookmanage();break;case 2:system("cls");buy();break;case 3:system("cls");listvip();break;case 4:system("cls");salesmanage();break;case 5:system("cls");break;case 0:system("cls");exit0();break;default:printf(&

8、quot;n選擇錯誤,請按主菜單提示輸入您的正確選擇(08)n");printf("按任意鍵返回繼續(xù):");rewind(stdin);/*清空緩沖區(qū)*/getch();return 0;/*菜單*/int menu()int choice;system("cls"); /*系統(tǒng)清屏*/printf("n *主菜單*nn");printf("1.圖書管理nn"); printf("2.銷售管理nn");printf("3.會員管理nn");printf("

9、4.銷售額統(tǒng)計nn");printf("5.說明nn");printf("0.退出nnn");printf("請輸入您的選擇(08):");rewind(stdin);/*清空緩沖區(qū)*/scanf("%d",&choice);return choice;/*返回用戶的選擇*/void bookmanage() system("cls"); int choice1; do printf(" "); /*顯示菜單*/printf(" *圖書管理* &q

10、uot;); printf(" ");printf(" ");printf(" 功能選項: n");printf(" 1 : 圖書信息錄入 n");printf(" 2 : 圖書信息瀏覽 n");printf(" 3 : 圖書信息查詢 n");printf(" 4 : 圖書信息刪除 n");printf(" 5 : 圖書信息保存 n");printf(" 0 : 返回主界面 n");printf(" &qu

11、ot;);printf("t請選擇操作:"); scanf("%d", &choice1); switch (choice1) /*菜單選擇*/ case 1 : system("cls");inputbook();break; case 2 : system("cls");list(); break ; case 3 :system("cls");search(); break ; case 4 : system("cls");delet(); break ; ca

12、se 5 : system("cls");save(); break ; case 0 :system("cls");break; while (choice1!=0); printf("n");void welcome() /*歡迎界面顯示*/ system("cls");printf("nntt*歡迎使用圖書銷售管理系統(tǒng)*nn");void loadbook() /*開始導(dǎo)入書庫信息*/FILE *fp;struct book *p7;if(fp=fopen("0.txt"

13、;,"r")=NULL) /*打開文件*/printf("nn文件打開失敗或文件不存在n");printf("nn按回車鍵繼續(xù):");getchar();return;head=p3=p1=(struct book*)malloc(LEN); /*開辟一個新單元*/p1->next=NULL;p7=(struct book*)malloc(LEN); /*作為一個臨時存儲空間,避免讀取文件最后的回車符*/fscanf(fp,"%s %s %s %f %d",&p7->bnum,&p7-&

14、gt;bname,&p7->author,&p7->price,&p7->acount);while(!feof(fp)T+;*p1=*p7; /*文件沒結(jié)束就將p7中的信息給p1*/p2=(struct book*)malloc(LEN); /*繼續(xù)開辟一個新單元,直到文件讀完*/p1->next=p2;p3=p1;p1=p2;p1->next=NULL;fscanf(fp,"%s%s%s%f%d",&p7->bnum,&p7->bname,&p7->author,&p

15、7->price,&p7->acount);free(p2); /*釋放多申請的一個單元*/p3->next=NULL;printf("nnttt%d項圖書信息已經(jīng)由系統(tǒng)自動載入.nnttt",T);rewind(stdin);/*清空緩沖區(qū)*/if(fclose(fp)printf("文件關(guān)閉失敗!n");exit(0);void salesmanage() system("cls"); int choice4; do printf(" "); /*顯示菜單*/printf("

16、 *銷售統(tǒng)計* "); printf(" ");printf(" ");printf(" 功能選項: n");printf(" 1 : 日銷售額 n");printf(" 2 : 月銷售額 n");printf(" 3 : 年銷售額 n");printf(" 0 : 返回主界面 n");printf(" ");printf("t請選擇操作:"); scanf("%d", &cho

17、ice4); switch (choice4) /*菜單選擇*/ case 1 : system("cls");daysales();break; case 2 : system("cls");monthsales(); break ; case 3 :system("cls");yearsales(); break ; case 0 :system("cls");break; while (choice4!=0); printf("n");void loadsales() /*開始導(dǎo)入銷售信息

18、*/FILE *vfp;if(vfp=fopen("sales.txt","r")=NULL) /*打開文件*/printf("nnttt銷售數(shù)據(jù)文件打開失敗或文件不存在nn");return;shead=s2=s1=(struct sales*)malloc(VLEN);while(!feof(vfp)S+;fscanf(vfp,"%f ",&s2->count);s1=(struct sales*)malloc(VLEN); s2->snext=s1;s2=s1;s1=NULL;s2->

19、;snext=NULL;free(s2);printf("nnttt項銷售信息已經(jīng)由系統(tǒng)自動載入.nnnnttt",S);rewind(stdin);/*清空緩沖區(qū)*/if(fclose(vfp)printf("文件關(guān)閉失敗!n");exit(0);void daysales()void monthsales()void yearsales()void listsales()s2=shead;printf("nntt *當前銷售信息*n");printf("nn 銷售額 nn");while(s2->coun

20、t!=NULL)printf("%f",s2->count);s2=s2->snext;(s2->snext)=s2=NULL;printf("n");printf("銷售信息列出完畢,按回車鍵返回子菜單:");rewind(stdin);/*清空緩沖區(qū)*/getchar();system("cls"); void loadvip() /*開始導(dǎo)入會員信息*/FILE *vfp;if(vfp=fopen("1.txt","r")=NULL) /*打開文件*/

21、printf("nnvip數(shù)據(jù)文件打開失敗或文件不存在n");printf("nn按回車鍵繼續(xù):");getchar();return;vhead=v2=v1=(struct vip*)malloc(VLEN);while(!feof(vfp)V+;fscanf(vfp,"%s %s %d %f %f",&v2->vnum,&v2->vname,&v2->level,&v2->persum,&v2->discount);v1=(struct vip*)malloc(

22、VLEN); v2->vnext=v1;v2=v1;v1=NULL;v2->vnext=NULL;free(v2);printf("nnttt%d項會員信息已經(jīng)由系統(tǒng)自動載入.nnnnttt按任意鍵顯示主菜單:",V);rewind(stdin);/*清空緩沖區(qū)*/getchar();if(fclose(vfp)printf("文件關(guān)閉失敗!n");exit(0);void listvip()v2=vhead;if(v2=NULL|V=0)/*文件不存在或書庫中沒書*/printf("nnnntttt當前書庫沒書!");p

23、rintf("nntt按回車鍵返回:");rewind(stdin);/*清空緩沖區(qū)*/getchar();return;elseprintf("nntt *當前書庫信息*n");printf("nn會員號 姓名 等級 會員總消費 會員折扣nn");while(v2->discount!=NULL)printf("%-18s%-10s%-5d %-6.2f %-5fn",v2->vnum,v2->vname,v2->level,v2->persum,v2->discount);v

24、2=v2->vnext;printf("n");printf("會員信息列出完畢,按回車鍵返回子菜單:");rewind(stdin);/*清空緩沖區(qū)*/getchar();system("cls"); void buy() system("cls"); /*系統(tǒng)清屏*/ int choice1; do printf(" "); /*顯示菜單*/printf(" *銷售管理* "); printf(" ");printf(" ")

25、;printf(" 功能選項: n");printf(" 1 : 會員購買 n");printf(" 2 : 非會員購買 n");printf(" 0 : 返回主界面 n");printf(" ");printf("t請選擇操作:"); scanf("%d", &choice1); switch (choice1) /*菜單選擇*/ case 1 : system("cls");buy_by_huiyuan();break; c

26、ase 2 : system("cls");buy_by_feihuiyuan(); break ; case 0 :system("cls");break; while (choice1!=0); printf("n");void buy_by_huiyuan()/*會員買書*/ time_t timep;char vipnum6; struct tm *p; time(&timep); p = gmtime(&timep);char bnum11;char ch;int i=0;float sum=0;/*保存所購

27、買書的總費*/v1=vhead;printf("nnnnnnnnnnnttt請輸入會員號碼:");scanf("%s",vipnum);while(v1!=NULL)if(strcmp(vipnum,v1->vnum)=0)break;else v1=v1->vnext;if(v1=NULL)printf("對不起,你所輸入的會員號不存在");if(p1=NULL|T=0)/*文件不存在或書庫中沒書*/printf("nnnnnnnnnntttt當前書庫沒書!");printf("nntttt

28、按任意鍵返回:");rewind(stdin);/*清空緩沖區(qū)*/getch();return;p5=p4=head2=(struct book*)malloc(LEN);p4->next=NULL;system("cls");printf("nntt收費標準:一級會員打9折 二級會員打8折nnttt三級會員打7折 四級會員打6折 ");doprintf("nn請輸入所需購買的書的書號(圖書編號):");/*書號唯一*/rewind(stdin);/*清空緩沖區(qū)*/gets(bnum);p1=head;while(p1

29、!=NULL)if(strcmp(p1->bnum,bnum)=0)break;else p1=p1->next;if(p1=NULL)system("cls");printf("nnnnnnnnnnt 沒有找到該書信息,可能書號輸入有誤,是否再次輸入書號?nn");printf("nnttt Y.是 N.否");rewind(stdin);/*清空緩沖區(qū)*/ch=getchar();if(ch='y'|ch='Y')system("cls");buy_flag=1;/*

30、防止在此函數(shù)中調(diào)用時,search()函數(shù)執(zhí)行了清屏*/search();/*調(diào)用查詢,通過其他途徑確定書號*/while(1)printf("nnttt提示:若沒有您要找的書,可按0結(jié)束!");printf("nntttt請重新輸入書號:");rewind(stdin);/*清空緩沖區(qū)*/gets(bnum);if(strcmp(bnum,"0")=0) break;/*沒有需要的書,結(jié)束輸入書號*/p1=head;while(p1!=NULL)if(strcmp(p1->bnum,bnum)=0) break;else p1

31、=p1->next;if(p1!=NULL) break;system("cls");if(p1!=NULL) if(p1->acount=0) printf("nntttt該書已售完!");while(p1!=NULL)if(strcmp(p1->bnum,bnum)=0)/*有相同書號,循環(huán)提前結(jié)束*/break;else p1=p1->next;if(p1!=NULL&&p1->acount!=0)*p4=*p1;sum=sum+p4->price;p5=(struct book*)malloc(

32、LEN);p4->next=p5;p6=p4;p4=p5;p4->next=NULL;i+;/*記錄買的本數(shù)i,*/p1->acount=p1->acount-1;/*減去售過的書(本數(shù))*/p4=head2;system("cls");printf("nnt*當前已選購書狀態(tài)*");printf("nn書號 書名作者 售價 數(shù)量 總費nn");while(p4->next!=NULL)/*顯示已買過的書*/printf("%-15s%-25s%-15s %.2f %d %.2fn",

33、p4->bnum,p4->bname,p4->author,p4->price,p4->acount,sum);p4=p4->next;printf("nntt 提示:可按N結(jié)束購書,按任意鍵繼續(xù)購書:");rewind(stdin);/*清空緩沖區(qū)*/ch=getchar();system("cls");while(ch!='n'&&ch!='N');/*結(jié)束購書*/free(p4);p5->next=NULL;if(head2->next=NULL) pr

34、intf("nnnnnnnnnntttt您當前沒有購書!nn");elseprintf("nnnnnnnnnnttt 確認購買這%d本書嗎?n",i);printf("nnttt 按任意鍵確認,按N撤銷購書:");/*不想購買時,亦可撤銷*/rewind(stdin);/*清空緩沖區(qū)*/ch=getchar();if(ch='n'|ch='N')for(p4=head2;p4!=NULL;p4=p4->next)for(p1=head;p1!=NULL;p1=p1->next)if(strc

35、mp(p1->bnum,p4->bnum)=0)p1->acount=p1->acount+1; /*書未銷售,本數(shù)加上*/printf("nntttt 撤銷完畢!");elseprintf("nnttt您所購買的書的總費(打折前)為%.2fnn",sum);printf("nnttt你的會員等級為%d級,可以享受%.1f折.nn",v1->level,(v1->discount)*10);printf("購買書本的折后價為%.2f.nn",(v1->discount)*s

36、um);save_flag=1;/*書庫信息變動標志*/printf("%d.%d.%dn", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday);rewind(stdin);/*清空緩沖區(qū)*/printf("nnttt 按回車鍵返回主菜單");getchar();void buy_by_feihuiyuan()/*非會員買書*/char bnum11;char ch;int i=0;float sum=0;/*保存所購買書的總費*/p1=head;if(p1=NULL|T=0)/*文件不存在或書

37、庫中沒書*/printf("nnnnnnnnnntttt當前書庫沒書!");printf("nntttt按任意鍵返回:");rewind(stdin);/*清空緩沖區(qū)*/getch();return;p5=p4=head2=(struct book*)malloc(LEN);p4->next=NULL;doprintf("nn請輸入所需購買的書的書號(圖書編號):");/*書號唯一*/rewind(stdin);/*清空緩沖區(qū)*/gets(bnum);p1=head;while(p1!=NULL)if(strcmp(p1->

38、;bnum,bnum)=0)break;else p1=p1->next;if(p1=NULL)system("cls");printf("nnnnnnnnnnt 沒有找到該書信息,可能書號輸入有誤,是否再次輸入書號?nn");printf("nnttt Y.是 N.否");rewind(stdin);/*清空緩沖區(qū)*/ch=getchar();if(ch='y'|ch='Y')system("cls");buy_flag=1;/*防止在此函數(shù)中調(diào)用時,search()函數(shù)執(zhí)行

39、了清屏*/search();/*調(diào)用查詢,通過其他途徑確定書號*/while(1)printf("nnttt提示:若沒有您要找的書,可按0結(jié)束!");printf("nntttt請重新輸入書號:");rewind(stdin);/*清空緩沖區(qū)*/gets(bnum);if(strcmp(bnum,"0")=0) break;/*沒有需要的書,結(jié)束輸入書號*/p1=head;while(p1!=NULL)if(strcmp(p1->bnum,bnum)=0) break;else p1=p1->next;if(p1!=NUL

40、L) break;system("cls");if(p1!=NULL) if(p1->acount=0) printf("nntttt該書已售完!");while(p1!=NULL)if(strcmp(p1->bnum,bnum)=0)/*有相同書號,循環(huán)提前結(jié)束*/break;else p1=p1->next;if(p1!=NULL&&p1->acount!=0)*p4=*p1;sum=sum+p4->price;p5=(struct book*)malloc(LEN);p4->next=p5;p6=

41、p4;p4=p5;p4->next=NULL;i+;/*記錄買的本數(shù)i,*/p1->acount=p1->acount-1;/*減去售過的書(本數(shù))*/p4=head2;system("cls");printf("nnt*當前已選購書狀態(tài)*");printf("nn書號 書名作者 售價 數(shù)量 總費nn");while(p4->next!=NULL)/*顯示已買過的書*/printf("%-15s%-25s%-15s %.2f %d %.2fn",p4->bnum,p4->bnam

42、e,p4->author,p4->price,p4->acount,sum);p4=p4->next;printf("nntt 提示:可按N結(jié)束購書,按任意鍵繼續(xù)購書:");rewind(stdin);/*清空緩沖區(qū)*/ch=getchar();system("cls");while(ch!='n'&&ch!='N');/*結(jié)束購書*/free(p4);p5->next=NULL;if(head2->next=NULL) printf("nnnnnnnnnntt

43、tt您當前沒有購書!nn");elseprintf("nnnnnnnnnnttt 確認購買這%d本書嗎?n",i);printf("nnttt 按任意鍵確認,按N撤銷購書:");/*不想購買時,亦可撤銷*/rewind(stdin);/*清空緩沖區(qū)*/ch=getchar();if(ch='n'|ch='N')for(p4=head2;p4!=NULL;p4=p4->next)for(p1=head;p1!=NULL;p1=p1->next)if(strcmp(p1->bnum,p4->b

44、num)=0)p1->acount=p1->acount+1;/*書未銷售,本數(shù)加上*/printf("nntttt 撤銷完畢!");elseprintf("nnttt您所購買的書的總費為%.2fnn",sum);save_flag=1;/*書庫信息變動標志*/rewind(stdin);/*清空緩沖區(qū)*/printf("nnttt 按回車鍵返回主菜單");getchar();void search()/*查詢書庫信息*/int choice;p1=head;if(p1=NULL|T=0)/*文件不存在或書庫中沒書*/pr

45、intf("nnnntttt當前書庫沒書!");printf("nntt按任意鍵返回:");rewind(stdin);/*清空緩沖區(qū)*/getch();system("cls");return;while(1)printf("n *查詢方式*nn");printf("1.通過書號查找nn");printf("2.通過書名查找nn");printf("3.通過作者查找nn");printf("0.退出圖書查詢nn");printf(&q

46、uot;nn請選擇一種查詢方式(03):");rewind(stdin);/*清空緩沖區(qū)*/scanf("%d",&choice);while(choice<0|choice>3)system("cls");print2();/*調(diào)用顯示查詢方式菜單*/printf("nttt輸入錯誤!nn");printf("ttt請重新輸入:");rewind(stdin);/*清空緩沖區(qū)*/scanf("%d",&choice);switch(choice)case 1:system("cls");search_by_bnum();break;case 2:system("cls");search_by_bname()

溫馨提示

  • 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論