C语言课程设计--实验设备管理系统设计(共26页).doc
精选优质文档-倾情为你奉上C语言课程设计院系: 姓名: 学号:班号:指导教师: 日期: 目录一 题目要求(1)二 需求分析(1)三 总体设计(1)四 详细设计(1)五 完整程序(12)六 上机操作(21)七 结束语(24)一.题目要求 实验设备信息包括:设备编号,设备种类(如:微机、打印机、扫描仪等等),设备名称,设备价格,设备购入日期等。试设计一实验设备信息管理系统,使之能提供以下功能:(1) 能够完成对设备的录入和修改(2) 对设备进行分类统计(3) 设备的查询二.需求分析 实验室设备信息用文件存储,提供文件的输入输出操作;要能够完成设备的录入和修改,需要提供设备添加和修改操作;实现对设备进行分类统计,需要提供排序操作;实现对设备的插叙需要提供查找操作,设备的查询可根据设备编号、设备种类、设备名称、设备购入日期、正常设备(未报废的)等多种方式查询;另外还要提供键盘式选择菜单以实现功能选择。三.总体设计根据上面的需求分析,可以将这个系统的设计分为以下模块 实验设备管理系统信息输入信息添加信息修改信息统计信息搜索四.详细设计1 主函数 流程图 显示一系列功能选项输入n,判断n是否是0-6根据n的值调用各功能模块函数 NY 程序 main() /*主函数*/int n,w,t;for(t=0;t<1;t+) 1doputs("tt*MENU*nn");puts("tt 1.Enter new data");puts("tt 2.Addition data");puts("tt 3.Modify data");puts("tt 4.Statist ");puts("tt 5.Search");puts("tt 6.Exit");puts("nntt*n");printf("What do you want to do(1-6):");scanf("%d",&n);if(n<1|n>6) /*对选择的数字作出判断*/ w=1; getchar();else w=0;while(w=1);switch(n) case 1:t=enter();break; /*输入模块*/ case 2:t=enter(); break; /*追加模块*/ case 3:t=modifty();break; /*修改模块*/ case 4:t=total();break; /*统计模块*/ case 5:t=search();break; /*搜索模块*/ case 6:exit(0); /*退出*/ 2.各功能模块设计(1)输入模块 流程图输入设备的各项详细信息输入用户要输入设备的个数i将输入的信息存储到文件中 程序 /*输入模块*/ 2 int enter() /*输入模块*/FILE *fp;EQ newequ;int i,j;int c;printf("*n");printf("Add new equimentn");printf("*n");printf("How many equiments do you want to add?n");scanf("%d",&i); /*输入要输入的设备个数*/for(j=0;j<i;j+)printf("-n");printf("Input equipcoden");scanf("%s",newequ.equipCode);printf("Input equiptypen");scanf("%s",newequ.equipType);printf("Input equipnamen");scanf("%s",newequ.equipName);printf("Input equipPricen");scanf("%f",&newequ.equipPrice);printf("Input buyYearn");scanf("%d",&newequ.buyYear);printf("Input buyMonthn");scanf("%d",&newequ.buyMonth);printf("Input buyDayn");scanf("%d",&newequ.buyDay);printf("Input scrapn");scanf("%d",&newequ.scrap);printf("Input scrapYearn");scanf("%d",&newequ.scrapYear);printf("Input scrapMonthn");scanf("%d",&newequ.scrapMonth);printf("Input scrapDayn");scanf("%d",&newequ.scrapDay);if(fp=fopen("test.txt","w")=NULL) /*打开文件,输入保存*/printf("Can not open file!n"); 3fprintf(fp,"%s %s %s %f %d %d %d %d %d %d %d",newequ.equipCode,newequ.equipType,newequ.equipName,newequ.equipPrice,newequ.buyYear,newequ.buyMonth,newequ.buyDay,newequ.scrap,newequ.scrapYear,newequ.scrapMonth,newequ.scrapDay); fclose(fp);printf("n-n");printf("Return to main menu? n");printf("1.YES n");printf("2.NO,I want to quit nown");scanf("%d",&c);if(c=1)return(-1);if(c=2)return(0); /*任务结束选择是返回主菜单还是跳出*/(2)追加模块流程图 程序 /*追加模块*/ int enter() /*追加模块*/FILE *fp;EQ newequ;int i,j;int c;printf("*n");printf("Add new equimentn");printf("*n");printf("How many equiments do you want to add?n");scanf("%d",&i); /*输入要追加的设备个数*/for(j=0;j<i;j+) 4printf("-n");printf("Input equipcoden");scanf("%s",newequ.equipCode);printf("Input equiptypen");scanf("%s",newequ.equipType);printf("Input equipnamen");scanf("%s",newequ.equipName);printf("Input equipPricen");scanf("%f",&newequ.equipPrice);printf("Input buyYearn");scanf("%d",&newequ.buyYear);printf("Input buyMonthn");scanf("%d",&newequ.buyMonth);printf("Input buyDayn");scanf("%d",&newequ.buyDay);printf("Input scrapn");scanf("%d",&newequ.scrap);printf("Input scrapYearn");scanf("%d",&newequ.scrapYear);printf("Input scrapMonthn");scanf("%d",&newequ.scrapMonth);printf("Input scrapDayn");scanf("%d",&newequ.scrapDay);if(fp=fopen("test.txt","w")=NULL) /*打开文件,输入保存*/printf("Can not open file!n");fprintf(fp,"%s %s %s %f %d %d %d %d %d %d %d",newequ.equipCode,newequ.equipType,newequ.equipName,newequ.equipPrice,newequ.buyYear,newequ.buyMonth,newequ.buyDay,newequ.scrap,newequ.scrapYear,newequ.scrapMonth,newequ.scrapDay); fclose(fp);printf("n-n");printf("Return to main menu? n");printf("1.YES n");printf("2.NO,I want to quit nown");scanf("%d",&c); 5if(c=1)return(-1);if(c=2)return(0); /*任务结束选择是返回主菜单还是跳出*/(3)修改模块 需求分析 此模块可以根据客户需要对以记录在文件中的信息进行修改 流程图 输入要修改的设备编号是否找到该设备资料显示找到的记录,调用修改函数显示没有找到对该设备的信息进行修改返回主菜单返回主菜单y n 程序 /*修改模块*/ int modifty() /*修改模块*/EQ equ50;char code10;int i,j,c;FILE *fp;printf("*n");printf("Modifty for the equimentn");printf("*n");printf("Please input the equipcode for modiftyingn");scanf("%s",code); /*输入要修改的设备编号*/printf("-n");if(fp=fopen("test.txt","r")=NULL) 6printf("nCan not open test!n");for(i=0;!feof(fp);i+) fscanf(fp,"%s %s %s %f %d %d %d %d %d %d %d",equi.equipCode,equi.equipType,equi.equipName,&equi.equipPrice,&equi.buyYear,&equi.buyMonth,&equi.buyDay,&equi.scrap,&equi.scrapYear,&equi.scrapMonth,&equi.scrapDay); if(strcmp(equi.equipCode,code)=0)printf("-n");printf("Input new equipcoden");scanf("%s",equi.equipCode);printf("Input new equiptypen");scanf("%s",equi.equipType);printf("Input new equipnamen");scanf("%s",equi.equipName);printf("Input equipPricen");scanf("%f",&equi.equipPrice);printf("Input new buyYearn");scanf("%d",&equi.buyYear);printf("Input new buyMonthn");scanf("%d",&equi.buyMonth);printf("Input new buyDayn");scanf("%d",&equi.buyDay);printf("Input new scrapn");scanf("%d",&equi.scrap);printf("Input new scrapYearn");scanf("%d",&equi.scrapYear);printf("Input new scrapMonthn");scanf("%d",&equi.scrapMonth);printf("Input new scrapDayn");scanf("%d",&equi.scrapDay); /*将修改后的信息写如文件中*/fclose(fp);j=i;if(fp=fopen("test.txt","w")=NULL)printf("nCan not open test!n"); 7for(i=0;i<j;i+)printf("nwrite!n"); fprintf(fp,"%s %s %s %f %d %d %d %d %d %d %d",equi.equipCode,equi.equipType,equi.equipName,equi.equipPrice,equi.buyYear,equi.buyMonth,equi.buyDay,equi.scrap,equi.scrapYear,equi.scrapMonth,equi.scrapDay);fclose(fp); printf("n-n");printf("Return to main menu? n");printf("1.YES n");printf("2.NO,I want to quit nown");scanf("%d",&c);if(c=1)return(-1);if(c=2)return(0);返回主菜单(4)统计模块 需求分析将已经输入的设备信息进行统计,并显示设备总数、价格总额等信息流程图打开文件,并对文件中的设备信息进行统计计算输出统计结果返回主菜单 程序int total()int c;float sum=0;int count=0;float aver=0;char type20;EQ equ;int i;FILE *fp;if(fp=fopen("test.txt","r")=NULL)printf("nWrongn"); 8printf("please input equipType:n");scanf("%s",type);for(i=0;!feof(fp);i+)fscanf(fp,"%s %s %s %f %d %d %d %d %d %d %d",equ.equipCode,equ.equipType,equ.equipName,&equ.equipPrice,&equ.buyYear,&equ.buyMonth,&equ.buyDay,&equ.scrap,&equ.scrapYear,&equ.scrapMonth,&equ.scrapDay); printf("nOK!n");printf("%s,%s,%s,%f,%d,%d,%d,%d,%d,%d,%dn",equ.equipCode,equ.equipType,equ.equipName,equ.equipPrice,equ.buyYear,equ.buyMonth,equ.buyDay,equ.scrap,equ.scrapYear,equ.scrapMonth,equ.scrapDay);if(strcmp(equ.equipType,type)=0) count+; sum+=equ.equipPrice; aver=sum/count; fclose(fp);printf("-Statist-Result-");printf("nnthe number of this type is:%d",count);printf("nnthe total sum of price is:%f",sum);printf("nnthe aver of total price is:%f",aver);printf("nPress any key to exit.");getch();printf("n-n");printf("Return to main menu? n");printf("1.YES n");printf("2.NO,I want to quit nown");scanf("%d",&c);if(c=1)return(-1);if(c=2)return(0);(5)搜索模块 9 需求分析 该模块的功能是查找用户需要的对应记录,可以分别根据设备编号、设备种类、设备名称、设备购入日期、正常设备(未报废的)等多种方式查询。 流程图询问用户想要选择的搜索方式 y设备编号设备种类设备名称设备购入日期是否报废yn显示找到的文件提示没有找到让用户选择1)返回主菜单2)跳出系统 程序 /*搜索模块*/int search() /*搜索模块*/char code10;char name20;float price;int choice;int c;FILE *fp;EQ equ;int i;fp=fopen("test.txt","r");if(fp=NULL)exit(0);printf("please choose the way of search:nn");printf("1.search by equipCodenn");printf("2.search by equipName nn");printf("3.search by equipPricenn");printf("0.returnnn");printf("please input number 0-5:");scanf("%d",&choice); 10 if(choice=0)exit(0);switch(choice)case 0:exit(0);break;case 1: printf("please input equipCode:n"); scanf("%s",code); for(i=0;!feof(fp);i+) fscanf(fp,"%s %s %s %f %d %d %d %d %d %d %d",equ.equipCode,equ.equipType,equ.equipName,&equ.equipPrice,&equ.buyYear,&equ.buyMonth,&equ.buyDay,&equ.scrap,&equ.scrapYear,&equ.scrapMonth,&equ.scrapDay); if(strcmp(equ.equipCode,code)=0) printf("nequipCode,equipType,equipName,equipPrice,buyYear,buyMonth,buyDay,scrap,scrapYear,scrapMonth,ScrapDayn"); printf("n%s,%s,%s,%f,%d,%d,%d,%d,%d,%d,%dn",equ.equipCode,equ.equipType,equ.equipName,equ.equipPrice,equ.buyYear,equ.buyMonth,equ.buyDay,equ.scrap,equ.scrapYear,equ.scrapMonth,equ.scrapDay); getch();break;case 2: printf("please input equipName:n"); scanf("%s",name); for(i=0;!feof(fp);i+) fscanf(fp,"%s %s %s %f %d %d %d %d %d %d %d",equ.equipCode,equ.equipType,equ.equipName,&equ.equipPrice,&equ.buyYear,&equ.buyMonth,&equ.buyDay,&equ.scrap,&equ.scrapYear,&equ.scrapMonth,&equ.scrapDay); if(strcmp(equ.equipName,code)=0) printf("nequipCode,equipType,equipName,equipPrice,buyYear,buyMonth,buyDay,scrap,scrapYear,scrapMonth,ScrapDayn"); 11 printf("n%s,%s,%s,%f,%d,%d,%d,%d,%d,%d,%dn",equ.equipCode,equ.equipType,equ.equipName,equ.equipPrice,equ.buyYear,equ.buyMonth,equ.buyDay,equ.scrap,equ.scrapYear,equ.scrapMonth,equ.scrapDay); getch();break;case 3: printf("please input equipPrice:n"); scanf("%d",&price); for(i=0;!feof(fp);i+) fscanf(fp,"%s %s %s %f %d %d %d %d %d %d %d",equ.equipCode,equ.equipType,equ.equipName,&equ.equipPrice,&equ.buyYear,&equ.buyMonth,&equ.buyDay,&equ.scrap,&equ.scrapYear,&equ.scrapMonth,&equ.scrapDay); if(equ.equipPrice=price) printf("nequipCode,equipType,equipName,equipPrice,buyYear,buyMonth,buyDay,scrap,scrapYear,scrapMonth,ScrapDayn"); printf("n%s,%s,%s,%f,%d,%d,%d,%d,%d,%d,%dn",equ.equipCode,equ.equipType,equ.equipName,equ.equipPrice,equ.buyYear,equ.buyMonth,equ.buyDay,equ.scrap,equ.scrapYear,equ.scrapMonth,equ.scrapDay); getch();break;fclose(fp);printf("n-n");printf("Return to main menu? n");printf("1.YES n");printf("2.NO,I want to quit nown");scanf("%d",&c);if(c=1)return(-1);if(c=2)return(0);五.完整程序#include<stdio.h> 12#include<stdlib.h>#include<string.h>typedef struct epuipmentInfo char equipCode10; char equipType20; char equipName20; float equipPrice; int buyYear; int buyMonth; int buyDay; int scrap; int scrapYear; int scrapMonth; int scrapDay;EQ;int enter()FILE *fp;EQ newequ;int i,j;int c;printf("*n");printf("Add new equimentn");printf("*n");printf("How many equiments do you want to add?n");scanf("%d",&i);for(j=0;j<i;j+)printf("-n");printf("Input equipcoden");scanf("%s",newequ.equipCode);printf("Input equiptypen");scanf("%s",newequ.equipType);printf("Input equipnamen");scanf("%s",newequ.equipName);printf("Input equipPricen");scanf("%f",&newequ.equipPrice);printf("Input buyYearn"); 13scanf("%d",&newequ.buyYear);printf("Input buyMonthn");scanf("%d",&newequ.buyMonth);printf("Input buyDayn");scanf("%d",&newequ.buyDay);printf("Input scrapn");scanf("%d",&newequ.scrap);printf("Input scrapYearn");scanf("%d",&newequ.scrapYear);printf("Input scrapMonthn");scanf("%d",&newequ.scrapMonth);printf("Input scrapDayn");scanf("%d",&newequ.scrapDay);if(fp=fopen("test.txt","w")=NULL)printf("Can not open file!n");fprintf(fp,"%s %s %s %f %d %d %d %d %d %d %d",newequ.equipCode,newequ.equipType,newequ.equipName,newequ.equipPrice,newequ.buyYear,newequ.buyMonth,newequ.buyDay,newequ.scrap,newequ.scrapYear,newequ.scrapMonth,newequ.scrapDay); fclose(fp);printf("n-n");printf("Return to main menu? n");printf("1.YES n");printf("2.NO,I want to quit nown");scanf("%d",&c);if(c=1)return(-1);if(c=2)return(0);int modifty()EQ equ50;char code10;int i;int j; 14int c;FILE *fp;printf("*