日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

C语言大作业 商品库存管理系统

發(fā)布時(shí)間:2023/12/31 windows 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言大作业 商品库存管理系统 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

利用c語(yǔ)言做的課程設(shè)計(jì)(鏈表),在DEV C++等編譯器上可通過(guò)

可根據(jù)需求自行更改為圖書(shū)管理系統(tǒng)或者其他類(lèi)似的系統(tǒng)


本課題的主要任務(wù)是設(shè)計(jì)和實(shí)現(xiàn)一個(gè)“商品庫(kù)存管理系統(tǒng)”,并滿(mǎn)足以下要求:

1.系統(tǒng)以菜單方式工作;

2.使用鏈表或結(jié)構(gòu)數(shù)組對(duì)商品信息進(jìn)行管理和維護(hù);

3.使用二進(jìn)制文件在磁盤(pán)上保存商品信息;

4. 鏈表中各結(jié)點(diǎn)或結(jié)構(gòu)數(shù)組中各元素包括的商品信息: 商品編號(hào)、 商品名

稱(chēng)、 商品類(lèi)型(如食品、 體育用品、 生活用品、 兒童玩具、 音像制品等) 、

單價(jià)、 庫(kù)存數(shù)量、 是否進(jìn)口等。

5.實(shí)現(xiàn)如下基本功能:

(1) 新增商品

(2) 商品瀏覽 (輸出所有商品信息)

(3) 商品刪除 (刪除指定編號(hào)的商品)

(4) 商品修改 (修改指定編號(hào)的商品信息)- 14 -

(5) 商品排序 ( 根據(jù)商品編號(hào)進(jìn)行排序)

(6) 商品查詢(xún)統(tǒng)計(jì) ( 提供商品類(lèi)型、 是否進(jìn)口方式兩種方式對(duì)商品進(jìn)行

統(tǒng)計(jì)查詢(xún)功能)

(7)將商品信息保存到文件存盤(pán) ( 將鏈表或結(jié)構(gòu)數(shù)組中的數(shù)據(jù)以文件的

形式存盤(pán))

(8)從文件中讀入商品信息 ( 將已存盤(pán)的文件讀入內(nèi)存, 進(jìn)行管理)

#include <stdio.h> #include <stdlib.h> #include <string.h> #define FORMAT "%d%s%s%d%d%d" struct product { long num; //商品編號(hào) char name[20]; //商品名稱(chēng) char type[20]; //商品類(lèi)型 long price; //商品單價(jià) long res; //庫(kù)存數(shù)量 long import; //是否進(jìn)口,1代表進(jìn)口,0代表非進(jìn)口 struct product *next; }; int n=0;struct product *creat(); void print(struct product *head); void save_to_file(struct product *head); void change(int search_num,struct product *head); void insert(struct product *head,struct product *newpro); void del(int del_num,struct product *head); void swap(long *a,long *b); void sort(struct product *head); void type_inquire(struct product *head); void import_inquire(struct product *head);struct product *creat() /*創(chuàng)建鏈表*/ {struct product *head,*L;struct product *p1,*p2;FILE *fp1;fp1=fopen("D:\\goods.txt","r");n=0;head=(struct product *)malloc(sizeof(struct product));head->next=NULL;p2=head; p1=(struct product *)malloc(sizeof(struct product));fscanf(fp1,FORMAT,&p1->num,p1->name,p1->type,&p1->price,&p1->res,&p1->import); while (p1->num!=0){ n++;p2->next=p1;p2=p1;p1=(struct product *)malloc(sizeof(struct product)); //p1在前方開(kāi)辟,p2來(lái)保存之前的節(jié)點(diǎn) fscanf(fp1,FORMAT,&p1->num,p1->name,p1->type,&p1->price,&p1->res,&p1->import);}free(p1);p2->next=NULL; fclose(fp1); return(head); //head指向第一個(gè)空白節(jié)點(diǎn),其內(nèi)的元素為空 }void print(struct product *head) //用于將表在屏幕上輸出,一個(gè)漢字等于兩個(gè)空格 { struct product *p; printf("\n此表中有%d個(gè)記錄\n",n);p=head->next;if(p!=NULL){printf("┌────┬─────────────┬─────────────┬────────┬────────┬──────────┐\n");printf("│編號(hào)│ 商 品 名 稱(chēng) │ 商 品 類(lèi) 型 │ 單 價(jià) │ 庫(kù)存數(shù) │ 是否進(jìn)口 │\n");while(p!=NULL){printf("├────┼─────────────┼─────────────┼────────┼────────┼──────────┤\n");if(p->import) printf("│%4d│%13s│%13s│%8d│%8d│ 是 │\n",p->num,p->name,p->type,p->price,p->res);else printf("│%4d│%13s│%13s│%8d│%8d│ 否 │\n",p->num,p->name,p->type,p->price,p->res);p=p->next;}printf("└────┴─────────────┴─────────────┴────────┴────────┴──────────┘\n");} }void save_to_file(struct product *head) {struct product *p;p=head->next;FILE *fp;fp=fopen("D:\\goods.txt","w");while(p!=NULL){fprintf(fp,"%d %s %s %d %d %d \n",p->num,p->name,p->type,p->price,p->res,p->import);p=p->next;}fprintf(fp,"0 0 0 0 0 0"); //用于作為文件結(jié)束標(biāo)記 fclose(fp); }void change(int search_num,struct product *head) {struct product *p;p=head->next;while(p!=NULL&&p->num!=search_num)p=p->next;if(p==NULL)printf("\n————————表中無(wú)所查商品————————\n");else {printf("請(qǐng)輸入新的商品信息,包括:\n編號(hào) 名稱(chēng) 類(lèi)型 單價(jià) 庫(kù)存數(shù)量 是否進(jìn)口(用1表示進(jìn)口,0表示非進(jìn)口)\n"); scanf(FORMAT,&p->num,p->name,p->type,&p->price,&p->res,&p->import);printf("\n————————商品信息修改成功!————————\n");} } void insert(struct product *head,struct product *newpro) {struct product *p;p=head;while(p->next!=NULL) p=p->next;newpro->next=p->next;p->next=newpro;n++;printf("\n————————新增商品成功!————————\n"); }void del(int del_num,struct product *head) {struct product *p,*q;p=head;while(p->next&&p->next->num!=del_num) //查找要?jiǎng)h除的元素,最終用p指向要?jiǎng)h除的節(jié)點(diǎn)的 前驅(qū) 節(jié)點(diǎn) p=p->next;if(p->next==NULL)printf("————————未找到要?jiǎng)h除的商品————————\n");else {q=p->next;p->next=q->next;free(q);n--;printf("————————商品刪除成功!————————");} }void swap(long *a,long *b) {long temp;temp=*a;*a=*b;*b=temp; }void sort(struct product *head) //鏈表的冒泡排序法 {struct product *p;struct product *pend=NULL;p=head->next;char temp[20];while(p!=pend){while(p->next!=pend){if(p->num>p->next->num){swap(&p->num,&p->next->num);strcpy(temp,p->name);strcpy(p->name,p->next->name);strcpy(p->next->name,temp);strcpy(temp,p->type);strcpy(p->type,p->next->type);strcpy(p->next->type,temp);swap(&p->price,&p->next->price);swap(&p->res,&p->next->res);swap(&p->import,&p->next->import);}p=p->next;}pend=p;p=head->next;}printf("————————商品排序成功!————————"); }void type_inquire(struct product *head) {struct product *p;int count=0;char get_type[20];p=head->next;printf("請(qǐng)輸入要統(tǒng)計(jì)的商品類(lèi)型:");gets(get_type); printf("找到的所有此類(lèi)型商品信息如下:\n");printf("┌────┬─────────────┬─────────────┬────────┬────────┬──────────┐\n");printf("│編號(hào)│ 商 品 名 稱(chēng) │ 商 品 類(lèi) 型 │ 單 價(jià) │ 庫(kù)存數(shù) │ 是否進(jìn)口 │\n");while(p!=NULL){if(strcmp(p->type,get_type)==0){ count++;printf("├────┼─────────────┼─────────────┼────────┼────────┼──────────┤\n");if(p->import) printf("│%4d│%13s│%13s│%8d│%8d│ 是 │\n",p->num,p->name,p->type,p->price,p->res);else printf("│%4d│%13s│%13s│%8d│%8d│ 否 │\n",p->num,p->name,p->type,p->price,p->res); }p=p->next;}printf("└────┴─────────────┴─────────────┴────────┴────────┴──────────┘\n");printf("——————該類(lèi)型商品共有%d種——————\n",count);} void import_inquire(struct product *head) { struct product *p;int count=0,k;p=head->next;printf("統(tǒng)計(jì)非進(jìn)口商品信息,輸入0\n統(tǒng)計(jì)進(jìn)口商品信息,輸入1\n");printf("請(qǐng)輸入:");scanf("%d",&k);printf("找到的所有此類(lèi)型商品信息如下:\n");printf("┌────┬─────────────┬─────────────┬────────┬────────┬──────────┐\n");printf("│編號(hào)│ 商 品 名 稱(chēng) │ 商 品 類(lèi) 型 │ 單 價(jià) │ 庫(kù)存數(shù) │ 是否進(jìn)口 │\n");while(p!=NULL){if(p->import==k){ count++;printf("├────┼─────────────┼─────────────┼────────┼────────┼──────────┤\n");if(p->import) printf("│%4d│%13s│%13s│%8d│%8d│ 是 │\n",p->num,p->name,p->type,p->price,p->res);else printf("│%4d│%13s│%13s│%8d│%8d│ 否 │\n",p->num,p->name,p->type,p->price,p->res); }p=p->next;}printf("└────┴─────────────┴─────────────┴────────┴────────┴──────────┘\n");printf("——————該類(lèi)型商品共有%d種——————\n",count); } void main() {struct product *head,*newpro,*p;int c;char get_type[20];int len,del_num,change_num,flag=1;head=creat(); print(head); printf(" 1.新增商品\n");printf(" 2.商品瀏覽\n");printf(" 3.商品刪除\n");printf(" 4.商品修改\n");printf(" 5.商品排序(根據(jù)編號(hào)排序)\n");printf(" 6.商品查詢(xún)統(tǒng)計(jì)(按商品類(lèi)型統(tǒng)計(jì))\n");printf(" 7.商品查詢(xún)統(tǒng)計(jì)(按是否進(jìn)口統(tǒng)計(jì))\n");printf(" 8.將商品信息保存到文件存盤(pán)\n"); printf(" 9.退出系統(tǒng)\n"); while(1){printf(" 請(qǐng)輸入功能選項(xiàng)(1..9) :"); scanf("%d",&c);getchar(); switch(c){ case 1:printf("請(qǐng)輸入一種新產(chǎn)品的信息,系統(tǒng)將在表中新增該商品信息后輸出(用1表示進(jìn)口,0表示非進(jìn)口)\n");newpro=(struct product *)malloc(sizeof(struct product));scanf(FORMAT,&newpro->num,newpro->name,newpro->type,&newpro->price,&newpro->res,&newpro->import); insert(head,newpro);print(head);break;case 2:print(head); break;case 3:if(head->next==NULL){printf("表已空,無(wú)法刪除\n");break;}else{printf("請(qǐng)輸入要?jiǎng)h除的產(chǎn)品的編號(hào):");scanf("%d",&del_num);del(del_num,head);print(head);break;}case 4:printf("請(qǐng)輸入要修改的商品編號(hào):");scanf("%d",&change_num);change(change_num,head);break;case 5:sort(head);print(head);break;case 6:type_inquire(head); break;case 7:import_inquire(head); break;case 8:save_to_file(head);printf("數(shù)據(jù)已成功保存至指定文件中\(zhòng)n");break;case 9:flag=0;break;default:printf("輸入有誤\n");}if(flag==0)break;}printf("\n——————————已退出系統(tǒng)——————————\n");}

代碼運(yùn)行部分:增刪改查等操作根據(jù)已有格式即可

?注:此程序采用文件儲(chǔ)存信息,需自行根據(jù)要求建立一個(gè)txt文檔,根據(jù)fscanf函數(shù),格式同上(同行用空格分開(kāi),隔行用回車(chē)),如在此程序中是在D盤(pán)

總結(jié)

以上是生活随笔為你收集整理的C语言大作业 商品库存管理系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。