C语言-宠物商店管理系统-实训报告(共14页).doc
精选优质文档-倾情为你奉上实 训 报 告实训项目:宠物商店管理系统院别专业:信息管理学院班级学号:学生姓名:煜指导教师:实训成绩:实验日期:2018年6月8日制信息管理学院实践教学中心一、 实训目的:1掌握C语法,函数,界面程序设计,文件操作。2掌握C文件编程方法。二、 实训内容及要求:用C语言设计基于文件的宠物商店管理系统。要求具有信息显示、录入、修改、查询和删除的界面并完成相关功能。三、实训方案:系统功能结构、主要界面与主要代码:1.功能结构如下:以下图仅供参考,以实际所做的系统功能为准!2.主要功能介绍:(1)添加宠物类型。(2)修改宠物类型。(3)显示添加的全部宠物类型。(4)显示宠物全部的交易记录。(5)显示宠物月度交易统计数据。(6)显示主功能菜单3主要代码:#include<stdio.h>#include<time.h>#include<string.h>#define SIZE 3#define SIZET 100struct pettypeint typeId;char name20;int petstore;pettypesSIZE;struct pettransinfoint transId;int typeId;int num;int transtype;int year;int month;int day;pettransinfosSIZET;int getcurrenttypeindex();int getcurrenttypeinfoindex();int getcurrenttransinfoindex();/*添加宠物类型*/void tjcwlx();/*修改宠物类型*/void xgcwlx();/*显示全部的宠物类型*/void tjqbdcwlx();/*添加宠物进货记录*/void tjcwxsjl();/*添加宠物销售记录*/void xscwqbjyjl();/*显示宠物全部交易记录*/void xscwjytjxx();/*显示宠物交易统计信息*/void xszgncd();/*显示主功能菜单*/void showmenu();int istypeexistsbyId(int typeId);int updatepetstore(int typeId,int num);int main(int argc,const char * argv)showmenu();return 0;void showmenu()int n;do system("cls");printf(" *n");printf(" * 欢迎使用宠物商店 *n");printf(" * = *n");printf(" * 1.添加宠物类型 *n");printf(" * 2.修改宠物类型 *n");printf(" * 3.显示全部宠物类型 *n");printf(" * 4.添加宠物进货记录 *n");printf(" * 5.添加宠物销售记录 *n");printf(" * 6.显示宠物全部交易记录 *n");printf(" * 7.显示宠物月度交易统计数据 *n");printf(" * 8.退出 *n");printf(" *n");printf("请选择您需要的操作:");scanf("%d",&n);switch(n)case 1:tjcwlx();break;case 2:xgcwlx();break;case 3:tjqbdcwlx();break;case 4:tjcwxsjl();break;case 5:xscwqbjyjl();break;case 6:xscwjytjxx();break;case 7:xszgncd();break;case 8:printf("欢迎你再次使用宠物商店系统n");return;default:break; printf("按回车继续!n"); fflush(stdin); getchar(); getchar();while(1);/*添加宠物类型*/void tjcwlx() int typeId;char typeName20;typeId=getcurrenttypeindex();if(typeId=-1)printf("当前宠物类型的数量已达上限,无法再次添加!n");return ;printf("请输入新增宠物类型:");scanf("%s",typeName);pettypestypeId-1.typeId=typeId;strcpy(pettypestypeId-1.name,typeName); pettypestypeId-1.petstore=0; printf("新宠物类型%s,已经添加成功!n", typeName);/*修改宠物类型*/void xgcwlx()int typeId; char typeName20;printf("请输入需要修改宠物类型编号:"); scanf("%d",&typeId);if(istypeexistsbyId(typeId)=-1)printf("当前系统不存在您输入的宠物类型编号!n");return;elseprintf("名称:%sn", pettypestypeId - 1.name);printf("请输入修改后的宠物名称:");scanf("%s",typeName);strcpy(pettypestypeId-1.name,typeName);printf("编号是%d的宠物类型名称已经改成%s!n", typeId,typeName);/*显示全部的宠物类型*/void tjqbdcwlx()int i;printf("类型编号t类型名称n");for(i=0;i<SIZE;i+)if(pettypesi.typeId=0)break;printf("%3dtt%sn",pettypesi.typeId,pettypesi.name);/*添加宠物进货记录*/void tjcwxsjl()int transId;int typeId;int purchasenum;time_t tp;struct tm *p;time(&tp);p = localtime(&tp);transId=getcurrenttransinfoindex();if(transId=-1)printf("宠物交易记录次数已经达到上限,无法再次进货!");return ;printf("请输入本次进货的宠物类型编号:");scanf("%d",&typeId);if(istypeexistsbyId(typeId)=-1)printf("当前系统不存在您输入的宠物类型编号!n");return;printf("请输入本次宠物进货的数量:");scanf("%d",&purchasenum);if(purchasenum<1)printf("进货数量不能小于1,操作失败!n");return ;time(&tp);p=gmtime(&tp);pettransinfostransId-1.year=p->tm_year+1900;pettransinfostransId-1.month=p->tm_mon+1;pettransinfostransId-1.day=p->tm_mday; /strftime(pettransinfostransId - 1.data, sizeof(pettransinfostransId - 1.data), "%Y-%m-%d", localtime(&tp);pettransinfostransId-1.transId=transId;pettransinfostransId-1.typeId=typeId;pettransinfostransId-1.num=purchasenum;pettransinfostransId-1.transtype=0;updatepetstore(typeId,purchasenum,1);printf("本次宠物进货完成记录!");/*添加宠物销售记录*/void xscwqbjyjl()int transId;int typeId;int purchasenum;time_t tp;struct tm *p;time(&tp);p = localtime(&tp);transId = getcurrenttransinfoindex();if (transId = -1)printf("宠物交易记录次数已经达到上限,无法再次销售!");return;printf("请输入本次销售的宠物类型编号:");scanf("%d", &typeId);if (istypeexistsbyId(typeId) = -1)printf("当前系统不存在您输入的宠物类型编号!n");return;printf("请输入本次销售的宠物数量:");scanf("%d", &purchasenum);if (purchasenum>pettypestypeId-1.petstore)printf("当前该类型宠物的库存数量不足,无法进行销售!n");return;time(&tp);p = gmtime(&tp);pettransinfostransId - 1.year = p->tm_year + 1900;pettransinfostransId - 1.month = p->tm_mon + 1;pettransinfostransId - 1.day = p->tm_mday;/strftime(pettransinfostransId - 1.data, sizeof(pettransinfostransId - 1.data), "%Y-%m-%d", localtime(&tp);pettransinfostransId - 1.transId = transId;pettransinfostransId - 1.typeId = typeId;pettransinfostransId - 1.num = purchasenum;pettransinfostransId - 1.transtype = 1;updatepetstore(typeId, purchasenum,2);printf("本次宠物销售完成记录!");/*显示宠物全部交易记录*/void xscwjytjxx()int i;char *name;printf("宠物编号t宠物名称t交易数量t交易日期t交易类型n");for (i = 0; i<SIZET; i+)if (pettransinfosi.transId = 0)break;if (pettransinfosi.transtype = 0)name = "入库"else if(pettransinfosi.transtype = 1)name = "售出"elsename = "未知"printf("%3dtt%stt%3dtt%d-%d-%dt%sn", pettransinfosi.typeId, pettypespettransinfosi.typeId-1.name,pettransinfosi.num, pettransinfosi.year, pettransinfosi.month, pettransinfosi.day, name);/*显示宠物交易统计信息*/void xszgncd()const char * split = "-"int i;char *name;int month;int j;int purchasenum=0;int salenum=0;printf("请输入需要查看的月份:");scanf("%d", &month);printf("类型编号t类型名称t入库数量t销售数量t库存数n");for (i = 0; i<SIZE; i+)if (pettypesi.typeId = 0)break;for (j = 0; j<SIZET; j+)if (pettransinfosj.transId = 0)break;if (pettransinfosj.month = month&&pettransinfosj.typeId = pettypesi.typeId)if (pettransinfosj.transtype = 0)purchasenum += pettransinfosj.num;elsesalenum+= pettransinfosj.num;printf("%3dtt%stt%3dtt%3dtt%3dn", pettypesi.typeId, pettypesi.name, purchasenum, salenum, purchasenum - salenum);int getcurrenttypeindex()int index=-1;int i;for(i=0;i<SIZE;i+) if(pettypesi.typeId=0)index=i+1;break;return index;int getcurrenttransinfoindex()int index = -1;int i;for (i = 0; i<SIZET; i+)if (pettransinfosi.transId = 0)index = i + 1;break;return index;int istypeexistsbyId(int typeId)if(typeId<1 | typeId>SIZE | pettypestypeId-1.typeId=0)return -1;elsereturn 1;int updatepetstore(int typeId,int num,int recordtype)int count;count=pettypestypeId-1.petstore;if (recordtype = 1)count += num;else count -= num;if(count>=0)pettypestypeId-1.petstore=count;return count;四、实训结果与分析:系统运行截图:系统运行结果说明:本系统为宠物商店提供对宠物进行统计的功能,通过本系统卖家可以实现对宠物类型.进货记录.销售记录的添加,可以查询销售记录.全部交易记录.月度交易统计数据功能。五、 实训心得:本学系统是宠物商店系统。通过本次实训本人学会了如何应用链表,循环等,先构建系统大概结构。会独自分析问题解决问题,提高解决问题的能力提高分析问题和解决问题的能力,提高程序设计水平,遇到问题及时询问老师同学。 六、教师评语: 成 绩主讲教师: 2018年 6月8日专心-专注-专业