• 603.00 KB
  • 2022-05-17 11:09:33 发布

设备管理系统报告_毕业论文.doc

  • 38页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
设备管理系统HUBEIUNIVERSITYOFAUTOMOTIVETECHNOLOGYC语言程序设计课程设计报告课设题目:设备管理系统专业:电气工程及其自动化班级:T1223-08姓名:成绩:完成日期:2013年6月18日-2013年6月22日指导教师:史旅华第37页共38页 设备管理系统目录1.课程设计目的22.需求分析22.1要求22.2任务描述22.3运行环境32.4开发工具33.总体设计33.1系统流设计33.2系统模块设计44.详细设计54.1数据结构设计54.2模块接口设计64.3以下是几个主要模块的流程图:75.运行结果105.1主菜单界面:105.2信息录入界面:105.3信息浏览界面:115.4信息查询界面:115.5信息修改界面:126.程序调试与测试126.1程序调试126.2程序测试127.问题与不足128.建议129.编程体会1210.程序源代码:1211.参考文献1312.用户使用手册13第37页共38页 设备管理系统1.课程设计目的1)通过课程设计,加深对结构化程序设计思想的理解,能对系统功能进行分析,并设计合理的模块化结构。2)通过课程设计,进一步掌握C语言中重要的数据结构。掌握并熟练运用指针、链表、结构体、文件等数据结构。3)通过课程设计,提高程序开发能力,能运用合理的控制流编写清晰高效的程序。4)通过课程设计,培养C语言知识运用和自学能力,真正的把课堂上获得的知识运用起来,培养自己对程序编写的兴趣,并能独立设计和实现一个小型系统。5)通过课程设计,加强了自己的程序分析能力。2.需求分析2.1要求1)遵循软件开发过程的基本规范;能灵活应用,初步具备运用C程序解决实际问题的能力。2)运用结构化程序设计方法,按照课程设计题目要求,完成包括需求分析、数据结构设计、概要设计、详细设计、编写代码、调试和测试C程序等过程。3)学会利用数组、结构体、链表进行相关信息表示。4)功能模块划分清晰,系统结构图符合功能操作要求,且有详尽的功能描述5)各主要功能模块有详尽的流程图及描述,用函数的形式实现,且调用入口、功能、出口等关系正确。6)所设计的C程序较好的可读性和可靠性;程序书写风格规范,注释清晰。7)界面友好(良好的人机互交),凡需要输入信息时,都有较详尽的提示信息,并对输入信息有较完善的值域分析。8)程序经上机调试通过,不应出现语法型、功能型错误,并获得满意的结果。9)学会通过各功能性测试用例测试程序的能力,尽可能避免原则性错误的出现。10)掌握编写、调试和测试C语言程序的基本技巧,充分理解结构化程序设计的基本方法。11)C语言课程设计报告的内容反应实际设计过程,且符合格式要求,无抄袭现象。2.2任务描述第37页共38页 设备管理系统此系统以设备、部门为背景,提供对设备、部门的购买、报废、查找、统计等功能。具体功能实现如下:1)购买:输入设备编号、部门编号(购买),购买日期、设备数量,完成购买的功能:需要判断设备编号、部门编号是否存在,设备数量是否大于0,购买日期格式是否合法(格式为:YYYY-MM-DD,如2009-01-02))购买时间必须通过调用系统时间获得。2)报废:输入设备编号、部门编号(报废),报废日期、设备数量,完成报废功能:需要判断设备编号、部门编号是否存在,设备数量是否大于0小于该部门当前正使用设备数量。报废日期格式是否合法(格式为:YYYY-MM-DD,如2009-01-02))3)查询指定设备编号购买历史4)指定部门报废设备的历史5)统计指定日期公司各设备可以使用的数量6)所有数据符合实际应用要求2.3运行环境1)WindowsXP/7系统2)VC++6.0编译环境2.4开发工具C语言3.总体设计3.1系统流设计本系统的功能模块如图1所示,主要有以下模块:第37页共38页 设备管理系统课程名称界面程序欢迎界面主菜单界面查询部门信息剩余使用次数购买设备报废设备设备的购买历史查询设备的报废历史查询退出系统通过设备编号查询通过部门编号查询通过设备编号查询通过部门编号查询查询设备信息显示全部信息设备信息列表显示设备信息显示部门信息显示购买,报废信息图1系统功能模块图3.2系统模块设计1)主菜单界面:构造函数intmain_menu(),实现课程设计名称的显示,实现欢迎使用设备管理系统的显示,系统主菜单的显示。2)读取显示设备信息:构造函数voidload_equipment(),实现设备信息的读取及显示。3)读取显示部门信息:构造函数voidload_department(),实现部门信息的读取及显示。4)记录购买设备的信息:构造函数voidsave_buy(structinformation第37页共38页 设备管理系统*head),实现设备购买的输入及记录。并通过设备编号查询购买信息函数voidID_buy(structinformation*head)、部门编号查询设备购买信息函数voidnum_buy(structinformation*head)的调用,实现相应的购买信息的查询。1)记录报废设备的信息:构造函数voidsave_ruin(structinformation*head),实现设备报废的输入及记录。并通过设备编号查询报废信息函数voidID_ruin(structinformation*head)、部门编号查询设备报废信息函数voidnum_ruin(structinformation*head)的调用,实现相应的报废信息的查询。2)显示购买报废设备信息记录:构造函数voidshow_information(structinformation*head),实现购买报废设备信息记录的显示。3)显示全部信息的界面:构造函数voidshow_menu(structinformation*head),实现全部信息的界面的显示。4.详细设计4.1数据结构设计根据系统要求,系统中需要保存的数据信息,其结构如下:数据项名称数据项系统表示数据类型数据长度备注设备编号IDint部门编号numint购买日期data[11]char11设备状态styleint设备数量numberint报废数量number1int单价pricedouble总价sumdouble根据系统要求,系统中需要保存的类别信息,其结构如下:类别代号IDnumnumbersum类别名称设备编号部门编号设备数量总价为了能实现不受限制的增加设备信息,采用链表的结构保存设备信息,在增加设备的基本信息时,创建一个设备信息的节点,将其插入到链表中,示意图如下。设备信息1设备信息2通讯录信息1221设备信息3设备信息4为此,先声明一个类型为structstudent的结构体,其成员为设备第37页共38页 设备管理系统信息。然后通过对指针、链表、文件等数据结构的操作,实现对设备信息的录入,插入,存盘,查询,浏览,删除,修改等一系列操作。其中,结构体定义如下:structinformation{intID;intnum;chardata[11];chardata1[11];intstyle;doubleprice;intnumber;intnumber1;doublesum;structinformation*next;};4.2模块接口设计1)所有函数模块声明如下:void load(structinformation*head);/*将信息存储到文件*/int main_menu();/*主菜单*/void menu_select(intsel,structinformation*head);/*进行主菜单操作选择*/void load_equipment();/*从文件中读取设备信息*/ void load_department();/*从文件中读取部门信息*/ voidsave_buy(structinformation*head);/*对设备进行购买输入*/void save_ruin(structinformation*head);/*对设备进行报废输入*/void ID_buy(structinformation*head);/*通过设备编号查询购买信息*/void num_buy(structinformation*head);/*通过部门编号查询购买信息*/void num_ruin(structinformation*head);/*通过部门编号查询报废信息*/void ID_ruin(structinformation*head);/*通过设备编号查询报废信息*/void buy_menu(structinformation*head);/*设备购买查询主菜单*/void ruin_menu(structinformation*head);/*设备报废查询主菜单*/第37页共38页 设备管理系统structinformation*scanf_add(structinformation*head);/*从TXT文件中导入上次存储的设备处理信息*/voidshow_information();/*显示购买和报废设备信息记录*/void show_menu(structinformation*head);/*显示全部信息主菜单*/int judge_date(chardate[11]);/*判断日期输入是否正确*/ void show_list(structinformation*head);/*部门可使用设备报表制作*/ voidprintftime();/*调用系统时间*/voidtongjishengyu();/*统计剩余使用次数*/1)并定义两个全局变量:intq;structintformation*head;2)主要模块的实现系统以主函数main()为入口,调用intmain_menu()函数,显示欢迎进入课程设计名称,直接进入主菜单界面,然后系统接收用户输入的选择,调用相应的函数,进入到下一级菜单进行相关工作。4.3以下是几个主要模块的流程图:1)主菜单函数:是否为0否打印主菜单接收用户选项是否合法调用对应选项函数进入下一级菜单退出系统是否是第37页共38页 设备管理系统图1主函数流程图1)购买设备函数:是打印购买设备子菜单输入设备编号选项否输入部门编号选项是否合法是否合法输入购买数量输入购买单价结束否图2购买设备流程图2)信息修改函数:第37页共38页 设备管理系统是打印购买历史子菜单输入查询方式选项否是否合法是否为0输入编号选项是否返回主菜单退出函数图3查询流程图5.运行结果5.1主菜单界面:图5主菜单界面输入功能选择,系统自动进入相应功能界面。第37页共38页 设备管理系统5.2设备信息界面:图6设备信息界面5.3部门信息界面:图7部门信息界面5.4购买历史查询信息界面:从键盘中输入选择,可以按设备编号和部门编号进行查询,并显示结果。第37页共38页 设备管理系统图8通过设备编号查询的结果5.5报废历史查询信息界面:从键盘中输入选择,可以按设备编号和部门编号进行查询,并显示结果。图9通过设备编号查询的结果第37页共38页 设备管理系统5.6显示全部信息界面:图10显示全部信息界面5.7设备信息报表:6.程序调试与测试6.1程序调试1.购买设备第37页共38页 设备管理系统从键盘输入需要购买的设备以及购买设备的编号。2.报废设备从键盘输入需要报废的设备信息。6.2程序测试1.购买信息第37页共38页 设备管理系统从键盘输入需要查询的方式。2.报废信息从键盘输入需要查询的方式。7.问题与不足(1)需求分析中存在的问题所有数据符合实际应用要求这一项没做好,导致所有数据都能随意输入,无论多大的数字都不会报错。(2)概要设计中不存在什么问题。(3)详细设计中存在的问题有不少地方都缺少报错,比如说输入设备数量时就算输入了英文也没有报错,反而把那个英文直接当做了1来处理。(4)代码编制中存在的问题结构不够精炼,有些拖泥带水,缺少实际经验。(5)调试和测试中不存在什么问题。第37页共38页 设备管理系统8.建议对于签到,每次签到都会有好多人代签,这导致了签到的无意义,我觉得取消签到或者严格查签到才能解决。9.编程体会通过这次大规模的编程,我发现了自己的许多不足,我的各个重点都掌握的不牢固,导致我花费了大量的时间去复习,当我复习完了再开始编程已经比别人慢了一大步,我发现程序的每一步都紧密相关着,然后我在老师与同学的帮助下,终于完成了本次编程。10.程序源代码:#include#include#include#include#include#includeintq;#define_TM_DEFINED#ifndef_TM_DEFINED/*定义时间结构体*/structtm{inttm_year;inttm_mon;inttm_mday;};/*定义设备结构体*/#endifstructequipment{intID;charname[20];}e[10];/*定义部门结构体*/structdepartment{intnum;charname[20];}d[4];/*购买和报废信息结构体*/structinformation{intID;/*设备名称*/第37页共38页 设备管理系统intnum;/*部门编号*/chardate[11];/*购买日期*/chardate1[11];/*报废日期*/intstyle;/*设备类型*/doubleprice;/*单价*/intnumber;/*购买数量*/intnumber1;/*报废数量*/doublesum;/*总价*/structinformation*next;};/*函数的声明*/voidload(structinformation*head);/*将信息存储到文件*/intmain_menu();/*主菜单*/voidmenu_select(intsel,structinformation*head);/*进行主菜单操作选择*/voidload_equipment();/*从文件中读取设备信息*/voidload_department();/*从文件中读取部门信息*/voidsave_buy(structinformation*head);/*对设备进行购买输入*/voidsave_ruin(structinformation*head);/*对设备进行报废输入*/voidID_buy(structinformation*head);/*通过设备编号查询购买信息*/voidnum_buy(structinformation*head);/*通过部门编号查询购买信息*/voidnum_ruin(structinformation*head);/*通过部门编号查询报废信息*/voidID_ruin(structinformation*head);/*通过设备编号查询报废信息*/voidbuy_menu(structinformation*head);/*设备购买查询主菜单*/voidruin_menu(structinformation*head);/*设备报废查询主菜单*/structinformation*scanf_add(structinformation*head);/*从TXT文件中导入上次存储的设备处理信息*/voidshow_information();/*显示购买和报废设备信息记录*/voidshow_menu(structinformation*head);/*显示全部信息主菜单*/intjudge_date(chardate[11]);/*判断日期输入是否正确*/voidshow_list(structinformation*head);/*部门可使用设备报表制作*/voidprintftime();/*调用系统时间*/voidtongjishengyu();/*统计剩余使用次数*//*选择菜单栏*/voidmenu_select(ints,structinformation*head)第37页共38页 设备管理系统{switch(s){case1:system("cls");load_equipment();break;case2:system("cls");load_department();break;case3:system("cls");save_buy(head);break;case4:system("cls");save_ruin(head);break;case5:system("cls");buy_menu(head);break;case6:system("cls");ruin_menu(head);break;case7:system("cls");tongjishengyu(head);break;case8:system("cls");show_menu(head);break;case9:system("cls");show_list(head);break;case0:system("cls");printf("********************************************************n");printf("*********谢谢使用!**********n");printf("****T1223-08-08****n");printf("****XXX****n");exit(0);}}/*显示主菜单界面*/intmain_menu(){inti;printf("1**********欢迎使用设备管理系统********************1n");printf("1***1.查询设备信息***1n");printf("1***2.查询部门信息***1n");printf("1***3.购买设备***1n");printf("1***4.报废设备***1n");printf("1***5.设备的购买历史查询***1n");printf("1***6.设备的报废历史查询***1n");printf("1***7.剩余使用次数***1n");printf("1***8.显示全部信息***1n");printf("1***9.设备信息报表***1n");printf("1***0.退出菜单***1n");printf("1**************************************************1n");while(1){第37页共38页 设备管理系统printf("请选择你所需要的操作序号(0~9):");do{scanf("%d",&i);if(i<0||i>9)printf("输入有误,请重新输入(0~9):");rewind(stdin);}while(i<0||i>9);system("cls");break;}returni;}/*读取显示设备信息*/voidload_equipment(){FILE*fp;structequipment*pt1=e;system("cls");if((fp=fopen("设备名称.txt","r"))==NULL){printf("打开错误!n");exit(0);}printf("**********************************设备信息界面*******************************");printf("nt设备编号(1~10)设备名n");while(!feof(fp)){fscanf(fp,"%d%s",&pt1->ID,&pt1->name);printf("ntt%dtt%s",pt1->ID,pt1->name);pt1++;}if(fclose(fp)){printf("不能关闭文件!!!n");exit(0);}第37页共38页 设备管理系统printf("nn********************************导入成功*********************************n");printf("n按Enter键返回");getchar();system("cls");}/*读取显示部门信息*/voidload_department(){FILE*fp;structdepartment*pt1=d;system("cls");if((fp=fopen("部门名称.txt","r"))==NULL){printf("打开错误!n");exit(0);}printf("*********************************部门信息界面**************************");printf("ntt部门编号(1~4)部门名称n");while(!feof(fp)){fscanf(fp,"%d%s",&pt1->num,&pt1->name);printf("ntt%dtt%s",pt1->num,pt1->name);pt1++;}if(fclose(fp)){printf("不能关闭文件!!!n");exit(0);}printf("nn*******************************导入成功*****************************n");printf("n按Enter键返回");getchar();system("cls");}/*记录购买设备的信息*/voidsave_buy(structinformation*head){structinformation*temp,*p=head;第37页共38页 设备管理系统system("cls");temp=(structinformation*)malloc(sizeof(structinformation));/*开辟一个新单元*/while(p->next!=NULL)p=p->next;printf("n设备编号部门编号购买日期设备状态(1买-1废)设备数量报废数量单价总价n");printf("请输入设备编号(1~10):");do{scanf("%d",&temp->ID);if(temp->ID<=0||temp->ID>10)printf("输入的设备编号有误,请重新输入(1~10):");rewind(stdin);}while(temp->ID<=0||temp->ID>10);printf("请输入部门编号(1~4):");do{scanf("%d",&temp->num);if(temp->num<=0||temp->num>4)printf("输入的部门编号有误,请重新输入(1~4):");rewind(stdin);}while(temp->num<=0||temp->num>4);{time_ttval;structtm*data;tval=time(NULL);data=localtime(&tval);printftime(p->date);printf("n当前时间(从系统调用)为:%sn",p->date);temp->date[0]=(data->tm_year+1900)/1000+"0";temp->date[1]=(data->tm_year+1900)/100%10+"0";temp->date[2]=(data->tm_year+1900)/10%100+"0";temp->date[3]=(data->tm_year+1900)%10+"0";temp->date[4]="-";temp->date[5]=(data->tm_mon+1)/10+"0";temp->date[6]=(data->tm_mon+1)%10+"0";temp->date[7]="-";temp->date[8]=(data->tm_mday)/10+"0";temp->date[9]=(data->tm_mday)%10+"0";temp->date[10]="";}/*将日期装换为字符型存入*/第37页共38页 设备管理系统temp->style=1;printf("请输入购买设备数量(整数):");do{scanf("%d",&temp->number);if(temp->number<=0)printf("输入的购买设备数量有误,请重新输入购买设备数量(整数):");rewind(stdin);}while(temp->number<=0);temp->number1=0;temp->price=1*temp->ID;printf("请输入设备单价:");do{scanf("%lf",&temp->price);if(temp->price<=0)printf("输入的设备单价有误,请重新输入设备单价:");rewind(stdin);}while(temp->price<=0);temp->sum=(temp->number)*(temp->price);printf("设备需要总价:%.2lfnn",temp->sum);p->next=temp;temp->next=NULL;getchar();load(head);printf("********************输入完成,按ENTER返回!!!*********************");getchar();system("cls");}/*记录报废设备的信息*/voidsave_ruin(structinformation*head){chardate2[10];FILE*fp;intm,n,s=0,o=0,g=0;structinformation*temp,*p=head,*w;system("cls");temp=(structinformation*)malloc(sizeof(structinformation));w=temp;while(p->next!=NULL)第37页共38页 设备管理系统p=p->next;printf("n设备编号部门编号购买日期设备状态(1买-1废)设备数量报废数量单价总价n");printf("请输入设备编号(1~10):");do{scanf("%d",&m);if(m<=0||m>10)printf("输入的设备编号有误,请重新输入(1~10):");rewind(stdin);}while(m<=0||m>10);printf("请输入部门编号(1~4):");do{scanf("%d",&n);if(n<=0||n>4)printf("输入的部门编号有误,请重新输入(1~4):");rewind(stdin);}while(n<=0||n>4);printf("n请输入报废日期,格式为(YYYY-MM-DD):");do{address:scanf("%s",date2);if(judge_date(date2)==0)printf("n您输入的日期格式不正确,请重新输入(YYYY-MM-DD):");}while(judge_date(date2)==0);if(strcmp(p->date,date2)>=0){printf("n>>>>>>>>提示:输入时间不能小于购买时间!请重新输入:");date2[0]="";gotoaddress;}strcpy(p->date1,date2);if((fp=fopen("购买报废记录.txt","r+"))==NULL){printf("打开错误!n");exit(0);}while(!feof(fp)){fscanf(第37页共38页 设备管理系统fp,"%d%d%s%d%d%d%lf%lfn",&w->ID,&w->num,w->date,&w->style,&w->number,&w->number1,&w->price,&w->sum);if(w->ID==m&&w->num==n){s=s+w->number;o=o+w->number1;g=s-o;}}printf("剩余使用数量:%d",g);q=g;temp->ID=m;temp->num=n;{time_ttval;structtm*data;tval=time(NULL);data=localtime(&tval);printftime(p->date);printf("n当前时间(从系统调用)为:%sn",p->date);temp->date[0]=(data->tm_year+1900)/1000+"0";temp->date[1]=(data->tm_year+1900)/100%10+"0";temp->date[2]=(data->tm_year+1900)/10%100+"0";temp->date[3]=(data->tm_year+1900)%10+"0";temp->date[4]="-";temp->date[5]=(data->tm_mon+1)/10+"0";temp->date[6]=(data->tm_mon+1)%10+"0";temp->date[7]="-";temp->date[8]=(data->tm_mday)/10+"0";temp->date[9]=(data->tm_mday)%10+"0";temp->date[10]="";}/*将日期装换为字符型存入*/temp->style=-1;temp->number=0;printf("请输入报废设备数量(整数)1~%d:",g);do{scanf("%d",&temp->number1);if(temp->number1<0||temp->number1>q)printf("输入的报废设备数量有误,请重新输入报废设备数量(整数):");rewind(stdin);}while(temp->number1<0||temp->number1>q);temp->price=1*temp->ID;printf("请输入设备单价:");temp->sum=(temp->number1)*(temp->price);do{scanf("%lf",&temp->price);第37页共38页 设备管理系统if(temp->price<=0)printf("输入的设备单价有误,请重新输入设备单价:");rewind(stdin);}while(temp->price<=0);temp->sum=(temp->number1)*(temp->price);printf("设备需要总价:%.2lfn",temp->sum);p->next=temp;temp->next=NULL;getchar();load(head);printf("********************输入完成,按ENTER返回!!!*********************");getchar();system("cls");}/*通过设备编号查询购买信息*/voidID_buy(structinformation*head){structinformation*p=head;intID1;printf("请输入设备编号(1~10)");do{scanf("%d",&ID1);if(ID1<=0||ID1>10)printf("输入的设备编号有误,请重新输入(1~10)");rewind(stdin);}while(ID1<=0||ID1>10);if(p->next==NULL){printf("购买信息为空。n");getchar();getchar();system("cls");return;}printf("n设备编号部门编号购买日期设备状态设备数量报废数量单价总价n");printf("(1买-1废)");while(p!=NULL){if(ID1==p->ID&&p->style==1)printf("n%dt%dt%st%dt%dt%dt%.2f第37页共38页 设备管理系统t%.2f",p->ID,p->num,p->date,p->style,p->number,p->number1,p->price,p->sum);p=p->next;}printf("n********************查询完成,按ENTER返回!!!*********************");getchar();system("cls");}/*通过部门编号查询设备购买信息*/voidnum_buy(structinformation*head){structinformation*p=head;intnum1;printf("请输入部门编号(1~4)");do{scanf("%d",&num1);if(num1<=0||num1>4)printf("输入的设备编号有误,请重新输入:");rewind(stdin);}while(num1<=0||num1>4);if(p->next==NULL){printf("购买信息为空。n");getchar();getchar();system("cls");return;}printf("n设备编号部门编号购买日期设备状态设备数量报废数量单价总价n");printf("(1买-1废)");while(p!=NULL){if(num1==p->num&&p->style==1)printf("n%dt%dt%st%dt%dt%dt%.2ft%.2f",p->ID,p->num,p->date,p->style,p->number,p->number1,p->price,p->sum);p=p->next;}printf("n********************查询完成,按ENTER返回!!!*****************");getchar();第37页共38页 设备管理系统system("cls");}/*通过设备编号查询报废信息*/voidID_ruin(structinformation*head){structinformation*p=head;intID1;printf("请输入设备编号(1~10)");do{scanf("%d",&ID1);if(ID1<=0||ID1>10)printf("输入的设备编号有误,请重新输入:");rewind(stdin);}while(ID1<=0||ID1>10);if(p->next==NULL){printf("购买信息为空。n");getchar();getchar();system("cls");return;}printf("n设备编号部门编号购买日期设备状态设备数量报废数量单价总价n");printf("(1买-1废)");while(p!=NULL){if(ID1==p->ID&&p->style==-1)printf("n%dt%dt%st%dt%dt%dt%.2ft%.2f",p->ID,p->num,p->date,p->style,p->number,p->number1,p->price,p->sum);p=p->next;}printf("n********************查询完成,按ENTER返回!!!*********************");getchar();getchar();system("cls");}/*通过部门编号查询设备报废信息*/voidnum_ruin(structinformation*head){第37页共38页 设备管理系统structinformation*p=head;intnum1;printf("请输入部门编号(1~4)");do{scanf("%d",&num1);if(num1<=0||num1>4)printf("输入的设备编号有误,请重新输入:");rewind(stdin);}while(num1<=0||num1>4);if(p->next==NULL){printf("购买信息为空。n");getchar();getchar();system("cls");return;}printf("n设备编号部门编号购买日期设备状态设备数量报废数量单价总价n");printf("(1买-1废)");while(p!=NULL){if(num1==p->num&&p->style==-1)printf("n%dt%dt%st%dt%dt%dt%.2ft%.2f",p->ID,p->num,p->date,p->style,p->number,p->number1,p->price,p->sum);p=p->next;}printf("n********************查询完成,按ENTER返回!!!*********************");getchar();getchar();system("cls");}/*读取购买报废记录信息*/structinformation*scanf_add(structinformation*head){structinformation*pt1=head;structinformation*temp;FILE*fp;system("cls");if((fp=fopen("购买报废记录.txt","r"))==NULL){printf("打开错误!n");第37页共38页 设备管理系统return0;}while(pt1->next!=NULL)pt1=pt1->next;while(!feof(fp)){temp=(structinformation*)malloc(sizeof(structinformation));fscanf(fp,"%d%d%s%d%d%d%lf%lfn",&temp->ID,&temp->num,temp->date,&temp->style,&temp->number,&temp->number1,&temp->price,&temp->sum);q=temp->number;pt1->next=temp;pt1=temp;}temp->next=NULL;if(fclose(fp)){printf("不能关闭文件!!!n");exit(0);}returnhead;getchar();system("cls");}/*显示购买报废设备信息记录*/voidshow_information(structinformation*head){structinformation*p=head->next;system("cls");if(p==NULL){printf("购买信息为空。n");getchar();getchar();system("cls");return;}printf("n设备编号部门编号购买日期设备状态设备数量报废数量单价总价n");printf("(1买-1废)");while(p!=NULL){第37页共38页 设备管理系统printf("n%dt%dt%st%dt%dt%dt%.2ft%.2f",p->ID,p->num,p->date,p->style,p->number,p->number1,p->price,p->sum);p=p->next;}printf("nn********************显示完成,按ENTER返回!!!*********************");getchar();system("cls");}/*设备购买信息查询显示界面*/voidbuy_menu(structinformation*head){ints;system("cls");printf("1*************************购买历史查询信息界面********************1n");printf("1*********1:通过设备编号查询购买信息********1n");printf("1*********2:通过部门编号查询购买信息********1n");printf("1*********0:返回********1n");printf("1*****************************************************************1");printf("n请输入0~2之间的数操作:");do{scanf("%d",&s);if(s<0||s>2)printf("n输入有误!请重新选择0~2之间的数操作:");rewind(stdin);}while(s<0||s>2);switch(s){case1:ID_buy(head);break;case2:num_buy(head);break;case0:system("cls");printf("**********************返回成功!**********************n");break;}}/*设备报废信息查询显示界面*/voidruin_menu(structinformation*head){ints;第37页共38页 设备管理系统system("cls");printf("1*************************报废历史查询信息界面********************1n");printf("1*********1:通过设备编号查询报废信息********1n");printf("1*********2:通过部门编号查询报废信息********1n");printf("1*********0:返回********1n");printf("1*****************************************************************1");printf("n请输入0~2之间的数操作:");do{scanf("%d",&s);if(s<0||s>3)printf("n输入有误!请重新选择0~2之间的数操作:");rewind(stdin);}while(s<0||s>2);switch(s){case1:ID_ruin(head);break;case2:num_ruin(head);break;case0:system("cls");printf("**********************返回成功!**********************n");break;}}/*显示全部信息的界面*/voidshow_menu(structinformation*head){ints;system("cls");printf("1******************************显示全部信息******************************1n");printf("1*****1:显示设备信息****1n");printf("1*****2:显示部门信息****1n");printf("1*****3:显示购买,报废信息****1n");printf("1*****0:返回****1n");printf("1************************************************************************1");printf("n请输入0~3之间的数选择需要的操作:");do{scanf("%d",&s);if(s<0||s>3)第37页共38页 设备管理系统printf("n输入有误!请重新选择0~3之间的数选择需要的操做:");rewind(stdin);}while(s<0||s>3);switch(s){case1:load_equipment();break;case2:load_department();break;case3:show_information(head);break;case0:system("cls");printf("**********************返回成功!**********************n");break;}}/*将信息存储到文件*/voidload(structinformation*head){structinformation*p=head->next;FILE*fp;system("cls");if((fp=fopen("购买报废记录.txt","w"))==NULL){printf("打开错误!n");exit(0);}while(p!=NULL){fprintf(fp,"n%dt%dt%st%dt%dt%dt%.2ft%.2f",p->ID,p->num,p->date,p->style,p->number,p->number1,p->price,p->sum);p=p->next;}if(fclose(fp)){printf("不能关闭文件!!!n");exit(0);}if(p==NULL)printf("nn***************************保存成功!***************************nn");}/*部门可使用设备报表制作*/voidshow_list(structinformation*head)第37页共38页 设备管理系统{structinformation*p=head->next;chardate1[11];intlist[4][2];inti,j;{time_ttval;structtm*data;tval=time(NULL);data=localtime(&tval);printf("制表时间:%d-%d-%dn",data->tm_year+1900,data->tm_mon+1,data->tm_mday);}for(i=0;i<4;i++)for(j=0;j<2;j++)list[i][j]=0;while(p!=NULL){if(strcmp(date1,p->date)>=0){if(p->num==1&&p->style==1)list[0][0]+=(p->number-p->number1);if(p->num==1&&p->style==-1)list[0][1]+=(p->number1);if(p->num==2&&p->style==1)list[1][0]+=(p->number-p->number1);if(p->num==2&&p->style==-1)list[1][1]+=(p->number1);if(p->num==3&&p->style==1)list[2][0]+=(p->number-p->number1);if(p->num==3&&p->style==-1)list[2][1]+=(p->number1);if(p->num==4&&p->style==1)list[3][0]+=(p->number-p->number1);if(p->num==4&&p->style==-1)list[3][1]+=(p->number1);}p=p->next;}printf("nn**************************************************************n");printf("部门编号剩余设备数量报废设备数量");for(i=0;i<4;i++)第37页共38页 设备管理系统{printf("ntt%d",i+1);for(j=0;j<2;j++)printf("tt%d",list[i][j]);}printf("ntt*********************************************");printf("nnntt可使用设备数量=剩余设备数量-报废设备数量");printf("nnntt*******************************************");printf("nnntt$$$部门1可以使用设备数量:%d$$$",list[0][0]-list[0][1]);printf("ntt$$$部门2可以使用设备数量:%d$$$",list[1][0]-list[1][1]);printf("ntt$$$部门3可以使用设备数量:%d$$$",list[2][0]-list[2][1]);printf("ntt$$$部门4可以使用设备数量:%d$$$",list[3][0]-list[3][1]);printf("nn********************输入完成,按ENTER返回!!!*********************");getchar();system("cls");return;}/*判断日期输入是否正确*/intjudge_date(chardate[]){intyear,month,day,i,judegement;if(strlen(date)!=10)return0;if((date[4]!="-")||(date[7]!="-"))return0;for(i=0,year=0;i<4;i++)/*字符串转化成整型*/year=year*10+(date[i]-"0");for(i=5,month=0;i<7;i++)month=month*10+(date[i]-"0");for(i=8,day=0;i<10;i++)day=day*10+(date[i]-"0");if(month<=0||month>12)return0;else{judegement=(year%4==0&&year%100!=0||year%400==0);第37页共38页 设备管理系统/*判断是否为闰年:等于1为闰年*/if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){if(day<0||day>31)return0;elsereturn1;}elseif(month==4||month==6||month==9||month==11){if(day<0||day>30)return0;elsereturn1;}elseif(judegement==1&&month==2){if(day<0||day>29)return0;elsereturn1;}else{if(day<0||day>28)return0;elsereturn1;}}}/*主函数*/main(){intsize=sizeof(structinformation);structinformation*head;head=(structinformation*)malloc(size);head->next=NULL;system("cls");第37页共38页 设备管理系统{scanf_add(head);while(1){menu_select(main_menu(),head);}}}/*调用系统时间*/voidprintftime(chardate[]){charstr1[10];time_tfirst;structtm*t;first=time(NULL);t=localtime(&first);itoa(t->tm_year+1900,date,10);strcat(date,"-");if(t->tm_mon+1<10)strcat(date,"0");itoa(t->tm_mon+1,str1,10);strcat(date,str1);strcat(date,"-");if(t->tm_mday<10)strcat(date,"0");itoa(t->tm_mday,str1,10);strcat(date,str1);}/*统计设备信息*/voidtongjishengyu(structinformation*head){chardate3[11];FILE*fp;intm,n,s=0,o=0,g=0;structinformation*temp,*p=head,*w;system("cls");temp=(structinformation*)malloc(sizeof(structinformation));w=temp;while(p->next!=NULL)p=p->next;第37页共38页 设备管理系统printf("请输入设备编号(1~10):");do{scanf("%d",&m);if(m<=0||m>10)printf("输入的设备编号有误,请重新输入(1~10):");rewind(stdin);}while(m<=0||m>10);printf("请输入部门编号(1~4):");do{scanf("%d",&n);if(n<=0||n>4)printf("输入的部门编号有误,请重新输入(1~4):");rewind(stdin);}while(n<=0||n>4);printf("n请输入日期,格式为(YYYY-MM-DD):");do{address:scanf("%s",date3);if(judge_date(date3)==0)printf("n您输入的日期格式不正确,请重新输入(YYYY-MM-DD):");}while(judge_date(date3)==0);if(strcmp(p->date,date3)>=0){printf("n>>>>>>>>提示:输入时间不能小于购买时间!请重新输入:");date3[0]="";gotoaddress;}if((fp=fopen("购买报废记录.txt","r+"))==NULL){printf("打开错误!n");exit(0);}while(!feof(fp)){fscanf(fp,"%d%d%s%d%d%d%lf%lfn",&w->ID,&w->num,w->date,&w->style,&w->number,&w->number1,&w->price,&w->sum);if(w->ID==m&&w->num==n){s=s+w->number;o=o+w->number1;g=s-o;}}printf("剩余使用数量:%dn",g);system("pause");第37页共38页 设备管理系统temp->ID=m;temp->num=n;printf("********************输入完成,按ENTER返回!!!*********************");getchar();system("cls");}11.参考文献[1]廖湖声.C程序设计案例教程.人民邮电出版社,2010.9[2]何钦铭.C语言程序设计.高等教育出版社,2009.5.[3]谭浩强.C程序设计(第2、3、4版).清华大学出版社,2000.1.[4]《C语言程序设计教程》,杨路明著,北京邮电大学出版社.12.用户使用手册(1)本系统能够查询设备信息,部门信息。能够购买设备,报废设备。能够查询设备的购买历史与报废历史。能够查看剩余使用次数,能够显示全部信息。能查看设备信息报表。(2)使用本系统前需要新建3个文本文件,分别是"设备名称.txt","部门名称.txt","购买报废记录.txt"。姓名:XXX日期:2013年6月17日第37页共38页