您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關(guān)C語言中怎么實(shí)現(xiàn)一個(gè)倉庫物資管理系統(tǒng),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
查詢庫存
*按電器名查詢*按品牌名查詢*按送貨人查詢*按提貨人查詢*按電器名稱由大到小順序輸出所有庫存*按庫存數(shù)量由高到低輸出所有庫存
物資存入
物資取出
統(tǒng)計(jì)物資
*入庫電器總價(jià)值*出庫電器總利潤*統(tǒng)計(jì)某月每種電器的出庫數(shù)目*統(tǒng)計(jì)某月每種品牌的電器的出庫數(shù)目
代碼
#include<stdio.h>#include<stdlib.h>#include<string.h>//------------------------------------------------------結(jié)構(gòu)體區(qū)域typedef struct{ char name[20]; //電器名稱 char brandName[20]; //品牌名稱 int num; //庫存數(shù)量 int unitPrice; //單價(jià) int year; int month; int day; char manName[20];}stock; //庫存stock s[10000],t[10000],x[10000],y[10000],in[10000],out[10000],no[10000],no1[10000],no2[10000]; //全局變量//-------------------------------------------------------函數(shù)聲明區(qū)域void menu(void);//主菜單函數(shù)void write(void);//創(chuàng)建倉庫函數(shù)void find(void);//查詢庫存函數(shù)void findPart(void);//部分查詢函數(shù)void findOne(void); //按電器名查詢void findTwo(void); //按品牌名查詢void findThree(void); //按提貨人查詢void findFour(void); //按送貨人查詢void findFive(void); //按電器名稱大小順序輸出所有庫存void findSix(void); //按庫存數(shù)量由高到低輸出所有庫存void deposit(void);//存入倉庫函數(shù)void takeout(void);//取出倉庫函數(shù)void tongji(void);//統(tǒng)計(jì)函數(shù)void tongji1(void);//第一種統(tǒng)計(jì)函數(shù)void tongji2(void);//第二種統(tǒng)計(jì)函數(shù)void tongji3(void);//第三種統(tǒng)計(jì)函數(shù)void tongji4(void);//第四種統(tǒng)計(jì)函數(shù)int readFile(void);//讀取庫存記錄文件中所有結(jié)構(gòu)體的數(shù)目int readFile1(void);//讀取入庫記錄文件中所有結(jié)構(gòu)體的數(shù)目int readFile2(void);//讀取出庫記錄文件中所有結(jié)構(gòu)體的數(shù)目void end(void);//結(jié)束退出函數(shù)//-------------------------------------------------------主函數(shù)int main(){ menu(); return 0;}void menu(void){ int n,l=0; printf("============================================================\n"); printf(" \n"); printf(" -----*****歡 迎 使 用 倉 庫 物 資 管 理 系 統(tǒng) ! *****----- \n"); printf(" \n"); printf("============================================================\n"); printf(" \n"); printf(" 您可以進(jìn)行以下操作: \n"); printf(" \n"); printf(" 1. 倉庫初始化 \n"); printf(" \n"); printf(" 2. 查詢庫存 \n"); printf(" \n"); printf(" 3. 物資存入 \n"); printf(" \n"); printf(" 4. 物資取出 \n"); printf(" \n"); printf(" 5. 統(tǒng)計(jì)物資 \n"); printf(" \n"); printf(" 0. 退出系統(tǒng) \n"); printf(" \n"); printf(" \n"); printf("============================================================\n"); printf("現(xiàn)在請選擇您要進(jìn)行的操作:(請輸入操作前的數(shù)字)"); while(scanf("%d",&n)!=EOF) { switch(n) { case 1:system("CLS");write();break; case 2:system("CLS");find();break; case 3:system("CLS");deposit();break; case 4:system("CLS");takeout();break; case 5:system("CLS");tongji();break; case 0:system("CLS");end();exit(0); default :printf("沒有此選項(xiàng)!\n 請重新輸入!\n"); } }}void write(void) //right{ FILE *fp; int i,n; fp=fopen("庫存記錄.dat","wb"); rewind(fp); printf("============================================================\n"); printf("請輸入倉庫中電器信息的組數(shù)!\n ps:相同電器但是不同品牌電器算多種!\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("開始寫入第%d組\n",i+1); printf("請輸入電器名稱:"); scanf("%s",s[i].name); printf("請輸入電器品牌名稱:"); scanf("%s",s[i].brandName); printf("請輸入電器數(shù)量:"); scanf("%d",&s[i].num); printf("請輸入電器單價(jià):"); scanf("%d",&s[i].unitPrice); printf("請輸入存貨時(shí)間: <年月日之間用空格隔開>例:2016 12 01\n"); scanf("%d%d%d",&s[i].year,&s[i].month,&s[i].day); printf("請輸入存貨人:"); scanf("%s",s[i].manName); } fwrite(s,sizeof(stock),n,fp); fclose(fp); printf("當(dāng)前庫存記錄:(請仔細(xì)核對)\n"); for(i=0;i<n;i++) { printf("%s\n%s\n%d\n%d\n%d.%d.%d\n%s\n",s[i].name,s[i].brandName,s[i].num,s[i].unitPrice,s[i].year,s[i].month,s[i].day,s[i].manName); } printf("電器信息寫入完成!\n 請按回車鍵返回主界面!\n"); getchar();getchar(); system("CLS"); menu();}void findOne(void){ char name[10],ch='y'; int i,k,n,bn; bn=readFile(); do { system("CLS"); printf("============================================================\n"); printf("請輸入要查詢的電器名稱:\n"); getchar(); gets(name); k=-1; for(i=0;i<bn;i++) { if(strcmp(t[i].name,name)==0) { printf("該電器信息如下:\n"); k=i; printf("電器名稱:%s,電器品牌:%s,庫存數(shù)量:%d,電器單價(jià):%d,入庫時(shí)間:%d.%d.%d,存貨人:%s\n",t[k].name,t[k].brandName,t[k].num,t[k].unitPrice,t[k].year,t[k].month,t[k].day,t[k].manName); } } if(k==-1) { printf("抱歉,本倉庫中無此電器!\n"); } printf("\n是否繼續(xù)查詢?<y/n>\n"); ch=getchar(); }while(ch=='y'||ch=='Y'); printf("將返回上一級(jí)菜單!\n 請按回車鍵確認(rèn)!\n"); getchar();getchar(); system("CLS"); findPart();}void findTwo(void){ char brandName[10],ch='y'; int i,k,n,bn; bn=readFile(); do { system("CLS"); printf("============================================================\n"); printf("請輸入要查詢的品牌名稱:\n"); getchar(); gets(brandName); k=-1; for(i=0;i<bn;i++) { if(strcmp(t[i].brandName,brandName)==0) { printf("該電器信息如下:\n"); k=i; printf("電器名稱:%s,電器品牌:%s,庫存數(shù)量:%d,電器單價(jià):%d,入庫時(shí)間:%d.%d.%d,存貨人:%s\n",t[k].name,t[k].brandName,t[k].num,t[k].unitPrice,t[k].year,t[k].month,t[k].day,t[k].manName); } } if(k==-1) { printf("抱歉,本倉庫中無此電器!\n"); } printf("\n是否繼續(xù)查詢?<y/n>\n"); ch=getchar(); }while(ch=='y'||ch=='Y'); printf("將返回上一級(jí)菜單!\n 請按回車鍵確認(rèn)!\n"); getchar();getchar(); system("CLS"); findPart();}void findThree(void) // 按送貨人查詢 入庫{ char manName[10],ch='y'; int i,k,n,bn1; bn1=readFile1(); FILE *fp1; fp1=fopen("入庫記錄.dat","rb+"); if(fp1==NULL) { printf("該倉庫中未添加任何電器!\n"); exit(0); } fread(&y,sizeof(stock),bn1,fp1); fclose(fp1); do { system("CLS"); printf("============================================================\n"); printf("請輸入要查詢的存貨人:\n"); getchar(); gets(manName); k=-1; for(i=0;i<bn1;i++) { if(strcmp(y[i].manName,manName)==0) { printf("該電器信息如下:\n"); k=i; printf("電器名稱:%s,電器品牌:%s,庫存數(shù)量:%d,電器單價(jià):%d,入庫時(shí)間:%d.%d.%d,存貨人:%s\n",y[k].name,y[k].brandName,y[k].num,y[k].unitPrice,y[k].year,y[k].month,y[k].day,y[k].manName); } } if(k==-1) { printf("抱歉,本倉庫中無此存貨人存入的電器!\n"); } printf("\n是否繼續(xù)查詢?<y/n>\n"); ch=getchar(); }while(ch=='y'||ch=='Y'); printf("將返回上一級(jí)菜單!\n 請按回車鍵確認(rèn)!\n"); getchar();getchar(); system("CLS"); findPart();}void findFour(void) //按提貨人查詢 出庫{ char manName[10],ch='y'; int i,k,n,bn2; bn2=readFile2(); FILE *fp2; fp2=fopen("出庫記錄.dat","rb+"); if(fp2==NULL) { printf("該倉庫中未提出任何電器!\n"); exit(0); } fread(&x,sizeof(stock),bn2,fp2); fclose(fp2); do { system("CLS"); printf("============================================================\n"); printf("請輸入要查詢的提貨人:\n"); getchar(); gets(manName); k=-1; for(i=0;i<bn2;i++) { if(strcmp(x[i].manName,manName)==0) { printf("該電器信息如下:\n"); k=i; printf("電器名稱:%s,電器品牌:%s,庫存數(shù)量:%d,電器單價(jià):%d,出庫時(shí)間:%d.%d.%d,提貨人:%s\n",x[k].name,x[k].brandName,x[k].num,x[k].unitPrice,x[k].year,x[k].month,x[k].day,x[k].manName); } } if(k==-1) { printf("抱歉,本倉庫中無此提貨人提出的電器!\n"); } printf("\n是否繼續(xù)查詢?<y/n>\n"); ch=getchar(); }while(ch=='y'||ch=='Y'); printf("將返回上一級(jí)菜單!\n 請按回車鍵確認(rèn)!\n"); getchar();getchar(); system("CLS"); findPart();}void findFive(void) //電器名稱大小順序輸出所有庫存{ int bn; bn=readFile(); printf("============================================================\n"); FILE *fp; fp=fopen("庫存記錄.dat","rb+"); if(fp==NULL) { printf("該倉庫中無庫存!\n"); exit(0); } fread(&s,sizeof(stock),bn,fp); int i,j; for(i=0;i<bn-1;i++) for(j=0;j<bn-1-i;j++) { if(s[j].name<s[j+1].name) { t[1]=s[j+1]; s[j+1]=s[j]; s[j]=t[1]; } } for(i=0;i<bn;i++) printf("%d. 電器名稱:%s,電器品牌:%s,庫存數(shù)量:%d,電器單價(jià):%d,入庫時(shí)間:%d.%d.%d,存貨人:%s\n",i+1,s[i].name,s[i].brandName,s[i].num,s[i].unitPrice,s[i].year,s[i].month,s[i].day,s[i].manName); printf("\n輸出完成!請按回車鍵返回上一級(jí)!\n"); getchar();getchar(); system("CLS"); findPart();}void findSix(void) //按庫存數(shù)量由高到低輸出所有庫存{ int bn; bn=readFile(); printf("============================================================\n"); FILE *fp; fp=fopen("庫存記錄.dat","rb+"); if(fp==NULL) { printf("該倉庫中無庫存!\n"); exit(0); } fread(&s,sizeof(stock),bn,fp); int i,j; for(i=0;i<bn-1;i++) for(j=0;j<bn-1-i;j++) { if(s[j].num<s[j+1].num) { t[1]=s[j+1]; s[j+1]=s[j]; s[j]=t[1]; } } for(i=0;i<bn;i++) printf("%d. 電器名稱:%s,電器品牌:%s,庫存數(shù)量:%d,電器單價(jià):%d,入庫時(shí)間:%d.%d.%d,存貨人:%s\n",i+1,s[i].name,s[i].brandName,s[i].num,s[i].unitPrice,s[i].year,s[i].month,s[i].day,s[i].manName); printf("\n輸出完成!請按回車鍵返回上一級(jí)!\n"); getchar();getchar(); system("CLS"); findPart();}void findPart(void){ int n; printf("============================================================\n"); printf("1. 按電器名查詢\n"); printf("2. 按品牌名查詢\n"); printf("3. 按送貨人查詢\n"); printf("4. 按提貨人查詢\n"); printf("5. 按電器名稱由大到小順序輸出所有庫存\n"); printf("6. 按庫存數(shù)量由高到低輸出所有庫存\n"); printf("0. 返回主菜單\n"); while(scanf("%d",&n)!=EOF) switch(n) { case 1:system("CLS");findOne();break; case 2:system("CLS");findTwo();break; case 3:system("CLS");findThree();break; case 4:system("CLS");findFour();break; case 5:system("CLS");findFive();break; case 6:system("CLS");findSix();break; case 0:system("CLS");menu();break; default :printf("沒有此選項(xiàng)!\n 請重新輸入!\n"); }}void find(void){ int i,bn; FILE *fp; fp=fopen("庫存記錄.dat","rb+"); if(fp==NULL) { printf("該倉庫中無庫存!\n"); exit(0); } rewind(fp); bn=readFile(); fread(&t,sizeof(stock),bn,fp); getchar(); findPart(); fclose(fp);}void deposit(void) //入庫{ printf("============================================================\n"); int bn,bn1; stock jia; FILE *fp1,*fp; int i=0,j,n=0; char ch='y'; printf("請輸入要加入倉庫的電器信息:\n"); do { fp1=fopen("入庫記錄.dat","ab+"); if(fp1==NULL) { printf("該倉庫中未添加任何電器!\n"); exit(0); } fp=fopen("庫存記錄.dat","ab+"); bn=readFile(); bn1=readFile1(); printf("請輸入電器名稱:"); scanf("%s",jia.name); printf("請輸入電器品牌:"); scanf("%s",jia.brandName); printf("請輸入電器數(shù)量:"); scanf("%d",&jia.num); printf("請輸入電器單價(jià):"); scanf("%d",&jia.unitPrice); printf("請輸入送貨時(shí)間: <ps: 年月日之間用空格隔開> 例:2016 12 01\n"); scanf("%d%d%d",&jia.year,&jia.month,&jia.day); printf("請輸入送貨人:"); scanf("%s",jia.manName); fwrite(&jia,sizeof(stock),1,fp1); fwrite(&jia,sizeof(stock),1,fp); fclose(fp1);fclose(fp); printf("是否繼續(xù)輸入?<y/n>\n"); getchar(); ch=getchar(); }while(ch=='y'||ch=='Y'); printf("將返回上一級(jí)菜單!\n 請按回車鍵確認(rèn)!\n"); getchar(); system("CLS"); menu();}void takeout(void) //出庫{ stock jian; printf("==============================================================\n"); int bn,bn2,i,j; char ch='y'; FILE *fp,*fp2; bn=readFile(); bn2=readFile2(); printf("請輸入要提出倉庫的電器信息:\n"); do { fp=fopen("庫存記錄.dat","rb+"); if(fp==NULL) { printf("無法打開此文件!\n"); exit(0); } for(i=0;i<bn;i++) { fread(&s[i],sizeof(stock),1,fp); } fclose(fp); fp2=fopen("出庫記錄.dat","wb+"); if(fp2==NULL) { printf("無法打開此文件!\n"); exit(0); } printf("請輸入電器名稱:"); scanf("%s",jian.name); printf("請輸入電器品牌:"); scanf("%s",jian.brandName); printf("請輸入電器數(shù)量:"); scanf("%d",&jian.num); printf("請輸入電器單價(jià):"); scanf("%d",&jian.unitPrice); printf("請輸入提貨時(shí)間: <ps: 年月日之間用空格隔開> 例:2016 12 01\n"); scanf("%d%d%d",&jian.year,&jian.month,&jian.day); printf("請輸入提貨人:"); scanf("%s",jian.manName); getchar(); fwrite(&jian,sizeof(stock),1,fp2); fclose(fp2); for(i=0;i<bn;i++) { if((strcmp(jian.name,s[i].name)==0)&&(strcmp(jian.brandName,s[i].brandName)==0)) { if(jian.num<=s[i].num) { s[i].num=s[i].num-jian.num; } else { printf("庫存不足!無法提出!\n"); printf("請按回車鍵返回!"); getchar(); system("CLS"); menu(); } } } fopen("庫存記錄.dat","wb+"); for(i=0;i<bn;i++) { fwrite(&s[i],sizeof(stock),1,fp); } fclose(fp); printf("\n出庫完成! 是否繼續(xù)輸入?<y/n>\n"); getchar(); ch=getchar(); }while(ch=='y'||ch=='Y'); printf("將返回上一級(jí)菜單!\n 請按回車鍵確認(rèn)!\n"); getchar(); system("CLS"); menu();}void tongji(void){ int n; system("CLS"); printf("==============================================================\n"); printf("1. 入庫電器總價(jià)值\n"); printf("2. 出庫電器總利潤\n"); printf("3.統(tǒng)計(jì)該月每種電器的出庫數(shù)目\n"); printf("4.統(tǒng)計(jì)該月每種品牌的電器的出庫數(shù)目\n"); printf("0. 返回主菜單\n"); printf("請選擇要進(jìn)行的操作:(0到4)\n"); scanf("%d",&n); getchar(); while(n!=0&&n!=1&&n!=2&&n!=3&&n!=4) { printf("沒有此選項(xiàng)!\n 請重新輸入!\n"); scanf("%d",&n); getchar(); } switch(n) { case 1:tongji3();break;//第三種統(tǒng)計(jì)函數(shù) case 2:tongji4();break;//第四種統(tǒng)計(jì)函數(shù) case 3:tongji1();break;//第一種統(tǒng)計(jì)函數(shù) case 4:tongji2();break;//第二種統(tǒng)計(jì)函數(shù) case 0:system("CLS");menu();break; }}void tongji2(void)//第二種統(tǒng)計(jì)函數(shù){ FILE *fp; int bn1,i,year,month,k=0; bn1=readFile1(); system("CLS"); printf("==============================================================\n"); fp=fopen("出庫記錄.dat","rb+"); if(fp==NULL) { printf("無法打開此文件!\n"); exit(0); } for(i=0;i<bn1;i++) { fread(&s,sizeof(stock),bn1,fp); } printf("請輸入一個(gè)日期(年 月 如 2017 01):\n"); scanf("%d%d",&year,&month); for(i=0;i<bn1;i++) { if((s[i].year==year)&&(s[i].month==month)) { printf("電器名稱:%s\n品牌名稱:%s\n出庫數(shù)目:%d\n",s[i].name,s[i].brandName,s[i].num); k+=1; } } if(k==0) printf("庫存記錄中不存在此種電器!\n"); fclose(fp); printf("統(tǒng)計(jì)完成,請按回車鍵返回!\n"); getchar(); getchar(); system("CLS"); tongji();}void tongji1(void)//第一種統(tǒng)計(jì)函數(shù){ FILE *fp; int bn1,i,year,month,k=0; bn1=readFile1(); system("CLS"); printf("==============================================================\n"); fp=fopen("出庫記錄.dat","rb+"); if(fp==NULL) { printf("無法打開此文件!\n"); exit(0); } for(i=0;i<bn1;i++) { fread(&s,sizeof(stock),bn1,fp); } printf("請輸入一個(gè)日期(年 月 如 2017 01 ):\n"); scanf("%d%d",&year,&month); for(i=0;i<bn1;i++) { if((s[i].year==year)&&(s[i].month==month)) { printf("電器名稱:%s\n出庫數(shù)目:%d\n",s[i].name,s[i].num); k+=1; } } if(k==0) printf("庫存記錄中不存在此種電器!\n"); fclose(fp); printf("統(tǒng)計(jì)完成,請按回車鍵返回!\n"); getchar(); getchar(); system("CLS"); tongji();}void tongji3(void)//第三種統(tǒng)計(jì)函數(shù){ FILE *fp; int bn1,i; long long int total=0; bn1=readFile1(); system("CLS"); printf("==============================================================\n"); fp=fopen("入庫記錄.dat","rb+"); if(fp==NULL) { printf("無法打開此文件!\n"); exit(0); } for(i=0;i<bn1;i++) { fread(&s[i],sizeof(stock),1,fp); } fclose(fp); for(i=0;i<bn1;i++) { total+=(s[i].num*s[i].unitPrice); } printf("商品總價(jià)值為%d\n",total); printf("統(tǒng)計(jì)完成,請按回車鍵返回!\n"); getchar(); system("CLS"); tongji();}void tongji4(void)//第四種統(tǒng)計(jì)函數(shù){ FILE *fp1,*fp2; int bn,bn2,i; long long int money=0; bn=readFile(); bn2=readFile2(); system("CLS"); printf("==============================================================\n"); fp1=fopen("庫存記錄.dat","rb+"); if(fp1==NULL) { printf("無法打開此文件!\n"); exit(0); } for(i=0;i<bn;i++) { fread(&s[i],sizeof(stock),1,fp1); } fclose(fp1); fp2=fopen("出庫記錄.dat","rb+"); if(fp2==NULL) { printf("無法打開此文件!\n"); exit(0); } for(i=0;i<bn2;i++) { fread(&t[i],sizeof(stock),1,fp2); } fclose(fp2); for(i=0;i<bn2;i++) { money+=((t[i].unitPrice-s[i].unitPrice)*t[i].num); } printf("總利潤為%d\n",money); printf("統(tǒng)計(jì)完成,請按回車鍵返回!\n"); getchar(); system("CLS"); tongji();}void end(void){ printf("==============================================================\n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" 感 謝 使 用 本 系 統(tǒng) ! \n"); printf(" \n"); printf(" 再 見 ! \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf("==============================================================\n");}int readFile(void)//庫存記錄文件中結(jié)構(gòu)體的個(gè)數(shù){ FILE *fb; int bn=0; fb=fopen("庫存記錄.dat","rb+"); if(fb==NULL) { return bn; } while(!feof(fb)) { if(fread(&no[bn],sizeof(stock),1,fb)) bn++; } fclose(fb); return bn;}int readFile1(void)//入庫記錄文件中結(jié)構(gòu)體的個(gè)數(shù){ FILE *fb; int bn1=0; fb=fopen("入庫記錄.dat","rb+"); if(fb==NULL) { return bn1; } while(!feof(fb)) { if(fread(&no1[bn1],sizeof(stock),1,fb)) bn1++; } fclose(fb); return bn1;}int readFile2(void)//出庫記錄文件中結(jié)構(gòu)體的個(gè)數(shù){ FILE *fb; int bn2=0; fb=fopen("出庫記錄.dat","rb+"); if(fb==NULL) { return bn2; } while(!feof(fb)) { if(fread(&no2[bn2],sizeof(stock),1,fb)) bn2++; } fclose(fb); return bn2;}
看完上述內(nèi)容,你們對C語言中怎么實(shí)現(xiàn)一個(gè)倉庫物資管理系統(tǒng)有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。