C语言程序课程设计商品进销存管理系统程序.docx
- 文档编号:27392738
- 上传时间:2023-06-30
- 格式:DOCX
- 页数:34
- 大小:383.17KB
C语言程序课程设计商品进销存管理系统程序.docx
《C语言程序课程设计商品进销存管理系统程序.docx》由会员分享,可在线阅读,更多相关《C语言程序课程设计商品进销存管理系统程序.docx(34页珍藏版)》请在冰豆网上搜索。
C语言程序课程设计商品进销存管理系统程序
一题目及运行说明
商品进销存管理程序
1、题目描述
设计一个商品进销管理程序,该程序具有以下功能:
(1)录入商品信息;
(2)给定商品编号,修改该商品信息;
(3)给定商品编号,删除该商品信息;
(4)录入商品的进货和销售信息;
(5)给定商品编号或商品名,查看该商品及库存信息;
(6)统计功能:
提供一些统计各类信息的功能。
2、题目要求
(1)按照分析、设计、编码、调试和测试过程完成应用程序;
(2)学习并使用流程图等工具,并在撰写报告中使用;
(3)程序的各项功能在程序运行时,以菜单形式选择并执行;
(4)要求用户输入数据时,要给出清晰、明确的提示,包括:
输入数据的内容、格式及其结束方式等
(5)所有的信息存储在一个文件或多个中,并实现文件读写操作。
(6)程序中用链表存放商品及进销存信息并实现增删减功能。
3、提示
(1)提醒事件信息可以设计一个结构体类型
(2)自己构思并增加的除规定功能之外的新功能,酌情加分
(1)程序中主要变量
Structgoods*head结构体指针Intn,kstructgoods{intnumber;
charname[20];intshumu;floatjiage;structgoods*next;};intn,k;
structgoods*head;等一些变量。
(2)数据输入的形式和输入值的范围字符不超过20位整型变量输入大于0
浮点型变量也大于0
商品编号为四位整数
(3)数据输入的形式
按程序运行的提示操作※
(4)程序所能达到的功能及出错处理该程序具有以下功能:
(1)录入商品信息;
(2)给定商品编号,修改该商品信息;
(3)给定商品编号,删除该商品信息;
(4)录入商品的进货和销售信息;
(5)给定商品编号或商品名,查看该商品及库存信息
(6)统计功能:
提供一些统计各类信息的功能。
二程序设计思路
根据要求首先设计一个结构体类型,设计好界面,设计好主函数。
程序各功能通过调用子函数来实现
用switch来实现菜单的选择
一切数据信息通通存在文件中,并实现文件读写操作。
设计子函数来实现查询,保存,读取数据,删除等操作。
【总体设计】
图1系统功能模块图
【详细设计】
1.主函数
主函数设计要求简洁,只提供部分提示语和函数的调用
【程序】
具体设计如下:
结构体设计
structgoods
{intnumber;
charname[20];
intshumu;
floatjiage;
structgoods*next;
};
主函数设计
voidmain()
{
voidjieman();
voidluru();
structgoods*shuju();
voidshanchu(structgoods*head);voidjinghuo(structgoods*head);voidxiaoshu(structgoods*head);voidxiugai(structgoods*head);voidchaxun(structgoods*head);structgoods*head=NULL;
intk=0;
system("cls");jieman();
printf("请选择你要的功能键:
");scanf("%d",&k);getchar();while(k!
=0)
{
head=shuju();switch(k)
{case1:
luru();break;
case2:
xiugai(head);break;
case3:
chaxun(head);break;
case4:
xiaoshu(head);break;
case5:
jinghuo(head);break;
case6:
shanchu(head);break;
case0:
exit(0);
default:
printf("pleasetryagain!
\n");
}
jieman();
printf("请选择你要的功能键:
");
scanf("%d",&k);
}
}
界面设计
voidjieman()
printf("☆☆☆★★★欢迎进入商品管理系统★★★☆☆☆\n");
printf("**1*录入信息少^***************★★★☆☆☆\n");
printf("**2*
彳修改信息***************
★★★☆☆☆\n");
printf("**3*
询信息***************
★★★☆☆☆\n");
printf("**4*
卡肖隹彳主息***************
★★★☆☆☆\n");
printf("**5*
^进货信息***************
★★★☆☆☆\n");
printf("**6*
删除信息少^***************
★★★☆☆☆\n");
printf("**0*
■退出系统***************
★★★☆☆☆\n");
printf("☆☆☆★★★欢迎进入商品管理系统\n");
\n");
printf(
文件保存函数设计
structgoods*baocun(structgoods*head){
structgoods*shuju();
structgoods*p=NULL;
FILE*fp=NULL;
charch='\0';
getchar();
printf("是否保存到文件?
(y/n):
");
ch=getchar();
putchar(10);
if(ch=='y'||ch=='Y')
{
fp=fopen("goods.txt","wb");
p=head;
if((fp==NULL)&&(p==NULL))
{
printf("读取数据失败!
");
exit(0);
}
while(p!
=NULL)
{
fprintf(fp,"%d\n%s\n%d\n%f\t",p->number,p->name,p->shumu,p->jiage);
p=p->next;
}
printf("保存成功!
\n");
fclose(fp);
return(head);
}
elseif(ch=='n'||ch=='N')
{
printf("信息未保存到文件!
\n");
head=shuju();
return(head);
}
else
{
printf("sorry,pleasetryagain(y/n):
");
ch=getchar();
putchar(10);
}
return(head);
}
数据读取函数设计
structgoods*shuju()
{
intn=0;
FILE*fp;
structgoods*head=NULL,*p1,*p2;
fp=fopen("goods.txt","rb");
if(fp==NULL)
{
printf("\nsorry,读取数据失败!
\n");exit(0);
}
else
{
p1=p2=(structgoods*)malloc(LEN);
fscanf(fp,"%d%s%d%f",&p1->number,p1->name,&p1->shumu,&p1->jiage);
while(!
feof(fp))
{
n++;
if(n==1)head=p1;
elsep2->next=p1;
p2=p1;
p1=(structgoods*)malloc(LEN);
fscanf(fp,"%d%s%d%f",&p1->number,p1->name,&p1->shumu,&p1->jiage);
}
p2->next=NULL;fclose(fp);return(head);
}
}
录入函数设计
voidluru()
{structgoods*shuju();
structgoods*baocun(structgoods*head);
structgoods*p1,*p2,*p3;
head=shuju();
p1=head;
p2=(structgoods*)malloc(LEN);
printf("请输入四位编号:
");
scanf("%d",&p2->number);printf("请输入商品名:
");
scanf("%s",p2->name);printf("请输入商品数量:
");scanf("%d",&p2->shumu);printf("请输入商品价格:
");
scanf("%f",&p2->jiage);
if(p1==NULL)
{p1=p2;
p2->next=NULL;
baocun(p2);
return;
}
while(p1!
=NULL)
{p3=p1;p1=p1->next;}p3->next=p2;
p2->next=NULL;
baocun(head);
}
进货函数设计voidjinghuo(structgoods*head)
{structgoods*baocun(structgoods*head);
intc;
intp;
structgoods*p1,*p2;
system("cls");
printf("请输入四位编号:
");
scanf("%d",&p);
p1=head;
while(p!
=p1->number&&p1->next!
=NULL)
{
p2=p1;
p1=p1->next;
}
if(p==p1->number)
{
printf("\n商品编号\t商品名\t数量\t价格\n");
printf("%d\t\t%s\t\t%d\t\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage);
printf("请输入该商品经货个数:
");scanf("%d",&c);
p1->shumu=p1->shumu+c;
printf("该商品经货个数:
%d\n",p1->shumu);}
baocun(head);
}
删除函数设计
voidshanchu(structgoods*head)
{structgoods*p1,*p2;
structgoods*baocun(structgoods*head);intp;
system("cls");
printf("请输入四位编号:
");
scanf("%d",&p);
p1=head;
while(p!
=p1->number&&p1->next!
=NULL)
{p2=p1;p1=p1->next;}
if(p==p1->number)
价格
{printf("\n商品编号\t商品名\t数量\t\n");
printf("%d\t\t%s\t\t%d\t\t%.2f\n",p1->number,p1->name,p1->shumu,p1->jiage);
if(p1==head)head=p1->next;
elsep2->next=p1->next;n=n-1;
}
printf("删除成功!
\n");
baocun(head);
}
查询函数设计
voidchaxun(structgoods*head)inta,c,i=0;
structgoods*p1,*p2;
chart[20];
printf("1*商品编号查询\n");
printf("2*商品名字查询\n");
printf("请选择你需要的功能键\n");
scanf("%d",&a);
getchar();
if(a==1)
{
printf("请输入四位编号:
");
scanf("%d",&c);getchar();
while(c!
=0&&i==0)
{
p1=head;
while(c!
=p1->number&&p1->next!
=NULL)
{p2=p1;p1=p1->next;}
if(c==p1->number)
价格:
\n");
{printf("\n商品编号\t名字\t数目\tprintf("%d\t%s\t%d\t%.2f\n",p1->number,p1->name,p1->shumu,p1->jiage);i=1;}
enter
else{printf("系统中无该商品记录!
pressreturn!
\n");getchar();system("cls");return;}
}
}
if(a==2&&i==0)
{
system("cls");printf("请输入商品名字:
");
scanf("%s",&t);getchar();
while(strcmp(t,"0")!
=0&&i==0)
{
p1=head;
if(strcmp(t,p1->name)!
=0&&p1->next!
=NULL)
{
p2=p1;p1=p1->next;
}
if(strcmp(t,p1->name)==0)
{
printf("\n商品编号\t名字\t数目\t价格:
\n");
printf("%d\t%s\t%d\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage);i=1;}
enter
else{printf("系统中无该商品记录!
pressreturn!
\n");getchar();system("cls");return;}
}
}
}
修改函数设计
voidxiugai(structgoods*head)
{structgoods*baocun(structgoods*head);
intp,i=0;
structgoods*p1,*p2;
system("cls");
printf("请输入四位编号:
");
scanf("%d",&p);
getchar();
if(p!
=0)
{
p1=head;
while(p!
=p1->number&&p1->next!
=NULL)
{
p2=p1;
p1=p1->next;
if(p==p1->number)
{printf("\n商品编号\t名字\t数目\t价格:
\n");
printf("%d\t%s\t%d\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage);
printf("请输入要修改的新商品编号");
scanf("%d",&p1->number);
i=1;
}
if(i==1)
{
printf("修改后新商品编号名字数目价格:
\n");
printf("%d%s%d%f",p1->number,p1->name,p1->shumu,p1->jiage);
printf("修改成功!
\n");
baocun(head);
}
}
销售函数设计
voidxiaoshu(structgoods*head)
{structgoods*baocun(structgoods*head);intc;
intp;
structgoods*p1,*p2;
system("cls");
printf("请输入四位编号:
");scanf("%d",&p);
getchar();
p1=head;
while(p!
=p1->number&&p1->next!
=NULL){
p2=p1;
p1=p1->next;
}
if(p==p1->number)
{
printf("\n商品编号\t商品名\t数量\t价格\n");
printf("%d\t\t%s\t\t%d\t\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage);
printf("请输入该商品售货个数:
");
scanf("%d",&c);
p1->shumu=p1->shumu-c;
printf("该商品经货个数:
%d\n",p1->shumu);
}
baocun(head);
}
三程序清单
#include
#include
#include
#include
#defineLENsizeof(structgoods)structgoods结构体
{intnumber;商品编号
charname[20];商品名intshumu;商品数目floatjiage;商品价格structgoods*next;
};
intn,k;全局变量
structgoods*head;全局变量
voidmain()主函数
{
voidjieman();界面函数声明
voidluru();录入函数声明
structgoods*shuju();数据读取函数声明
voidshanchu(structgoods*head);删除函数声明
voidjinghuo(structgoods*head);进货函数声明
销售函数声明
修改函数声明
查询函数声明
voidxiaoshu(structgoods*head);voidxiugai(structgoods*head);voidchaxun(structgoods*head);structgoods*head=NULL;intk=0;
system("cls");jieman();
printf("请选择你要的功能键:
");scanf("%d",&k);getchar();while(k!
=0)
{
head=shuju();switch(k)
{case1:
luru();break;
case2:
xiugai(head);break;
case3:
chaxun(head);break;
case4:
xiaoshu(head);break;
case5:
jinghuo(head);break;
case6:
shanchu(head);break;case0:
exit(0);
default:
printf("pleasetryagain!
\n");
}
jieman();
printf("请选择你要的功能键:
");
scanf("%d",&k);
}
}structgoods*baocun(structgoods*head){
structgoods*shuju();
structgoods*p=NULL;
FILE*fp=NULL;
charch='\0';
getchar();
printf("是否保存到文件?
(y/n):
");ch=getchar();
putchar(10);
保存函数
判断是否保存
if(ch=='y'||ch=='Y')
fp=fopen("goods.txt","wb");
p=head;
if((fp==NULL)&&(p==NULL))
{
printf("读取数据失败!
");
exit(0);
}
while(p!
=NULL)
{
fprintf(fp,"%d\n%s\n%d\n%f\t",p->number,p->name,p->shumu,p->jiage);
p=p->next;
}
printf("保存成功!
\n");
fclose(fp);
return(head);
}
elseif(ch=='n'||ch=='N')
{
printf("信息未保存到文件!
\n");
head=shuju();
return(head);
}
else
{
printf("sorry,pleasetryagain(y/n):
");ch=getchar();
putchar(10);
}
return(head);
}
voidchaxun(structgoods*head)查询函数
{
inta,c,i=0;
structgoods*p1,*p2;
chart[20];
printf("1*商品编号查询\n");
printf("2*商品名字查询\n");
printf("请选择你需要的功能键\n");scanf("%d",&a);
getchar();
if(a==1)
{
printf("请输入四位编号:
");
scanf("%d",&c);getchar();
while(c!
=0&&i==0)
{
p1=head;
while(c!
=p1->number&&p1->next!
=NULL)查找商品{p2=p1;p1=p1->next;}
if(c==p1->number)
{printf("\n商品编号\t名字\t数目\t价格:
\n");
printf("%d\t%s\t%d\t%.2f\n",p1->number,p1->name,p1->shumu,p1->jiage);i=1;}
enter
else{printf("系统中无该商品记录!
pressreturn!
\n");getchar();system("cls");return;}
}
}
if(a==2&&i==0)
system("cls");printf("请输入商品名字:
");scanf("%s",&t);getchar();
while(strcmp(t,"0")!
=0&&i==0)
{
p1=head;
if(strcmp(t,p1->name)!
=0&&p1->next!
=NULL)查找商品{
p2=p1;p1=p1->next;
}
if(strcmp(t,p1->name)==0)
{
printf("\n商品编号\t名字\t数目\t价格:
\n");
printf("%d\t%s\t%d\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage);i=1;}
enter
else{printf("系统中无该商品记录!
pressreturn!
\n");getchar();system("cl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 程序 课程设计 商品 进销存 管理 系统