C语言宠物商店管理系统实训报告Word格式.docx
《C语言宠物商店管理系统实训报告Word格式.docx》由会员分享,可在线阅读,更多相关《C语言宠物商店管理系统实训报告Word格式.docx(15页珍藏版)》请在冰豆网上搜索。
#include<
stdio.h>
#include<
time.h>
#include<
string.h>
#defineSIZE3#defineSIZET100structpettype
{
inttypeId;
charname[20];
intpetstore;
}pettypes[SIZE];
structpettransinfo{inttransId;
inttypeId;
intnum;
inttranstype;
intyear;
intmonth;
intday;
}pettransinfos[SIZET];
intgetcurrenttypeindex();
intgetcurrenttypeinfoindex();
intgetcurrenttransinfoindex();
/*添加宠物类型*/voidtjcwlx();
/*修改宠物类型*/
voidxgcwlx();
/*显示全部的宠物类型*/
voidtjqbdcwlx();
/*添加宠物进货记录*/
voidtjcwxsjl();
/*添加宠物销售记录*/
voidxscwqbjyjl();
/*显示宠物全部交易记录*/
voidxscwjytjxx();
/*显示宠物交易统计信息*/
voidxszgncd();
/*显示主功能菜单*/
voidshowmenu();
intistypeexistsbyld(inttypeld);
intupdatepetstore(inttypeld,intnum);
intmain(intargc,constchar*argv[]){
showmenu();
return0;
}
voidshowmenu()
intn;
do
system("
cls"
);
printf("
*欢迎使用宠物商店
*\n"
*・
\n);
*
1.
添加宠物类型
2.
修改宠物类型
3.
显示全部宠物类型
4.
添加宠物进货记录
5.
添加宠物销售记录
6.
显示宠物全部交易记录*\n"
7.
显示宠物月度交易统计数据*\n"
printf("
8.
退出
*****************************************
printf(”请选择您需要的操作:
"
scanf("
%d"
&
n);
switch(n)
case1:
tjcwlx();
break;
case2:
xgcwlx();
case3:
tjqbdcwlx();
case4:
tjcwxsjl();
case5:
xscwqbjyjl();
case6:
xscwjytjxx();
case7:
xszgncd();
case8:
欢迎你再次使用宠物商店系统\n"
return;
default:
按回车继续!
\n"
fflush(stdin);
getchar();
/*添加宠物类型*/
voidtjcwlx()
inttypeld;
chartypeName[20];
typeld=getcurrenttypeindex();
if(typeld==-1)
当前宠物类型的数量已达上限,无法再次添加!
return;
请输入新增宠物类型:
%s"
typeName);
pettypes[typeld-1].typeld=typeld;
strcpy(pettypes[typeId-1].name,typeName);
pettypes[typeld-1].petstore=0;
新宠物类型%s,已经添加成功!
typeName);
};
voidxgcwlx()
请输入需要修改宠物类型编号:
&
typeld);
if(istypeexistsbyId(typeId)==-1)
当前系统不存在您输入的宠物类型编号!
else
名称:
%s\n"
pettypes[typeld-1].name);
请输入修改后的宠物名称:
scanf("
编号是%d的宠物类型名称已经改成%s!
\n"
typeId,typeName);
voidtjqbdcwlx()
inti;
类型编号\t类型名称\n"
for(i=0;
i<
SIZE;
i++)
if(pettypes[i].typeId==0)
%3d\t\t%s\n"
pettypes[i].typeld,pettypes[i].name);
voidtjcwxsjl()
inttransId;
intpurchasenum;
time_ttp;
structtm*p;
time(&
tp);
p=localtime(&
transld=getcurrenttransinfoindex();
if(transId==-1)
宠物交易记录次数已经达到上限,无法再次进货!
"
请输入本次进货的宠物类型编号:
typeId);
if(istypeexistsbyld(typeld)==-1)
请输入本次宠物进货的数量:
purchasenum);
if(purchasenum<
1)
printf(”进货数量不能小于1,操作失败!
p=gmtime(&
tp);
pettransinfos[transld-1].year=p->
tm_year+1900;
pettransinfos[transld-1].month=p->
tm_mon+1;
pettransinfos[transld-1].day=p->
tmmday;
〃strftime(pettransinfos[transld-1].data,sizeof(pettransinfos[transld
1].data),"
%Y-%m-%d"
localtime(&
&
tp));
pettransinfos[transId-1].transId=transld;
pettransinfos[transld-1].typeld=typeld;
pettransinfos[transld-1].num=purchasenum;
pettransinfos[transld-1].transtype=0;
updatepetstore(typeld,purchasenum,1);
printf("
本次宠物进货完成记录!
voidxscwqbjyjl(){
inttransld;
transld=getcurrenttransinfoindex();
if(transld==-1)
宠物交易记录次数已经达到上限,无法再次销售!
请输入本次销售的宠物类型编号:
if(istypeexistsbyld(typeld)==-1)
请输入本次销售的宠物数量:
if(purchasenum>
pettypes[typeld-1].petstore)
当前该类型宠物的库存数量不足,无法进行销售!
p=gmtime(&
pettransinfos[transld-1].year=p->
tm_year+1900;
pettransinfos[transld二1].month=p->
tmmon+1;
pettransinfos[transld-1].day=p->
tm_mday;
〃strftime(pettransinfos[transld-1].data,sizeof(pettransinfos[transld
pettransinfos[transld-1].transld=transId;
pettransinfos[transld-1].typeld=typeld;
pettransinfos[transld-1].num=purchasenum;
pettransinfos[transld-1].transtype=1;
updatepetstore(typeld,purchasenum,2);
本次宠物销售完成记录!
voidxscwjytjxx(){
char*name;
宠物编号\t宠物名称\t交易数量\t交易日期\t交易类型\n"
for(i=0;
ivSIZET;
i++)
if(pettransinfos[i].transld==0)
if(pettransinfos[i].transtype==0)
name="
入库"
;
elseif(pettransinfos[i].transtype==1)
售出"
未知"
;
%3d\t\t%s\t\t%3d\t\t%d-%d-%d\t%s\n"
pettransinfos[i].typeld,
pettypes[pettransinfos[i].typeId-1].name,pettransinfos[i].num,
pettransinfos[i].year,pettransinfos[i].month,pettransinfos[i].day,name);
voidxszgncd(){
constchar*split="
-"
intmonth;
intj;
intpurchasenum=0;
intsalenum=0;
请输入需要查看的月份:
month);
类型编号\t类型名称\t入库数量\t销售数量\t库存数\n"
ivSIZE;
if(pettypes[i].typeld==0)
for(j=0;
jvSIZET;
j++)
if(pettransinfos[j].transld==0)
if(pettransinfos[j].month==month&
pettransinfos[j].typeId
pettypes[i].typeId)
if(pettransinfos[j].transtype==0)
purchasenum+=pettransinfos[j].num;
salenum+=pettransinfos[j].num;
%3d\t\t%s\t\t%3d\t\t%3d\t\t%3d\n"
pettypes[i].typeld,
pettypes[i].name,purchasenum,salenum,purchasenum-salenum);
intgetcurrenttypeindex()
intindex=-1;
if(pettypes[i].typeld==0)
index=i+1;
break;
returnindex;
intgetcurrenttransinfoindex()
intindex=-1;
index=i+1;
intistypeexistsbyld(inttypeId)
if(typeId<
1||typeId>
SIZE||pettypes[typeld-1].typeld==0){
return-1;
return1;
intupdatepetstore(inttypeId,intnum,intrecordtype)
intcount;
count=pettypes[typeId-1].petstore;
if(recordtype==1)
count+=num;
count-=num;
if(count>
=0)
pettypes[typeld-1].petstore=count;
}returncount;
四、实训结果与分析:
系统运行截图:
禎迎使冃宜物痔古
:
4簡录“更務完:
T零进
青请-+^>
4-
15
i;
ml.
s.§
僞塾垂
逞人拥车
進却基回
系统运行结果说明:
本系统为宠物商店提供对宠物进行统计的功能,通过本系统卖家可以实现对宠物类型•进货记录.销售记录
的添加,可以查询销售记录•全部交易记录•月度交易统计数据功能。
五、实训心得:
本学系统是宠物商店系统。
通过本次实训本人学会了如何应用链表,循环等,先构建系统大概结构。
会独自分析问题解决问题,提高解决问题的能力提高分析问题和解决问题的能力,提高程序设计水平,遇到问题及时询问老师同学。
六、教师评语:
成绩
主讲教师:
2018年6月8日