#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#include <windows.h>
#include <string.h>
//小型超市库存销售管理系统void toxy(int x, int y);//光标移动void setup();//启动void mainmenu();//主菜单void menuONE();//库存管理void addcommodity();//增加商品
void addcommodity_sum();//增加库存
void printcommodity();//查看库存
void emptycommodity();//清空库存void menuTWO();//销售管理void reducecommodity_sum();//销售商品
void copyfile();//复制备用文件到原文件void resetsystem();//重置系统void aboutsystem();//关于系统typedef struct Commodity//商品
{char name[16];//商品名(不超过8字)double purchasing;//进价(不超过2位数)double selling;//售价(不超过2位数)int num;//余量
}commodity;double sale=0;//总销售额
double profit=0;//总利润int main()
{setup();while(1)mainmenu();return 0;
}void toxy(int x, int y)//将光标移动到x,y处
{COORD pos = { x , y };HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(Out, pos);
}void setup()//启动
{int i=6;toxy(40,3);printf("系统启动中");for(;i;i--){printf(".");Sleep(1000);}
}void mainmenu()//主菜单
{system("cls");printf("请输入需要进行的操作对应的序号\n");printf("1)库  存  管  理\n");printf("2)销  售  管  理\n");printf("3)重  置  系  统\n");printf("4)关  于  系  统\n");printf("按 ESC 退 出 系 统\n");printf(">>");char s=getch();printf("\n");switch(s){case 49:menuONE();break;case 50:menuTWO();break;case 51:resetsystem();break;case 52:aboutsystem();break;case 27:printf("感谢您的使用,期待下次光临\n");exit(0);default:printf("您的输入有误,请重新输入\n");}
}void menuONE()//库存管理
{toxy(17,1);printf("----->1)添  加  商  品\n");toxy(17,2);printf("      2)增  加  库  存\n");toxy(17,3);printf("      3)查  看  库  存\n");toxy(17,4);printf("      4)清  空  库  存\n");toxy(17,5);printf("      按 ESC 返 回\n");while(1){printf("  >>");char s=getch();printf("\n");switch(s){case 49:addcommodity();break;case 50:addcommodity_sum();break;case 51:printcommodity();break;case 52:emptycommodity();break;case 27:mainmenu();default:printf("您的输入有误,请重新输入\n");}}
}void addcommodity()//添加商品
{int n, i;FILE* fp;printf("请输入添加商品的种类数n(1=<n<=20)\n请不要输入同样或已存在的商品,否则后果自负!!!\n");while(1){printf("    >>");scanf("%d", &n);if(n>=1&&n<=20)break;else{printf("输入不满足1=<n<=20,请重新输入\n");}}commodity a[21];if((fp = fopen("inventory.txt", "a"))==NULL){printf("商品文件打开失败,无法添加商品,请重置系统");Sleep(2000);mainmenu();}printf("    商品名      进价\t售价\t余量\n");for (i = 1; i <= n; i++){printf("[%d]",i);scanf("%s %lf %lf %d", a[i].name, &a[i].purchasing, &a[i].selling, &a[i].num);fprintf(fp, "%-16s\t¥%.2lf\t¥%.2lf\t%d\n", a[i].name, a[i].purchasing, a[i].selling, a[i].num);}fclose(fp);printf("添加成功\n");
}void addcommodity_sum()//增加库存
{char name[16];int add,flag=0;commodity b;FILE *fp;if((fp = fopen("inventory.txt","r"))==NULL){printf("商品文件打开失败,无法增加库存,请重置系统");Sleep(2000);mainmenu();}else{FILE *fp1;char ch;if((fp1 = fopen("inventory1.txt","w"))==NULL){printf("商品文件打开失败,无法增加库存,请重置系统");Sleep(2000);mainmenu();}printf("增加商品名 增加库存数目\n");scanf("%s %d",name,&add);fprintf(fp1,"商品名          \t进价\t售价\t余量\n");fseek(fp,31L,0);//略过第一行while(1){fscanf(fp,"%16s %*2c %lf %*2c %lf %d",b.name,&b.purchasing,&b.selling,&b.num);if(feof(fp))break;if(strcmp(name,b.name)==0){b.num+=add;flag=1;}fprintf(fp1, "%-16s\t¥%.2lf\t¥%.2lf\t%d\n", b.name, b.purchasing, b.selling, b.num);}fclose(fp);fclose(fp1);copyfile();if(flag){printf("增加成功\n");}else{printf("该商品不存在\n");}}
}void printcommodity()//查看库存
{FILE *fp;char ch;if((fp = fopen("inventory.txt","r"))==NULL){printf("商品文件打开失败,无法查看库存,请重置系统");Sleep(2000);mainmenu();}else{fscanf(fp,"%c",&ch);while(!feof(fp)){putchar(ch);fscanf(fp,"%c",&ch);}fclose(fp);}
}void emptycommodity()//清空库存
{printf("清空库存所有商品将会消失,是否确定?\n");printf("1)确定\n");printf("2)不确定\n请输入数字,否则会出BUG\n");FILE* fp;while(1){printf("    >>");int choice=0;scanf("%d",&choice);if(choice==1){if((fp = fopen("inventory.txt", "w"))==NULL){printf("商品文件打开失败,无法清空库存,请重置系统\n");Sleep(2000);mainmenu();}fprintf(fp,"商品名          \t进价\t售价\t余量\n");fclose(fp);printf("库存已清空\n");Sleep(1000);mainmenu();}else if(choice==2){break;}else{printf("您的输入有误,请重新输入\n");}}
}void menuTWO()//销售管理
{toxy(17,2);printf("----->1)销  售  商  品\n");toxy(17,3);printf("      2)利  润  统  计\n");toxy(17,4);printf("      3)销  售  额  统  计\n");toxy(17,5);printf("      按 ESC 返 回\n");while(1){printf("  >>");char s=getch();printf("\n");switch(s){case 49:reducecommodity_sum();break;case 50:{FILE *fp2;if((fp2 = fopen("data.dat","r"))==NULL){printf("数据文件打开失败,无法查看利润,请重置系统");Sleep(2000);mainmenu();}else{fscanf(fp2,"%lf %lf",&sale,&profit);fclose(fp2);printf("当前利润:¥%.2lf\n",profit);break;}}case 51:{FILE *fp2;if((fp2 = fopen("data.dat","r"))==NULL){printf("数据文件打开失败,无法查看销售额,请重置系统");Sleep(2000);mainmenu();}else{fscanf(fp2,"%lf %lf",&sale,&profit);fclose(fp2);printf("当前销售额:¥%.2lf\n",sale);break;}}case 27:mainmenu();default:printf("您的输入有误,请重新输入\n");}}
}void reducecommodity_sum()//销售商品
{char name[16];int reduce,flag=0;commodity b;FILE *fp;if((fp = fopen("inventory.txt","r"))==NULL){printf("商品文件打开失败,无法销售商品,请重置系统");Sleep(2000);mainmenu();}else{FILE *fp1;FILE *fp2;char ch;if((fp1 = fopen("inventory1.txt","w"))==NULL){printf("商品文件打开失败,无法销售商品,请重置系统");Sleep(2000);mainmenu();}printf("销售商品名 销售商品数目\n");scanf("%s %d",name,&reduce);if((fp2 =  fopen("data.dat","w+"))==NULL){printf("数据文件打开失败,无法销售商品,请重置系统");Sleep(2000);mainmenu();}fscanf(fp2,"%lf %lf",&sale,&profit);fprintf(fp1,"商品名          \t进价\t售价\t余量\n");fseek(fp,31L,0);//略过第一行while(1){fscanf(fp,"%16s %*2c %lf %*2c %lf %d",b.name,&b.purchasing,&b.selling,&b.num);if(feof(fp))break;if(strcmp(name,b.name)==0){if(reduce<=b.num){b.num-=reduce;flag=1;sale+=reduce*b.selling;profit+=reduce*(b.selling-b.purchasing);}elseflag=2;}fprintf(fp1, "%-16s\t¥%.2lf\t¥%.2lf\t%d\n", b.name, b.purchasing, b.selling, b.num);}fprintf(fp2,"%.2lf %.2lf",sale,profit);fclose(fp);fclose(fp1);fclose(fp2);copyfile();if(flag==1){printf("销售成功\n");}else if(flag==2){printf("该商品库存不足\n");}else{printf("该商品不存在\n");}}
}void copyfile()//复制备用文件到原文件
{char ch;FILE* pfr = fopen("inventory1.txt", "r");FILE* pfw = fopen("inventory.txt", "w");if (NULL == pfw){printf("商品文件打开失败,无法销售商品,请重置系统");Sleep(2000);mainmenu();}if (NULL == pfr){printf("商品文件打开失败,无法销售商品,请重置系统");Sleep(2000);mainmenu();}while ((ch=fgetc(pfr))!=EOF)//EOF是文件结束标志{fputc(ch,pfw);}fclose(pfr);fclose(pfw);
}void resetsystem()//重置系统
{printf("重置系统销售额、利润和所有商品将会消失,是否确定?\n");printf("1)确定\n");printf("2)不确定\n请输入数字,否则会出BUG\n");FILE* fp;while(1){printf("  >>");int choice=1;scanf("%d",&choice);if(choice==1){if((fp = fopen("inventory.txt", "w"))==NULL){printf("商品文件打开失败,系统无法使用,请联系作者维修");Sleep(2000);mainmenu();}fprintf(fp,"商品名          \t进价\t售价\t余量\n");fclose(fp);sale=profit=0;FILE *fp2;if((fp2 = fopen("data.dat","w"))==NULL){printf("商品文件打开失败,无法重置系统");Sleep(1000);mainmenu();}else{fprintf(fp2,"%.2lf %.2lf",sale,profit);fclose(fp2);printf("系统已重置\n");Sleep(1000);mainmenu();}}else if(choice==2)mainmenu();else{printf("您的输入有误,请重新输入\n");}}
}void aboutsystem()//关于系统
{toxy(17,4);printf("----->1)关  于  作  者\n");toxy(17,5);printf("      2)关  于  版  本\n");toxy(17,6);printf("      按 ESC 退 出\n");while(1){printf("  >>");char s=getch();printf("\n");switch(s){case 49:{Sleep(1000);printf("*   河南工  业大学   *\n");Sleep(1000);printf("*人工智能与大数据学院*\n");Sleep(1000);printf("*   软  件  工  程   *\n");Sleep(1000);printf("*     2  0  0  3     *\n");Sleep(1000);printf("*        王泽        *\n");break;}case 50:printf("当前版本:1.1032\n已是最新版本\n");break;case 27:mainmenu();default:printf("您的输入有误,请重新输入\n");}}
}

小型超市库存与销售管理系统(C语言课设)2021-04-24相关推荐

  1. 学生信息管理系统c语言课设,学生信息管理系统C语言课设.doc

    学生信息管理系统C语言课设 目录 一.需求分析2 二.概要设计2 三.详细设计4 四.调试分析9 五.用户手册9 六.测试数据9 七.附录10 一.需求分析学生学籍管理系统用数据文件存放学生的学籍,可 ...

  2. 网吧管理系统------C语言课设

    网吧管理系统------C语言课设 1.课程设计报告的要求 2.实现管理员注册和登录模块的代码 3.实现管理员对用户的管理功能及简介如下,包括上下机,余额积分加减等功能. 4.主函数 5.存在的不足 ...

  3. C语言课设物资管理系统,C语言课设之物资管理系统.doc

    C语言课设之物资管理系统 C语言课程设计 目 录 1.需求分析: 2.系统总框图: 3.每个模块的设计分析: 4.列出所有定义的函数及说明: 5.举例说明1.2个比较有特点的算法: 6.数据分析.完备 ...

  4. 课设 c语言编译学籍管理系统,C语言课设之学生学籍管理系统

    <C语言课设之学生学籍管理系统>由会员分享,可在线阅读,更多相关<C语言课设之学生学籍管理系统(10页珍藏版)>请在人人文库网上搜索. 1.题目:学生学籍管理系统 目录:一.个 ...

  5. c语言建筑工地管理系统,C语言课设之建筑工地信息管理系统.doc

    C语言课设之建筑工地信息管理系统 C 语 言 课 程 实 习 报 告 建筑工地信息管理系统 题目要求 <建筑工地信息管理系统>要求要建立与建筑相关的四个文件信息:1)项目2)工地 3)配件 ...

  6. c语言设计之歌曲信息管理系统,C语言课设之歌曲信息管理系统

    <C语言课设之歌曲信息管理系统>由会员分享,可在线阅读,更多相关<C语言课设之歌曲信息管理系统(10页珍藏版)>请在人人文库网上搜索. 1.C语言课程设计目 录1.题目要求2. ...

  7. 职工管理系统c语言课设需求分析,人力资源管理系统需求分析报告及系统架构图...

    人力资源管理系统需求分析 小组成员:朱国辉 许珍源 1.需求获取及分析 1.1业务需求 随着现在计算机技术的不断完善,以及现代经济的不断发展,传统的管理技术不再满足企业的需要,越来越多的企业注重计算机 ...

  8. 高校教师工资管理系统/C语言课设

    此项目为BJFU2020级课程设计 供学弟学妹们参考 项目总体介绍:  一.总体介绍 1. 项目名称:高校教师工资管理系统 2. 项目简介: 完成高等院校教师工资管理软件开发.教师的基本信息包括:工号 ...

  9. c语言电脑报价系统,笔记本电脑销售管理系统-C语言-课程设计-实验.doc

    笔记本电脑销售管理系统-C语言-课程设计-实验 笔记本电脑销售管理系统-C语言-课程设计-实验 PAGE / NUMPAGES 笔记本电脑销售管理系统-C语言-课程设计-实验 笔记本电脑销售管理系统 ...

最新文章

  1. cpu和GPU有什么区别
  2. 剑指offer-链表中倒数第K个结点
  3. opengl从入门到精通
  4. C语言malloc和calloc的区别
  5. 前端学习(2312):react之路由基础
  6. “富豪相亲大会”究竟迷失了什么?
  7. TensorFlow HOWTO 1.2 LASSO、岭和 Elastic Net
  8. Spring Boot学习总结(25)——Spring Boot 资源初始化加载总结
  9. 统计1到2021中6的个数
  10. 如何把jpg转换成word文档
  11. 2012-08-20 → 2012-08-26 周总结
  12. freeswitch安装1.6
  13. RestTemplate获取HTTP状态码
  14. Dell uefi使用U盘重装系统
  15. Java Instrument 功能使用及原理
  16. bios卡+型号+hp服务器,HPE Gen9 server UEFI BIOS下升级BIOS 阵列卡 HBA卡固件的操作方法...
  17. 18-EMM Procedure 6. Handover without TAU - Part 3. S1 Handover
  18. 破解音频隐写术:结合机器学习
  19. arch linux yaourt arm,在ARM設備(樹莓派、香蕉派)上為Arch Linux配置yaourt
  20. apk系统签名小技巧

热门文章

  1. cordic sinh matlab,利用FPGA进行基本运算及特殊函数定点运算
  2. SpringBoot Jar包构建源码分析
  3. 软件测试具有哪些优势
  4. c语言调用子程序的例子,几个C语言编程应用实例.DOC
  5. 51校园购==酷玩网
  6. go-ethereum相关
  7. 软件工程n!程序流程图
  8. 关于怎样选择人事考勤工资软件的一些建议
  9. JDK1.7和JDK1.8 的区别
  10. 深圳市晶光华电子有限公司 - 晶振选型的四个重要参数是什么?