c语言课程设计

                                    

该系统主要是介绍超市进销存管理信息系统的环境、功能作用、所用到的语言、设计的方案等各方面的内容。主要是让使用者了解此系统,使他们能更好的运用本系统,使此系统发挥出应有的作用。本系统运用计算机管理信息技术,对超市的进销存过程进行详细的分析,实现了对超市的进货、出售和库存的科学管理。
    本系统主要包括以下几大模块:输入单据:出库、入库、物品清单;查询:数量查询、价格查询、生产地查询。
关键词 : 销售;管理信息系统;C语言
                               

               

Abstract
       This text mainly introduces the supermarket and enters to sell such contents of various fields as the environment which stores the management information system , scheme on the function , language , design used ,etc.. Let user find out about system this , enable them fine application this system mainly, make this system give play to due function . This system uses the information technology of computer management,sell the course of storing to carry on detailed analysis to the entering of the supermarket, have realized the purchase , sale and scientific management held in store to the supermarket.
      This system is major and includes following several big modules : The input receipts : The warehouse is gone out to be put in storage that the product end product detailed list is inquired about : The report form being put in storage is gone out the report form product end product detailed list report form in warehouse to sell to move back the money list report form to advance.

keywords :  Sell ; management information system ;C language

目  录

1概述. 1

1.1 设计思想. 1

1.2 设计原则. 1

1.3性能需求. 1

2总体设计. 2

2.1系统功能设计图. 2

2.2系统功能设计. 2

2.2.1 系统颜色模块功能. 3

2.2.2 销售管理模块功能. 3

2.2.3 进货管理模块功能. 3

2.2.4 库存管理模块功能. 3

2.3系统模块的运用方法. 3

2.3.1输入记录模块. 3

2.3.2查询记录模块. 3

2.3.3输出记录模块. 3

3详细设计使用. 4

3.1数据定义. 4

3.2主函数流程图. 5

3.3源程序. 7

4调试分析. 8

4.1进入主界面. 8

4.2 系统菜单界面. 8

4.3 商品信息查询窗口. 10

5总结. 11

参考文献. 12

致  谢. 13

附件. 14


1概述

1.1 设计思想

(1)系统分成几个相对独立的模块,但这些模块都进行集中式管理。

(2)分层的模块化程序设计思想,整个系统采用模块化结构设计作为应用程序,有较强的可操作性和扩展性。

(3)合理的数据设计,在应用系统设计中,相对独立的模块间以数据相互连接,使各模块间的耦合性较低,方便系统运行,提高系统安全性 。     

1.2 设计原则

为了使本系统功能齐全完备,操作简便,最大限度的提高软件的质量,从而满足用户的实际需要,在设计开发过程中遵循了如下原则:

(1)合法性原则:依据产品核算系统的工作规定以及要求,参照核算实际的工作情况,进行诸如产品进货、销售等工作。

(2)实用性原则:适合产品信息管理工作的实际需求,并能够处理一些特殊情况的要求,此外,尽可能预留空间,以便扩充功能。

(3)准确性原则:对输入的相关资料建立检错机制,及时报错,使用户能够及时准确的输入合法资料(如:类型匹配,长度不超限等)。

(3)易操作原则:要求设计的系统功能齐全,界面友好,操作方便,必要的地方进行提示。

(5)源程序可读性原则:为了便于其他设计,维护人员读懂代码或以后的代码修改,软件升级维护,即可能做好代码注释工作。

1.3性能需求

(1)数据精确度

产品的进货单和销售单中,单价、金额采用浮点数,保留至小数点后两位。

2总体设计

2.1系统功能设计图

图2-1 超市管理系统功能结构

2.2系统功能设计

系统功能设计是使整个系统能基本实现超市的进、销、存等管理功能,能让超市管理者更直观的了解超市的经营状况,以做出相应的经营决策。管理信息系统(MIS)就是进行信息的收集、传送、存储、编制成各种凭证、报表、台帐、图形等信息,同时对这些信息进行维护,通过实测超市的各种运行情况,并利用过去的历史数据预测未来的发展,从超市全局的角度出发进行决策,利用信息控制超市的行为,辅助超市完成其目标。

本系统共包括四大模块,分别是系统颜色模块,销售管理模块,进货管理模块,库存管理模块。每个模块的功能如下:

2.2.1 系统颜色模块功能

(1)实现系统颜色转换;

(2)查看系统颜色;

2.2.2 销售管理模块功能

(1)实现销售信息的查询;

(2)实现商品销售信息的盘点。

2.2.3 进货管理模块功能

(1)实现进货信息的查询;

(2)实现进货信息的更新,包括增加、删除、修改功能。

2.2.4 库存管理模块功能

(1)实现商品信息的查询;

(2)实现商品信息的更新,包括增加、删除、修改功能;

(3)实现库存信息的查询;

(4)实现库存信息的更新,包括增加、删除、修改功能。

2.3系统模块的运用方法

2.3.1输入记录模块

 输入记录模块的功能:输入各种商品的信息;

2.3.2查询记录模块

    查询记录模块的功能:查询各种商品的信息;

2.3.3输出记录模块

输出记录模块的功能:输出各种商品的信息;

3详细设计使用

3.1数据定义

使用C语言创建的结构体和定义的函数如下:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<conio.h>

struct produce_node

{   int id;

   char name[20];

   char produce[30];

   int number;

   double price;

   double price1;

   struct produce_node *next;

};

struct ima

{  int id;

   char name[20];

   char produce[30];

   int number;

   double price;

   double price1;

   struct 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 produce_node *InsertDoc(struct produce_node *head,struct produce_node *produce);

   struct produce_node *DeleteDoc(struct produce_node *head,int num);

3.2主函数流程图

控制整个程序的运行,通过主函数模块分别调用各个模块,实现各项功能,流程图如图3.1所示。


 

 

 


                    

                         图3.1  主函数流程图

3.3源程序

       见附件

4调试分析

4.1进入主界面

打开系统,进入主界面,显示“欢迎使用超市管理系统”然后使用者可以按任意键进入下一界面,此界面整齐美观,界面友好,是使用者更容易接受。主界面显示图如图4.1所示。

图4.1主界面

4.2 系统菜单界面

在主界面按任意键进入系统菜单界面,界面显示“1.......新购商品入库;2………商品信息删除;3………商品信息修改;4………..商品信息查询;5……….商品信息浏览;6……….系统颜色设置;7………应用程序退出;8………...物品价值总和浏览;9…………物品的出售管理;10……….商品的预计利润”使用者可以按相应的数字键进入子系统。系统菜单界面如图4.2所示。

                      图4.2系统菜单

4.3 商品信息查询窗口

    在系统菜单按4进入商品信息查询子菜单,输入所查询的商品编号,界面显示的物品信息有“商品编号、商品名称、生产厂家、进口数量、进货价格、出售价格”然后会问你是否继续,继续按Y,不想继续按N。商品信息查询窗口如图4.3所示。

                      图4.3  商品信息查询

 5总结

本文共分为五大部分,第一部分简要叙述了计算机科学及IT产业的发展状况和本系统基本概况。第二,三部分分别按照软件工程的要求出发,首先进行问题定义,解决目标问题,其次进行可行性研究,分别从技术可行性,经济可行性和操作可行性进行分析,然后进行的总体设计和详细设计阐述了如何实现具体功能。第四部分为系统调试其中包括子模块测试和总体测试。第五部分为帮助文件和参考文献。
     在此次设计当中让我认识到开发一项好的软件不是某一个人就能完成的任务。一个团队的小组,一个勤奋的小组非常重要,沟通是解决问题的最好办法。所以小组中的每个成员的能力与协作能力也是至关重要的。同时,不仅是团队内部的交流,更多需要协调好团队之间的交流。其次呢,在实习中我了解到,在开发一个项目时一定要先做好规划,按照软件的开发过程,详细地写好每一个必要的文档。由于开发者能力有限,加上时间仓促,本系统难免会出现一些不足之处,我们深表歉意,如发现还有其它问题,希望老师批评指正。

通过此次编程培养了我们结构化程序设计的思想,加深了对高级语言基本语言要素和控制结构的理解,锻炼我们独立思考制作程序的能力,并且掌握了一些课程设计的相关知识与实践操作能力,为以后的学习提供了锻炼的机会。经过设计和开发,销售管理系统基本开发完毕以及各类相关报表的打印。并提供部分系统维护功能,使用户方便进行数据备份和恢复、数据删除。对于数据的一致性的问题也通过程序进行了有效的解决。从而是我对c语言这门课程有了更好的了解。

                  

参考文献

[1]姜灵芝,余健. C语言课程设计案例精编.北京:清华大学出版社,2008

[2]王新,孙雷. C语言课程设计.北京:清华大学出版社,2009

[3]游洪跃、彭骏、谭斌.C语言程序设计实验与课程设计教程.北京:清华大学出版社,2011

[4]王连相.C/C++程序设计上机指导与测试. 北京:中国铁道出版社,2006

    [5]C语言函数手册,机械工业出版社,1999

[6]王勇领.计算机数据处理系统分析与设计.北京:清华大学出版社,2007.3

[7]张基温.信息系统开发案例.北京;清华大学出版社,2006.3

致  谢

经过五天的艰苦努力,我终于完成了超市管理系统的全部设计过程,并使该系统达到可实际应用的阶段。软件设计是一个精细漫长的过程。在整个过程中,都需要周密的计划和安排,每一步骤,都需要按照软件工程标准来完成。在设计中,我始终坚持理论指导实践原则,并通过实践来加强理论的学习,通过实习锻炼,我熟悉了软件的一般过程,加强了对实际问题的处理能力。实践证明,在高科技突飞猛进的时代,光靠课堂所学的知识是远远不够的,必须依靠实践去不断的深化认识,尤其是计算机科学,操作性和实践性很强,只有加强实际的动手能力,才能更好的掌握这一现代化工具。
    这次学习,无论是从技术上还是对环境的适应能力上讲,对我今后步入社会都打下了一个良好的基础。在学习过程中,我也遇到了一些困难,主要表现了技术和经验的欠缺,但通过努力,终于一一克服了。

在编写程序的过程中,我们得到了马生菊老师的精心指导以及孜孜不倦的教诲,在老师的指导下,我们的能力得到了提高,同时养成了科学、严谨的作风和习惯,在此,我们对老师的精心栽培表示衷心的感谢!

感谢我们小组同学对我的帮助和指点。在课设的整个过程中,我的师长、同学、朋友给了我无言的帮助,在这里请接受我诚挚的谢意。

附件

       #include<stdio.h>

       #include<stdlib.h>

       #include<string.h>

       #include<conio.h>

struct produce_node

{   int id;

       char name[20];

       char produce[30];

       int number;

       double price;

       double price1;

       struct produce_node *next;

};

struct ima

{     int id;

       char name[20];

       char produce[30];

       int number;

       double price;

       double price1;

       struct 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 produce_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("\n\t1=====================【           新购商品入库         】\n");

              printf("\n\t2=====================【           商品信息删除         】\n");

              printf("\n\t3=====================【           商品信息修改         】\n");

              printf("\n\t4=====================【           商品信息查询         】\n");

              printf("\n\t5=====================【           商品信息浏览         】\n");

              printf("\n\t6=====================【           系统颜色设置         】\n");

              printf("\n\t7=====================【           应用程序退出         】\n");

              printf("\n\t8=====================【           商品价值总和浏览     】\n");

              printf("\n\t9=====================【           商品的出售管理       】\n");

              printf("\n\t10====================【           商品的预计的利润     】\n");

              printf("\n\t请输入您要选择的菜单......");

              scanf("%d",&choice);

              switch(choice)                                       

              {

              case 1:

                     Append();

                     break;

              case 2:

                     Selldelete();

                     break;

              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("\n\t\t\t\t\t输入无效,请您重新输入......");

                     getch();

                     system("cls");

                     menu();

              }

       }

       void colorsetting()

       {   int a;

       char choice;

              system("cls");

              printf("\n\n\t\t选择以下方案\n");

              printf("\n\n\t\t1**************红底黑字\n");

              printf("\n\n\t\t2**************白底黑字\n");

              printf("\n\n\t\t3**************黑底红字\n");

              printf("\n\n\t\t4**************绿底蓝字\n");

              printf("\n\n\t\t5**************黄底紫字\n");

              printf("\n\n\t\t6**************系统默认\n");

              printf("\n\n\t\t\t\t\t请挑选您喜爱的颜色<1-5>......");

          

              scanf("%d",&a);

              switch(a)                                 

              {

                     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("\n\n\t\t\t\t\t输入无效,重新输入......");

                     getch();

                     colorsetting();

      

              }

             

              printf("\n选择的颜色您还满意吗?(y返回主菜单/n继续选择)");

              scanf(" %c",&choice);

              if(choice=='Y'||choice=='y')

              {

                    

                     system("cls");

                     menu();

              }

              else

              {

                     colorsetting();

              }

       }

       int validateID(int id)

       {  

              FILE *fp;

              struct ima i;

              fp=fopen("ima.date","r");

              if(fp==NULL)                                      

              {

                     printf("\t\t\t系统错误,请您重试........");

                     exit(0);

              }

             

              fread(&i,sizeof(struct ima),1,fp);

              while(!feof(fp))

              {

                     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 j;                

            char choice;

            FILE *fp;                              

              fp=fopen("ima.date","ab");

            i=&j;                             

              if(fp==NULL)

              {

                     printf("\t\t\t系统错误,请您重试........");  

                     exit(0);

              }

             

         labID:

              printf("\n\t请您输入要入库商品的信息...\n");

              printf("\t\t\t\t   商品的编号:");

              scanf("%d",&j.id);

              if(validateID(j.id)==1)                          

              {

                     printf("\t\t\t\t此编号已被使用,请您重新输入......\n");

                     goto labID;

              }

              else

                     printf("    ****************************此编号没有被使用您可以使用**********************************\n");

              i=lianbiao();                      

              while(i!=NULL)

              {

                     fwrite(i,sizeof(struct produce_node),1,fp);

                     i=i->next;                                                     

              }

              fclose(fp);

              printf("\t\t\t\t\t\t  商品信息已入库成功!!!\n");

              free(i);

             

              printf("\n您想继续吗?(y/n)");

              scanf(" %c",&choice);

              if(choice=='Y'||choice=='y')

              {

                     Append();

              }

              else

              {

                     system("cls");

                     menu();

              }

       }

       void Selldelete()

       {   struct ima i[1000];

              struct ima temp;

              int delID;

              char choice;

              int index=0;

              int j=0;

              FILE *fp;

              fp=fopen("ima.date","r");

              if(fp==NULL)

              {

                     printf("\t\t\t系统错误,请您重试........");

                     exit(0);

              }

             

             

              fread(&temp,sizeof(struct ima),1,fp);

              while(!feof(fp))

              {

                     i[index]=temp;

                     index++;

                     fread(&temp,sizeof(struct ima),1,fp);

              }

              fclose(fp);

             

              printf("\n\t请输入要删除的商品的编号:");

              scanf("%d",&delID);

              fopen("ima.date","w");/*打开文件*/

              if(fp==NULL)

              {

                     printf("\t\t\t系统错误,请您重试........");

                     exit(0);

              }

              for( j=0;j<index;j++)               

              {

                     if(i[j].id!=delID)

                     {

                            fwrite(&i[j],sizeof(struct ima),1,fp);

                     }

              }

           fclose(fp);

              printf("\t\t\t\t\t商品信息已清除!!!\n");

             

              printf("\n您想继续吗?(y/n)");

              scanf(" %c",&choice);

              if(choice=='Y'||choice=='y')

              {

                     Selldelete();

              }

              else

              {

                     system("cls");

                     menu();

              }

       }

       void Amend()

       {   int index=0;

           int ID,j;

           char choice;

           struct ima i[1000];

           struct    ima temp;

              FILE *fp;

              fp=fopen("ima.date","r");

              if(fp==NULL)

              {

                     printf("\t\t\t系统错误,请您重试........");

                     exit(0);

              }

             

             

              fread(&temp,sizeof(struct ima),1,fp);

              while(!feof(fp))

              {

                     i[index]=temp;

                     index++;

                     fread(&temp,sizeof(struct ima),1,fp);

              }

              fclose(fp);

              fp=fopen("ima.date","w");

              if(fp==NULL)

              {

                     printf("\\t\t\t系统错误,请您重试........");

                     exit(0);

              }

             

              printf("\n\t请输入要修改的信息的商品的编号:");

              scanf("%d",&ID);

              for(j=0;j<=index-1;j++)                        

              {

                     if(i[j].id!=ID)

                     {

                            fwrite(&i[j],sizeof(struct ima),1,fp);

                     }

                     else                                   

                     {

                            printf("\t\t商品名称修改为:");

                            scanf("%s",i[j].name);

                            printf("\t\t商品生产地修改为:");

                            scanf("%s",i[j].produce);

                            printf("\t\t商品数量修改为:");

                            scanf("%d",&i[j].number);

                            printf("\t\t商品进货单价修改为:");

                            scanf("%lf",&i[j].price);

                            printf("\t\t商品出售单价修改为:");

                            scanf("%lf",&i[j].price1);

                            fwrite(&i[j],sizeof(struct ima),1,fp);

                     }

              }

              fclose(fp);

              printf("\t\t\t\t商品信息已修改......");

             

              printf("\n您想继续吗?(y/n)");

              scanf(" %c",&choice);

              if(choice=='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("\t\t\t系统错误,请你重试........");

                     exit(0);

              }

           printf("\n\t请输入要查询的商品的编号..");

              scanf("%d",&findID);

             

              fread(&i,sizeof(struct ima),1,fp);

             

              while(!feof(fp))

              {

                     if(i.id==findID)

                     {

                            a=1;

                            printf("\n\n\t***************商品信息******************");

                            printf("\n\t商品编号...%30d\n",i.id);

                            printf("\n\t-----------------------------------------");

                            printf("\n\t商品名称...%30s\n",i.name);

                            printf("\n\t-----------------------------------------");

                            printf("\n\t生产厂家...%30s\n",i.produce);

                            printf("\n\t-----------------------------------------");

                            printf("\n\t进口数量...%30d\n",i.number);

                            printf("\n\t-----------------------------------------");

                            printf("\n\t进货价格...%30.3f\n",i.price);

                            printf("\n\t-----------------------------------------");

                            printf("\n\t出售价格...%30.3f\n",i.price1);

                            printf("\n\t-----------------------------------------");

                            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("\t\t\t\t\t输入的编号不存在,请您重新输入......");

              printf("\n您想继续吗?(y/n)");

                            scanf(" %c",&choice);

                            if(choice=='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("\t\t\t系统错误,请你重试........");

                     exit(0);

              }

             

              fread(&i,sizeof(struct ima),1,fp);

             

              while(!feof(fp))

              {

                    

                     printf("\n\n\t****************商品信息%d*****************",++index);

                     printf("\n\t商品编号...%30d\n",i.id);

                     printf("\n\t-----------------------------------------");

                     printf("\n\t商品名称...%30s\n",i.name);

                     printf("\n\t-----------------------------------------");

                     printf("\n\t生产厂家...%30s\n",i.produce);

                     printf("\n\t-----------------------------------------");

                     printf("\n\t进口数量...%30d\n",i.number);

                     printf("\n\t-----------------------------------------");

                     printf("\n\t进货价格...%30.3f\n",i.price);

                     printf("\n\t-----------------------------------------");

                     printf("\n\t出售价格...%30.3f\n",i.price1);

                     printf("\n\t-----------------------------------------");

                     getch();

                     fread(&i,sizeof(struct ima),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("\t\t\t系统错误,请你重试........");

                     exit(0);

              }

             

              fread(&i,sizeof(struct ima),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()

       {char choice;

              system("cls");

             

              printf("\n\n\n\n\n\n\n\t\t\t您确定要退出系统吗?\n\n\n\t\t\t如果您想退出请按'y',其它键将返回主菜单.....");

              scanf(" %c",&choice);

              if(choice=='Y'||choice=='y')

              {

                     system("cls");

                     printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t谢谢您的使用!!!");

                     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

              }

              else

              {

                     system("cls");

                     menu();

              }

      

       }

       main()

       {

              printf("\n\n");

              system("color 1a");

              printf("\t\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 \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                        欢迎使用                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                    小型超市管理系统                          \3\n");

              printf("\t\3                      按任意键继续                             \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\3                                                               \3\n");

              printf("\t\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 \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 name[20];char produce [30];double price1;

      

       int size=sizeof(struct produce_node);

       do{

              printf("********************您要录入信息吗?请选一,要退出录入吗?请输入零*************************** \n");

             

f:

              i++;

              scanf("%d",&choice);

              if(choice==0&&i<=1)

              {

                     head=NULL;

              }

              switch (choice){

              case 1:

                     head=Create_produce_Doc();

                     break;

              case 2:

labID:

                     printf("请输入: 产品序列号:\n");

                     scanf("%d",&id);

              if(validateID(id)==1)                     

              {

                     printf("\t\t\t\t此编号已被使用,请您重新输入......\n");

                     goto labID;

              }

              else

                     printf("*******此编号没有被使用您可以使用*******\n");

                     printf("请输入: 产品序列号**商品名称**商品产地**商品数量**商品进货价格**商品出售价格:\n");

                     scanf("%d%s%s%d%lf%lf",&id,name,produce,&number,&price,&price1);

                     p=(struct produce_node*)malloc(size);

                     p->number=number;

                     strcpy(p->name,name);

                     p->price=price;

                     p->price1=price1;

                     p->id=id;

                     strcpy(p->produce,produce);

                     head=InsertDoc(head,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)

       return head;

       else

       {

       return NULL;

       system("cls");     

       menu();

       }

      

}

struct produce_node*Create_produce_Doc()

{

       struct produce_node *head,*p;

       int number;

       int id;

       double price;

       double price1;

       char name[20];

       char produce[30];

       int size=sizeof(struct produce_node);

       head =NULL;

       printf("请输入: 商品序列号***商品名称***商品产地***商品数量***商品进货价格***商品的出售价格:\n");

       scanf("%d%s%s%d%lf%lf",&id,name,produce,&number,&price,&price1);

       while(number!=0){  

              p=(struct produce_node*)malloc(size);              

              p->number=number;                                    

              strcpy(p->name,name);

              strcpy(p->produce,produce);

              p->price=price;   

              p->price1=price1;

              p->id=id;

              head=InsertDoc(head,p);

              break;

             

       }

       return head;

}

struct produce_node*InsertDoc(struct produce_node *head,struct produce_node *produce)

{

       struct produce_node*ptr,*ptr1,*ptr2;

       ptr2=head;

       ptr=produce;

       if (head==NULL)

    {

              head=ptr;

              head->next=NULL;

       }

       else{

              while ((ptr->id >ptr2->id)&&(ptr2->next !=NULL))

         {

                     ptr1=ptr2;

                     ptr2=ptr2->next;

              }

              if(ptr->id<=ptr2->id)

              {     if(head==ptr2) head=ptr;

                     else ptr1->next=ptr;

                     ptr->next=ptr2;

              }

              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);

       }

       if(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 i[1000];

              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("\t\t\t系统错误,请您重试........");

                     exit(0);

              }

             

             

              fread(&temp,sizeof(struct ima),1,fp);

              while(!feof(fp))

              {

                     i[index]=temp;

                     index++;

                     fread(&temp,sizeof(struct ima),1,fp);

              }

              fclose(fp);

             

              printf("\n\t请输入要出售的商品的编号:");

              scanf("%d",&delID);

              fopen("ima.date","w");

              if(fp==NULL)

              {

                     printf("\t\t\t系统错误,请您重试........");

                     exit(0);

              }

              for( j=0;j<index;j++)

              {

                     if(i[j].id!=delID)

                     {

                            fwrite(&i[j],sizeof(struct ima),1,fp);

                     }

                     else

                     {

                            if(i[j].number>=count)

                            {

                                   mm=i[j];

                                   i[j].number=i[j].number-count;

                       fwrite(&i[j],sizeof(struct ima),1,fp);

                            }

                            else if(i[j].number!=0)

                            {

                                   shuliang=1;

                                   fwrite(&i[j],sizeof(struct ima),1,fp);

                            }

                            else if(i[j].number==0)

                            {

                                   shuliang=1;

                            }

                     }

              }

           fclose(fp);

              if(shuliang==1)

              {                  

                     printf("\t\t\t\t\t商品库存不足不能出售!!!\n");

              }

              else

              {

                     jine=mm.price1*count;

                     printf("您所需要的金额为%lf",jine);

                     printf("\t\t\t\t\t商品已出售!!!\n");

              }

             

              printf("\n您想继续吗?(y/n)");

              scanf(" %c",&choice);

              if(choice=='Y'||choice=='y')

              {

                     int i;

                     printf("请输入您要卖出的数量:");

                     scanf("%d",&i);

                     chushou(i);

              }

              else

              {

                     system("cls");

                     menu();

              }

       }

       void liren()

       {   struct ima i;

           double index=0;

              char choice;

              FILE *fp;

              fp=fopen("ima.date","r");

              if(fp==NULL)

              {           

                     printf("\t\t\t系统错误,请你重试........");

                     exit(0);

              }

             

              fread(&i,sizeof(struct ima),1,fp);

             

              while(!feof(fp))

              {

                     index=index+i.price1*i.number-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')

              {

                     liren();

              }

              else

              {

                     system("cls");

                     menu();

              }

       }

相关推荐