版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include #include #include #include struct produce_node /* 定义物品信息结构体produce_node*/ int id; char name20; char produce30; int number; double price; double price1; struct produce_node *next; ; struct ima /* 定义物品信息结构体ima*/ int id; char name20; char produce30; int number; double price; double price1; str
2、uct ima *next; ; void liren(); /* 超市信息管理系统的所有的函数声明*/ void chushou(int count); void append(); void selldelete(); void amend(); void findin(); void browse(); void colorsetting(); void endprogram(); void zonghe(); struct produce_node * lianbiao(); struct produce_node *create_produce_doc(); struct produ
3、ce_node *insertdoc(struct produce_node *head,struct produce_node *produce); struct produce_node *deletedoc(struct produce_node *head,int num); void menu() /* 系统主菜单的定义*/ int choice; printf(n 【超市库存管理系统】n); printf(-系统菜单显示如下-); printf(nt= 【新购物品入库】n); printf(nt= 【物品信息删除】n); printf(nt= 【物品信息修改】n); printf(
4、nt= 【物品信息查询】n); printf(nt= 【物品信息浏览】n); printf(nt= 【系统颜色设置】n); printf(nt= 【应用程序退出】n); printf(nt= 【物品价值总和浏览】n); printf(nt= 【物品的出售管理】n); printf(nt= 【物品的预计的利润】n); printf(nt请输入您要选择的菜单.); scanf(%d,&choice); switch(choice) /* 用 switch 语句对功能函数进行调用*/ case 1: append(); break; case 2: selldelete(); break;
5、case 3: amend(); break; case 4: findin(); break; case 5: browse(); break; case 6: colorsetting(); break; case 7: endprogram(); break; case 8: zonghe(); break; case 9: int i; printf( 请输入您要卖出的数量:); scanf(%d,&i); chushou(i); break; case 10: liren(); break; default: printf(nttttt输入无效,请您重新输入.); getch
6、(); system(cls);/* 清屏并且返回到主菜单*/ menu(); void colorsetting()/* 系统的颜色设置*/ int a; char choice; system(cls); printf(nntt选择以下方案 n); printf(nntt1*红底黑字 n); printf(nntt2*白底黑字 n); printf(nntt3*黑底红字 n); printf(nntt4*绿底蓝字 n); printf(nntt5*黄底紫字 n); printf(nntt6*系统默认 n); printf(nnttttt请挑选您喜爱的颜色.); scanf(%d,&
7、a); switch(a) /* 用 switch 函数对颜色进行设置*/ case 1: system(color 40); break; case 2: system(color 70); break; case 3: system(color 04); break; case 4: system(color 21); break; case 5: system(color 65); break; case 6: system(color 1a); break; default: printf(nnttttt输入无效 ,重新输入 .); getch(); colorsetting(); p
8、rintf(n选择的颜色您还满意吗?(y 返回主菜单 /n 继续选择 ); scanf( %c,&choice); if(choice=y|choice=y)/*用 if 语句选择是否返回主菜单或者继续设置*/ system(cls); menu(); else colorsetting(); int validateid(int id)/*判断系统文件中是否已经存在此条数据,或者是有同名的序列号*/ file *fp; struct ima i; fp=fopen(ima.date,r); if(fp=null) /* 打开文件 */ printf(ttt系统错误,请您重试.); e
9、xit(0); fread(&i,sizeof(struct ima),1,fp);/*读取文件中的数据*/ while(!feof(fp)/*如果数据已经存在则返回是1*/ if(i.id=id) fclose(fp); return 1; break; fread(&i,sizeof(struct ima),1,fp);/*读取文件中的数据*/ fclose(fp);/* 关闭文件 */ return 0; void append()/* 物品入库函数*/ struct produce_node *i; /* 定义一个结构体的指针*/ struct produce_node
10、 j; /* 定义一个结构体变量*/ i=&j; /* 将结构体的变量的地址赋值给指针*/ char choice; file *fp; /* 定义文件指针*/ fp=fopen(ima.date,ab); /* 打开文件 */ if(fp=null) printf(ttt系统错误,请您重试.); /* 如果文件是空的就结束程序*/ exit(0); labid: printf(nt请您输入要入库物品的信息.n); printf(tttt 物品的编号 :); scanf(%d,&j.id); if(validateid(j.id)=1) /* 调用函数对数据编号判断是否存在*/
11、 printf(tttt此编号已被使用,请您重新输入.n); goto labid; else printf( *此编号没有被使用您可以使用*n); i=lianbiao(); /* 调用链表函数对i 进行赋值 */ while(i!=null) fwrite(i,sizeof(struct produce_node),1,fp);/*将 i 中的数据读入文件*/ i=i-next; /* 将 i 指针指向链表中的下一条语句 */ fclose(fp);/* 关闭文件 */ printf(tttttt 物品信息已入库成功!n); free(i); printf(n您想继续吗 ?(y/n); s
12、canf( %c,&choice); if(choice=y|choice=y)/*if语句选择是否继续录入或者进入主菜单*/ append(); else system(cls); menu(); void selldelete()/* 物品信息删除函数*/ struct ima i1000; struct ima temp; int delid; char choice; int index=0; int j=0; file *fp; fp=fopen(ima.date,r);/*打开文件 */ if(fp=null) printf(ttt系统错误,请您重试.); exit(0);
13、 fread(&temp,sizeof(struct ima),1,fp);/*读取文件中的数据*/ while(!feof(fp) iindex=temp; index+; fread(&temp,sizeof(struct ima),1,fp);/*将文件中的数据全部存放到数组中*/ fclose(fp);/* 关闭文件 */ printf(nt请输入要删除的物品的编号:); scanf(%d,&delid); fopen(ima.date,w);/*打开文件 */ if(fp=null) printf(ttt系统错误,请您重试.); exit(0); for( j
14、=0;jindex;j+) /* 对数组中的数据依次进行比对找到要删除的数据编号*/ if(ij.id!=delid) fwrite(&ij,sizeof(struct ima),1,fp);/* 如果不满足条件就将信息重新写入文件*/ fclose(fp); printf(ttttt物品信息已清除!n); printf(n您想继续吗 ?(y/n); scanf( %c,&choice); if(choice=y|choice=y) selldelete(); else system(cls); menu(); void amend()/* 物品信息修改函数*/ int ind
15、ex=0; int id,j; char choice; struct ima i1000; struct ima temp; file *fp; fp=fopen(ima.date,r);/*打开文件 */ if(fp=null) printf(ttt系统错误,请您重试.); exit(0); fread(&temp,sizeof(struct ima),1,fp);/*读取文件中的数据到数组中*/ while(!feof(fp) iindex=temp; index+; fread(&temp,sizeof(struct ima),1,fp); fclose(fp); fp
16、=fopen(ima.date,w); if(fp=null) printf(ttt系统错误,请您重试.); exit(0); printf(nt请输入要修改的信息的物品的编号:); scanf(%d,&id); for(j=0;j=index-1;j+) /* 对数组中的数据进行比对,如果序列号不相等就写入文件 */ if(ij.id!=id) fwrite(&ij,sizeof(struct ima),1,fp); else /* 如果相等就进行修改并写入文件*/ printf(tt物品名称修改为:); scanf(%s,); printf(tt物品生产地修改
17、为:); scanf(%s,duce); printf(tt物品数量修改为:); scanf(%d,&ij.number); printf(tt物品进货单价修改为:); scanf(%lf,&ij.price); printf(tt物品出售单价修改为:); scanf(%lf,&ij.price1); fwrite(&ij,sizeof(struct ima),1,fp); fclose(fp); printf(tttt物品信息已修改.); printf(n您想继续吗 ?(y/n); scanf( %c,&choice); if(choice
18、=y|choice=y) amend(); else system(cls); menu(); void findin()/* 物品信息查询函数*/ int a=0; file *fp; int findid;char choice;struct ima i; fp=fopen(ima.date,r); if(fp=null) printf(ttt系统错误,请你重试.); exit(0); printf(nt请输入要查询的物品的编号.); scanf(%d,&findid); fread(&i,sizeof(struct ima),1,fp);/*将数据读出来 */ while
19、(!feof(fp) if(i.id=findid)/* 找到匹配的编号并且输出*/ a=1; printf(nnt*物品信息 *); printf(nt物品编号 .%30dn,i.id); printf(nt-); printf(nt物品名称 .%30sn,); printf(nt-); printf(nt生产厂家 .%30sn,duce); printf(nt-); printf(nt进口数量 .%30dn,i.number); printf(nt-); printf(nt进货价格 .%30.3fn,i.price); printf(nt-); printf(nt出售
20、价格 .%30.3fn,i.price1); printf(nt-); printf(n您想继续吗 ?(y/n); scanf( %c,&choice); if(choice=y|choice=y) findin(); else system(cls); menu(); fread(&i,sizeof(struct ima),1,fp);/*文件没有读完则继续读出*/ fclose(fp); if(a!=1) printf(ttttt输入的编号不存在,请您重新输入.); printf(n您想继续吗 ?(y/n); scanf( %c,&choice); if(choic
21、e=y|choice=y) findin(); else system(cls); menu(); void browse()/* 物品信息浏览 */ struct ima i; int index=0; char choice; file *fp; fp=fopen(ima.date,r); if(fp=null) printf(ttt系统错误,请你重试.); exit(0); fread(&i,sizeof(struct ima),1,fp); while(!feof(fp)/*依次将文件中的数据输出*/ printf(nnt*物品信息 %d*,+index); printf(nt
22、物品编号 .%30dn,i.id); printf(nt-); printf(nt物品名称 .%30sn,); printf(nt-); printf(nt生产厂家 .%30sn,duce); printf(nt-); printf(nt进口数量 .%30dn,i.number); printf(nt-); printf(nt进货价格 .%30.3fn,i.price); printf(nt-); printf(nt出售价格 .%30.3fn,i.price1); printf(nt-); getch(); fread(&i,sizeof(struct ima),
23、1,fp); fclose(fp); printf(n您想继续吗 ?(y/n); scanf( %c,&choice); if(choice=y|choice=y) browse(); else system(cls); menu(); void zonghe()/* 物品的总价值浏览*/ struct ima i; double index=0; char choice; file *fp; fp=fopen(ima.date,r); if(fp=null) printf(ttt系统错误,请你重试.); exit(0); fread(&i,sizeof(struct ima)
24、,1,fp); while(!feof(fp)/*将每条物品的单价和数量做统计,并且求和*/ index=index+i.price*i.number; fread(&i,sizeof(struct ima),1,fp); fclose(fp); printf( 这是您的超市食品价格总和%lf,index); printf(n您想继续吗 ?(y/n)n); scanf( %c,&choice); if(choice=y|choice=y) zonghe(); else system(cls); menu(); void endprogram()/* 结束程序, 直接结束main
25、 函数, 不再调用别的函数,或者调用主菜单函数 */ char choice; system(cls); printf(nnnnnnnttt您确定要退出系统吗?nnnttt如果您想退出请按y,其它键将返回主菜单.); scanf( %c,&choice); if(choice=y|choice=y) system(cls); printf(nnnnnnnnnntttt谢谢您的使用 !); printf(nnnnnnnnnnnnnnnn); else system(cls); menu(); void main()/* 登录界面 */ printf(nn); system(color 1
26、a); printf(t3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3n); printf(t3 3n); printf(t3 3n); printf(t3 欢迎 使用3n); printf(t3 3n); printf(t3 3n); printf(t3 超 市 库 存 管 理 系 统3n); printf(t3 按 任 意 键 继 续3n); printf(t3 3n); printf(t3 3n); printf(t3 3n); printf(t3 3n); printf(t3 3n); printf(t
27、3 3n); printf(t3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3); getch(); system(cls); menu(); struct produce_node * lianbiao(void)/*链表的主函数 */ int i=0; struct produce_node *head;/*定义链表的头指针*/ struct produce_node *p; int id; int choice,number;double price;char name20;char produce 30;
28、double price1; int size=sizeof(struct produce_node);/*计算结构体的字节长度*/ do printf(*您要录入信息吗?请选一,要退出录入吗?请输入零* n);/*人性化界面,如果管理员不想录入了可以直接退出*/ f: i+; scanf(%d,&choice); if(choice=0&inumber=number; strcpy(p-name,name); p-price=price; p-price1=price1; p-id=id; strcpy(p-produce,produce); head=insertdoc(h
29、ead,p);/* 调用插入链表的函数,将刚刚录入的信息添加到链表中去 */ break; case 3: printf( 请输入产品序列号:n); scanf(%d,&id); head=deletedoc(head,id);/* 删除链表函数中的一条数据*/ break; case 0: break; if(choice!=0) printf( 您还要录入信息吗?请选二n); printf( 您要删除刚刚录入的信息?请选三n); printf( 您要停止录入吗?请选零n); goto f; while(choice!=0); if(head!=null)/* 如果管理员已经创建了链
30、表就返回头指针*/ return head; else return null; system(cls); /* 如果开始管理员就想放弃,则返回null*/ menu(); struct produce_node*create_produce_doc()/*创建链表 */ struct produce_node *head,*p; int number; int id; double price; double price1; char name20; char produce30; int size=sizeof(struct produce_node); head =null; print
31、f( 请输入 : 产品序列号 * 物品名称 * 物品产地 * 物品数量 * 物品进货价格*物品的出售价格:n); scanf(%d%s%s%d%lf%lf,&id,name,produce,&number,&price,&price1); while(number!=0) p=(struct produce_node*)malloc(size); /* 给 p 动态分配空间*/ p-number=number; /* 给 p 赋值,赋上物品的信息*/ strcpy(p-name,name); strcpy(p-produce,produce); p-price=
32、price; p-price1=price1; p-id=id; head=insertdoc(head,p);/* 调用插入链表函数,来判断当前形参中的head 是否是头指针 */ break; return head; struct produce_node*insertdoc(struct produce_node *head,struct produce_node *produce)/*插入链表函数 */ struct produce_node*ptr,*ptr1,*ptr2;/*定义物品信息结构体指针变量*/ ptr2=head;/* 将头指针赋给ptr2*/ ptr=produce
33、; if (head=null)/* 如果头指针为null,就将刚刚输入的produce 指针赋给头指针*/ head=ptr; head-next=null;/* 将头指针的下一个设为null*/ else while (ptr-id ptr2-id)&(ptr2-next !=null)/*将链表中的数据按照编号插入*/ ptr1=ptr2; ptr2=ptr2-next; if(ptr-idid)/*如果头指针没有经过while 语句的修改则进行头指针的替换*/ if(head=ptr2) head=ptr; else ptr1-next=ptr; ptr-next=ptr2;/
34、*将刚刚录入的信息按照编号排列,插入后,将后面的部分连到链表末尾 */ else ptr2-next=ptr; /* 将输入的信息添加到链表的后面*/ ptr-next=null; return head; struct produce_node *deletedoc(struct produce_node *head,int id)/*链表的删除函数*/ struct produce_node*ptr1,*ptr2; while(head!=null&head-id=id)/*如果头指针即是要删的数据就执行*/ ptr2=head; head=head-next; free(ptr2
35、); if(head=null)/* 判断 head 在删除后是否为空指针,是就返回null*/ printf( 删除成功 n); return null; ptr1=head; ptr2=head-next; while(ptr2!=null)/* 找到要删除的编号,用后面的指针覆盖他,并且释放掉本指针*/ if(ptr2-id=id) ptr1-next=ptr2-next; free(ptr2); else ptr1=ptr2; ptr2=ptr1-next; printf( 删除成功 n); return head; void chushou(int count)/*出售函数 */ struct ima i1000; int shuliang=0; struct ima temp; struct ima mm; int delid; double jine; char choice; int index=0; int j=0; file *fp; fp=fopen(ima.date,r); if(fp=null) printf(ttt系统错误,请您重试.); exit(0); fread(&temp,sizeof(struct
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年承德护理职业学院辅导员招聘考试真题汇编附答案
- 2024年海南政法职业学院辅导员招聘考试真题汇编附答案
- 2024年涞源县招教考试备考题库附答案
- 2025年三明学院辅导员考试笔试题库附答案
- 智能汽车维修工安全培训竞赛考核试卷含答案
- 2024年湖南农业大学辅导员考试参考题库附答案
- 2024年许昌市直机关遴选公务员笔试真题汇编附答案
- 2024年福州市特岗教师笔试真题题库附答案
- 2024年荣昌县特岗教师招聘考试真题汇编附答案
- 2024年阳江市直属机关遴选公务员笔试真题汇编附答案
- 河南豫能控股股份有限公司及所管企业2026届校园招聘127人考试备考题库及答案解析
- 2026浙江宁波市鄞州人民医院医共体云龙分院编外人员招聘1人笔试参考题库及答案解析
- (2025年)新疆公开遴选公务员笔试题及答案解析
- 物业管家客服培训课件
- 直销公司旅游奖励方案
- 解除劳动合同证明电子版(6篇)
- 呼吸科规培疑难病例讨论
- 有关中国居民死亡态度的调查报告
- 核对稿100和200单元概述
- 医学统计学(12)共143张课件
- 特种设备安全检查台账
评论
0/150
提交评论