C语言版商品库存管理系统Word格式.docx
- 文档编号:22619833
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:20
- 大小:18.47KB
C语言版商品库存管理系统Word格式.docx
《C语言版商品库存管理系统Word格式.docx》由会员分享,可在线阅读,更多相关《C语言版商品库存管理系统Word格式.docx(20页珍藏版)》请在冰豆网上搜索。
保存商品信息到文件
读取文件内商品信息退出程序
#define_CRT_SECURE_NO_WARNINGS
#include<
stdlib.h>
string.h>
malloc.h>
windows.h>
mmsystem.h>
#pragmacomment(lib,"
WINMM.lib"
)
#include"
标头.h"
voidmenu(inf*head)//
{
背景.wav"
),NULL,
SND_FILENAME|SND_ASYNC|SND_LOOP);
system("
color3B"
);
显示菜单
printf("
\t\t*****************************************************\n"
\t\t\t\t欢迎进入商品库存管理系统\n"
\n"
\t\t|
基本信息
|\n"
\t\t|
1.
商品信息录入
|2.
|\n"
3.
查找商品信息
|4.
5.
|6.
保存文件信息
7.
读取文件信息
|8.
显示商品信息
9.
按价格从高到低进行排序
\t\t|__
0.
释放链表。
退出
|"
\n\t\t\t
请输入你的选项(
0---8):
\t\t|====================================================|\n"
\t请输入你的选择:
\n"
}
inf*create()//创建链表
inf*p;
p=(inf*)malloc(sizeof(structinformation));
if(p==NULL)
链表创建失败.\n"
exit(0);
p->
next=NULL;
return(p);
voidInput(inf*head)//
inti,n;
录入货物信息
请输入:
你想录入多少个商品信息:
\n"
scanf("
%d"
&
n);
for(i=1;
i<
=n;
i++)
结点创建失败.\n"
exit(0);
请输入商品:
编号,名称,价格,数量:
生产日期
编号:
"
scanf("
%s"
p->
number);
printf("
名称:
sname);
价格:
%f"
price);
数量:
count);
生产日期:
"
p->
dath);
p->
while(head->
next!
=NULL)
head=head->
next;
head->
next=p;
voidtianjia(inf*head)//添加货物信息{
你想添加多少个商品信息:
链表结点创建失败。
=NULL)head=head->
head->
voidoutput(inf*head)//输出货物信息
intn=0;
p=head->
链表为空,请先输入信息!
return;
while(p!
n++;
%s\n"
printf(”商品信息:
编号:
%s,名称:
%s,价格:
%.2f数量:
%d生产日期:
number,p->
sname,p->
price,p->
count,p->
p=p->
商品总数为:
%d\n"
n);
voidchaxun(inf*head)//
inta;
\t\t查询信息\n"
while
(1)
\t1.按编号查询\n"
\t2.按名称查询\n"
请输入你的选择:
a);
查询货物信息函数
if(a==1)
chaxun_number(head);
//break;
if(a==2)
chaxun_sname(head);
调用按编号查询的函数
调用按名称查询的函数
if(a!
=1&
&
a!
=2)
输入错误!
break;
}getchar();
voidchaxun_number(inf*head)
charnum[20];
inti=-1;
p=head;
//
按编号查询
请输入你要查询的商品的编号:
num);
while(p->
{p=p->
if(strcmp(p->
number,num)==0)
i=1;
已找到该商品信息\n"
货物信息:
%s,名称:
%.2f.数量:
%d,生产日
期:
%s\n"
if(i<
0)
没有此商品信息!
voidchaxun_sname(inf*head)//按名称查询
chara[20];
请输入要查找商品的名称:
a);
sname,a)==0)
商品信息:
%s,名称:
%s,价格:
%d,生产日期\n"
}}if(i<
voidxiugai(inf*head)//{
\t********************\n"
\t
请输入修改的方式:
\t1.
单个信息全部修改。
\t2.
单个信息逐个修改。
没有此商品!
修改货物信息
请输入选项:
charno[20];
p=head;
请输入要修改商品的编号:
no);
number,no)==0)
已找到该商品\n请输入新的的编号,名称,价格,数量:
生产日
没有此商品信息!
0)printf("
}
inf*p=NULL;
intb;
charnumber2[20];
charname2[100];
floatprice2;
intcount2;
没有商品信息,请先保存商品信息!
\t\t
请输入要修改的内容\n"
\t\t1.
修改编号2.修改名称\n"
\t\t3.
修改价格4.修改数量\n"
\t\t5.
修改生产日期\n"
请选择\n"
b);
switch(b)
case1:
请输入原商品编号:
number2);
number,number2)==0)
:
已找到该商品\n请输入新的编号scanf("
该商品信息已修改成功。
break;
case2:
请输入原名称:
name2);
sname,name2)==0)
请输入新的名称:
case3:
请输入该商品编号:
&
请输入原价格:
price2);
number,number2)==0&
price2==p->
price)
请输入新的价格:
case4:
请输入被修改的数量:
count2);
if(count2==p->
count&
strcmp(p->
请输入新的数量:
删除货物信息
该商品信息已修改成功。
default:
修改内容有错误!
voidshanchu(inf*head)//
\t\t1.按编号删除2.按名称删除\n"
\t\t请输入选项:
switch(a)
inf*p,*h;
请输入你要删除的商品的编号:
number);
if(strcmp(number,p->
next->
number)==0)
h=p->
next=p->
free(h);
已删除该商品信息。
charname[20];
inti=-1;
请输入你要删除的商品的名称:
name);
if(strcmp(name,p->
sname)==0)
free(h);
}if(i<
voidwrite_file(inf*head)
保存货物信息到文件
FILE*fp;
商品信息.txt"
"
wb"
))==NULL)
if((fp=fopen("
Donothavethisfile\n"
fwrite(p,sizeof(structinformation),1,fp);
}fclose(fp);
读取文件内的货物信息
inf*Read__file()//
inf*p,*d,*head;
head=(inf*)malloc(sizeof(structinformation));
p=(inf*)malloc(sizeof(structinformation));
商品信息.txt"
rb"
不能打开文件!
if(fread(head,sizeof(structinformation),1,fp))
d=head;
while(fread(p,sizeof(structinformation),1,fp))
{d->
d=p;
d->
fclose(fp);
return(head);
释放空间退出程序
voidfreeh(inf*head)//
free(p);
}free(p);
voidpaixu(inf*head)
inf*p=head,*q=NULL,*t=NULL,*subhead=NULL;
inti,j,count=0;
count++;
for(i=0;
count-1;
subhead=head;
q=p->
for(j=0;
j<
count-i-1;
j++)
if(p->
price<
q->
{subhead->
next=q->
t=p;
p=q;
q=t;
subhead=subhead->
q=q->
}output(head);
intmain()
inf*head;
head=(inf*)malloc(sizeof(structinformation));
head=create();
功能选择
{menu(head);
inth;
h);
switch(h)//
{case1:
Input(head);
Sleep(500);
tianjia(head);
Sleep(1000);
chaxun(head);
xiugai(head);
write_file(head);
case5:
shanchu(head);
output(head);
case6:
\t已经成功保存信息!
\t\n"
case7:
next=Read__file();
case8:
case9:
paixu(head);
case0:
freeh(head);
\t\n"
\t已经退出程序
输入错误\n"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言版 商品 库存 管理 系统