商品銷售管理系統(tǒng)設(shè)計_第1頁
商品銷售管理系統(tǒng)設(shè)計_第2頁
商品銷售管理系統(tǒng)設(shè)計_第3頁
商品銷售管理系統(tǒng)設(shè)計_第4頁
商品銷售管理系統(tǒng)設(shè)計_第5頁
已閱讀5頁,還剩99頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、104/104、商品銷售治理問題描述:已知一公司有10種產(chǎn)品(產(chǎn)品編號,產(chǎn)品名稱,產(chǎn)品價格,產(chǎn)品產(chǎn)地,庫存數(shù)量(最開始為1000個),設(shè)計一程序,完成以下功能:1)銷售:從鍵盤輸入顧客姓名,銷售數(shù)量、銷售日期,實現(xiàn)銷售功能。需要推斷產(chǎn)品是否存在,銷售數(shù)量是否小于庫存數(shù)量,銷售日期格式是否合法(格式為:YYYY-MM-DD,如2009-01-02)2)能依照產(chǎn)品編號查詢產(chǎn)品的銷售歷史3)計算時刻段內(nèi)各個產(chǎn)品的銷售總額4)能依照顧客姓名,查詢購買歷史5)能顯示所有顧客的姓名提示:定義一個日期結(jié)構(gòu)體保存日期,具體信息為:年、月、日推斷存款日期和取款日期的格式是否合法時,需要推斷長度是否為10,第5位

2、和第8位是否為-,字符,將1-4位表示的年份,6-7位表示的月份,9-10位表示的日期分不轉(zhuǎn)換成整數(shù)。推斷是否滿足構(gòu)成日期的條件閏年月份只能是1-12之間的數(shù),假如是閏年,二月能夠是29天否則不能大于28,1,3,5,7,8,10,12月能夠是31天,其余只能小于等于30(建議寫成函數(shù))。定義一個結(jié)構(gòu)體數(shù)組保存10種產(chǎn)品信息,具體信息為:產(chǎn)品編號,產(chǎn)品名稱,產(chǎn)品價格,產(chǎn)品產(chǎn)地,庫存數(shù)量(最開始為1000個)定義一個鏈表,保存銷售信息,具體為:顧客代碼,銷售數(shù)量、銷售日期。定義一個鏈表保存顧客信息,具體為:顧客代碼,顧客姓名當輸入銷售信息時查詢顧客鏈表,假如在鏈表中存在該姓名的顧客記錄,則將其代

3、碼在該銷售鏈表中插入一條記錄,假如不存在,則在顧客鏈表中插入一條記錄,(顧客代碼需要自動生成)。 #include stdio.h /*I/O函數(shù)*/#include stdlib.h /*標準庫函數(shù)*/#include string.h/*字符串函數(shù)*/#include ctype.h /*字符操作函數(shù)*/#include time.h /*時鐘函數(shù)*/#include cstdlib#include conio.hint x,k;/*定義全局變量用于保存當前商品種類*/struct product /*定義商品數(shù)據(jù)結(jié)構(gòu)*/ int num; /*商品編號*/ char name20; /*

4、商品名稱*/ float price; /*商品售價*/ char place10; /*商品名稱*/ int storage; /*商品庫存*/_product10,product110;/定義主結(jié)構(gòu)體數(shù)組和備用結(jié)構(gòu)體數(shù)組struct data/定義日期結(jié)構(gòu)體 int year,month,day;struct sell /*定義銷售數(shù)據(jù)結(jié)構(gòu)*/ int cus; /*顧客代碼*/ int num; /*商品編號*/ float sells;/*銷售數(shù)量*/ char data112;/*日期*/ struct sell * next;*head_s,*pp,*tail_s;/定義頭指針操、

5、作指針以及尾指針 struct customer /*定義銷售數(shù)據(jù)結(jié)構(gòu)*/ int cus; /*顧客代碼*/ char name10; /*顧客姓名*/ struct customer * next;*head_c,*qq,*tail_c;/定義頭指針操、作指針以及尾指針void load();/讀取文件函數(shù)void add();/添加銷售信息函數(shù)int search_num();/依照商品編號查詢商品的銷售歷史void cal();/計算時刻段內(nèi)各個商品的銷售總額int search_name();/依照顧客姓名,查詢購買歷史void list_name();/顯示所有顧客的姓名void

6、main();/主函數(shù)int judge();/主體推斷函數(shù)int judge_data(char *data1);/細節(jié)推斷函數(shù),用于推斷日期是否合法void download_s();/寫入銷售信息(顧客代碼,銷售數(shù)量、銷售日期)文件void download_c();/導(dǎo)出顧客購買記錄void display();/顯示現(xiàn)在的商品信息/主函數(shù)void main() int choice; struct customer * head;/定義結(jié)構(gòu)指針 head=malloc(sizeof(struct customer);/申請動態(tài)存儲空間 head-next=NULL;do printf

7、(*歡迎使用商品銷售治理系統(tǒng)!*nn); printf( 1. 導(dǎo)入商品信息n); printf( 2. 顯示商品信息n); printf( 3. 輸入銷售記錄記錄n); printf( 4. 按編號查尋商品銷售歷史n); printf( 5. 計算時刻段內(nèi)各個銷售總額n); printf( 6. 按顧客姓名查找購買歷史n); printf( 7. 顯示顧客姓名n); printf( 8. 導(dǎo)出銷售信息(顧客代碼,銷售數(shù)量、銷售日期)文件n); printf( 9. 導(dǎo)出顧客信息文件n); printf( 0. 退出n); printf(*n); printf(請選擇不同功能 輸入09的數(shù)字n

8、 若輸入其它值會提早退出n); scanf(%d,&choice); system(cls); switch(choice) case 1: load(); system(cls); break; case 2: display(); break; case 3: add(); break; case 4: search_num(); break; case 5: cal(); break; case 6: search_name(); break; case 7: list_name(head); break; case 8: download_s(); break; case 9: dow

9、nload_c(); break; case 0: printf(nnnn); printf(*感謝使用*nnnn); break; while(choice0&choicenext=NULL; qq-next=NULL; system(cls); /*清屏*/ printf(*商品信息*nnn); printf( 商品編號 商品名稱 商品價格 商品產(chǎn)地 庫存數(shù)量n); while(i10) /輸出商品記錄 printf(%8d%12s %12.2f%10s%14dn,_producti.num,_,_producti.price, _producti.place,_

10、producti.storage); i+; printf(nn查詢完畢,請按任意鍵接著); getch(); system(cls);void load()/讀取文件函數(shù) int i=0,n=0,a,b,j; FILE *fp; /指向文件的指針 do printf(請選擇導(dǎo)入商品信息的方法n1:通過鍵盤輸入n2:通過文件導(dǎo)入n); scanf(%d,&a); if(a=2) if(fp=fopen(商品信息.txt,rb)=NULL)/打開文件 printf(不能打開文件,請檢查文件路徑n); /不能打開 exit(0); /退出*/ printf(*88商品信息88*n); printf

11、(編號 名稱 價格 產(chǎn)地 庫存數(shù)量n); while(!feof(fp) /讀入文件 fscanf(fp,%d%s%f%s%d,&_producti.num,_,&_producti.price,_producti.place,&_producti.storage); printf(%-10d%-10s %-10.2f%-12s%-12dn,_producti.num,_,_producti.price,_producti.place,_producti.storage); i+; for(i=0;i10;i+) product1i=_pro

12、ducti; /對備用結(jié)構(gòu)體數(shù)組賦值 fclose(fp); /關(guān)閉文件 printf(tt數(shù)據(jù)讀入成功!按任意鍵接著n); if(a=1) if(fp=fopen(商品信息1.txt,w)=NULL)/打開文件 printf(不能打開文件,請檢查文件路徑n); /不能打開 exit(0); /退出*/ printf(請輸入商品種數(shù)); scanf(%d,&b); printf(*商品信息*n); printf(編號 名稱 價格 產(chǎn)地 庫存數(shù)量n); for(j=1;j10000|year12|month31|day30) n=0; if(month=2&day=29) n=0; if(mon

13、th=4|month=6|month=9|month=11) if(day30) n=0; return n;/推斷函數(shù) int judge()/推斷商品編號 數(shù)量 日期是否正確 int i,j=0,k,temp; for(i=0;inum=_producti.num) j+; x=k=i; temp=_productk.storage; if(_productk.storage-(int)pp-sells)=0) _productk.storage-=(int)pp-sells;/推斷計算剩余量 break; if(j=0) return 3;/推斷是否存在輸入編號的商品 else if(t

14、emp-(int)pp-sellssells-(int)pp-sells=1e-6) return 4;/商品量 else if(judge_data(pp-data1)=0) return 0;/推斷日期 else return 1;/完全正確/添加銷售信息函數(shù)void add() int code,i=0,n,m; pp=(struct sell *)malloc(sizeof(struct sell);/申請動態(tài)存儲空間并將指針轉(zhuǎn)變?yōu)榻Y(jié)構(gòu)類型 qq=(struct customer *)malloc(sizeof(struct customer);/申請動態(tài)存儲空間并將指針轉(zhuǎn)變?yōu)榻Y(jié)構(gòu)類型

15、 srand(time(0); code=rand(); pp-next=NULL; qq-next=NULL; system(cls); /*清屏*/ printf(請輸入銷售記錄nnn); /*提示輸入記錄*/ printf(顧客姓名 商品編號 銷售數(shù)量 銷售日期n); printf(n); scanf(%s%d%f%s,qq-name,&pp-num,&pp-sells,pp-data1); /*輸入記錄*/ n=(int)pp-sells; if(nsells); while(1) m=judge();/推斷商品編號 數(shù)量 日期是否正確 if(m=1) / pp=(struct sel

16、l *)malloc(sizeof(struct sell);/申請動態(tài)存儲空間并將指針轉(zhuǎn)變?yōu)榻Y(jié)構(gòu)類型 / qq=(struct customer *)malloc(sizeof(struct customer); pp-cus=qq-cus=code;/隨機數(shù) if(head_s=NULL) head_s=pp; else tail_s-next=pp; tail_s=pp; if(head_c=NULL) head_c=qq; else tail_c-next=qq; tail_c=qq; printf(tt銷售信息輸入成功!按任意鍵接著n); getch(); system(cls);

17、break; else if(m=2) system(cls); printf(銷售數(shù)量已大于庫存數(shù)量,請重新輸入:nnn); printf(請輸入銷售數(shù)量nnn); /*提示輸入記錄*/ printf(銷售數(shù)量 n); scanf(%f,&pp-sells); /*輸入記錄*/ continue; else if(m=3) system(cls); printf(無此商品,請重新輸入:nnn); printf(請輸入銷售記錄nnn); /*提示輸入記錄*/ printf( 商品編號 n); scanf(%d,&pp-num); /*輸入記錄*/ continue; else if(m=4)

18、system(cls); printf(商品數(shù)量輸入錯誤,請重新輸入商品數(shù)量:nnn); printf(請輸入銷售記錄nnn); /*提示輸入記錄*/ printf(銷售數(shù)量:n); scanf(%f,&pp-sells); /*輸入記錄*/ continue; else if(m=0) system(cls); printf(銷售日期不合法,請重新輸入銷售日期:nnn);/*提示輸入記錄*/ printf(銷售日期n); scanf(%s,pp-data1); /*輸入記錄*/ continue; k+; /依照商品編號查詢商品的銷售歷史search_num() int i,num,k=0,

19、flag=1,n=0; struct sell * ptr; system(cls); printf(請輸入商品編號:n); scanf(%d,&num); for(i=0;inext) if(num=ptr-num) if(k=0) printf(商品編號 銷售數(shù)量 銷售總額 銷售日期n); printf(n); k+; printf(%5d%20d%20.2f%15sn,ptr-num,(int)ptr-sells, (int)ptr-sells*_producti.price,ptr-data1); if(k=0) printf(該商品記錄為空!按任意鍵接著); getch(); sys

20、tem(cls); return 0; else printf(nn查詢完畢,請按任意鍵接著); getch(); system(cls); return 0; /計算時刻段內(nèi)各個商品的銷售總額void cal() int i,n=0; struct sell s1,s2,*p=&s1,*q=&s2,*ptr; system(cls); printf(請輸入開始日期:); scanf(%s,p-data1); system(cls); do if(judge_data(pp-data1)!=1) printf(輸入日期不合法,請重新輸入:); scanf(%s,p-data1); system

21、(cls); n=1; else n=0;while(n=1); printf(請輸入結(jié)束日期:); scanf(%s,q-data1); system(cls);do if(judge_data(q-data1)!=1) printf(輸入日期不合法,請重新輸入:); scanf(%s,q-data1); system(cls); n=1; else n=0;while(n=1); printf(銷售記錄如下:tt時刻:%s至%sn,p-data1,q-data1); printf(nntt商品編號 銷售總額n); printf(ttnn);for(ptr=head_s;ptr;ptr=pt

22、r-next) for(i=0;inum) break; product1i.storage-=(int)ptr-sells; for(i=0;inext) for(ptr2=head_s;ptr2;ptr2=ptr2-next) if(ptr1-cus=ptr2-cus) break; for(i=0;inum=_producti.num) break; if(strcmp(name,ptr1-name)=0) / if(k=0|k%8=0) printf(顧客姓名 顧客代碼 商品編號 購買數(shù)量 購買總額 購買日期n); printf(n); printf(%2s%15d%15d%10d%1

23、5.2f%15sn,ptr1-name,ptr1-cus,ptr2-num,(int)ptr2-sells,(int)ptr2-sells)*product1i.price,ptr2-data1); /k+; k=0; if(k=0) printf(不存在此顧客!按任意鍵接著); getch(); system(cls); return 0; else printf(nn查詢完畢,請按任意鍵接著); getch(); system(cls); return 0; /顯示所有顧客的姓名void list_name() int n=1; struct customer * ptr; system(

24、cls); if(head_c!=NULL)/推斷鏈表是否為空 printf(顧客姓名如下:n);/用來顯示所有顧客的姓名 for(ptr=head_c;ptr;ptr=ptr-next) printf(tt%sn,ptr-name); n+; printf(nn顧客姓名查詢完畢,請按任意鍵接著); getch(); system(cls); else printf(顧客鏈表為空!請按任意鍵接著); getch(); system(cls); void download_s()/寫入銷售信息(顧客代碼,銷售數(shù)量、銷售日期)文件int i=0; FILE *fp; struct customer *ptr1; struct sell *ptr2; system(cls); if(fp=fopen(銷售信息文件.txt,w)=NULL) printf(銷售信息文件無法生成!n); exit(0); if(qq!=NULL) fprintf(fp, 顧客代碼 銷售數(shù)量 購買日期n); for(ptr1=head_c;ptr1;ptr1=ptr1

溫馨提示

  • 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

提交評論