1、c语言实践实验设备管理完整中国地质大学(武汉)机械设计制造及其自动化专业072105陈乾#include#include#define AMOUNT 50typedef struct int year。 int month。 int day。DATE。struct EQU int num。 /*本程序默认设备编号各不相同且不为0*/ char type20。 char name20。 int price。 DATE buy_time。 int scrap。 /*0表示报废1表示不报废*/ DATE scr_time。equAMOUNT。 /*公共函数 保存与加载函数*/void save()
2、FILE *fp。 int i。 if(fp=fopen(record,wb)=NULL) printf(cannot open filen)。 for(i=0。iAMOUNT。i+) if(fwrite(&equi,sizeof(struct EQU),1,fp)!=1) printf(file write errorn)。 fclose(fp)。void load() FILE *fp。 int i。 if(fp=fopen(record,rb)=NULL) printf(cannot open filen)。 for(i=0。inum!=0)p+。 printf(请输入设备编号n)。 s
3、canf(%d,&p-num)。 printf(请输入设备种类n)。 scanf(%s,p-type)。 printf(请输入设备名称n)。 scanf(%s,p-name)。 printf(请输入设备价格n)。 scanf(%d,&p-price)。 printf(请输入设备购买日期 年 月 日以空格隔开n)。 scanf(%d%d%d,&p-buy_time.year,&p-buy_time.month,&p-buy_time.day)。 p-scrap=1。 p-scr_time.year=0。 p-scr_time.month=0。 p-scr_time.day=0。 printf(n
4、以下记录录入成功n)。 printf(编号:%d 设备种类:%s 设备名称:%sn价格:%d 购买日期:%d %d %dn是否报废:%d 报废日期:%d %d %d n,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 printf(继续录入请按1,退出请按2n)。 scanf(%d,&flag)。 while(flag=1)。 save()。/*修改模块*/void chang
5、e() int flag,n,i=0。 struct EQU *p。 p=equ。 load()。 printf(请输入要更改的设备编号n)。 scanf(%d,&flag)。 for(i=0,p=equ。inum=flag) do printf(请输入要更改的信息:n1设备编号n2设备种类n3设备名称n4设备价格n5购买日期n6是否报废n7退出n)。 scanf(%d,&n)。 switch(n) case 1: printf(请输入新的设备编号n)。 scanf(%d,&p-num)。break。 case 2: printf(请输入新的设备种类n)。 scanf(%s,p-type)。b
6、reak。 case 3: printf(请输入新的设备名称n)。 scanf(%s,p-name)。break。 case 4: printf(请输入新的价格n)。 scanf(%d,&p-price)。break。 case 5: printf(请输入新的设备购买日期 年 月 日n)。 scanf(%d%d%d,&p-buy_time.year,&p-buy_time.month,&p-buy_time.day)。break。 case 6: printf(请输入是否报废设备n)。 scanf(%d,&p-scrap)。 printf(请输入报废日期n)。 scanf(%d%d%d,&p-
7、scr_time.year,&p-scr_time.month,&p-scr_time.day)。 break。 case 7: break。 while(n!=7)。 printf(修改后的记录为:)。 printf(编号:%d 设备种类:%s 设备名称:%sn价格:%d 购买日期:%d %d %dn是否报废:%d 报废日期:%d %d %d n,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_t
8、ime.day)。 save()。/*查询模块*/void search() int n,num,i,year,month,day。 char s20。 struct EQU *p。 p=equ。 load()。 do printf(1.按编号查询n)。 printf(2.按设备种类查询n)。 printf(3.按设备名称查询n)。 printf(4.按购买日期查询n)。 printf(5.查询正常的设备n)。 printf(6.退出n)。 scanf(%d,&n)。 switch(n) case 1: printf(请输入要查询的设备编号n)。 scanf(%d,&num)。 for(i=0
9、,p=equ。inum=num) printf(编号:%d 设备种类:%s 设备名称:%sn价格:%d 购买日期:%d %d %dn是否报废:%d 报废日期:%d %d %d n,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 2: printf(请输入要查询的设备种类n)。 scanf(%s,s)。 for(i=0,p=equ。itype)=0) pr
10、intf(编号:%d 设备种类:%s 设备名称:%s价格:%d 购买日期:%d %d %d 是否报废:%d 报废日期:%d %d %dn,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 3: printf(请输入要查询的设备名称n)。 scanf(%s,s)。 for(i=0,p=equ。iname)=0) printf(编号:%d 设备种类:%s 设备
11、名称:%s价格:%d 购买日期:%d %d %d 是否报废:%d 报废日期:%d %d %dn,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 4: printf(请输入要查询的设备购买日期 年 月 日n)。 scanf(%d%d%d,&year,&month,&day)。 for(i=0,p=equ。ibuy_time.year&month=p-buy
12、_time.month&day=p-buy_time.day) printf(编号:%d 设备种类:%s 设备名称:%s价格:%d 购买日期:%d %d %d 是否报废:%d 报废日期:%d %d %dn,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 5: printf(未报废的设备有:n)。 for(i=0,p=equ。iscrap=1) print
13、f(编号:%d 设备种类:%s 设备名称:%s价格:%d 购买日期:%d %d %d 是否报废:%d 报废日期:%d %d %dn,p-num,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 6: break。 while(n!=6)。/*统计模块*/void statis() int flag,n,i,j,k=0。 char s20。 struct EQU *p。
14、 struct EQU strAMOUNT,str11。 p=equ。 load()。 printf(请输入要查询的设备种类n)。 scanf(%s,&s0)。 for(i=0,n=0,p=equ。itype)=0) strn.num=p-num。 strn.price=p-price。 strcpy(strn.name,p-name)。 strn.scrap=p-scrap。 strcpy(strn.type,p-type)。 strn.buy_time.year=p-buy_time.year。 strn.buy_time.month=p-buy_time.month。 strn.buy_
15、time.day=p-buy_time.day。 strn.scr_time.day=p-scr_time.day。 strn.scr_time.month=p-scr_time.month。 strn.scr_time.year=p-scr_time.year。 n+。 /*以上程序是将需要查询的设备种类的所有设备信息存入数组str中*/ do printf(1.按编号排序n)。 printf(2.按价格排序n)。 printf(3.按购买日期排序n)。 printf(4.退出n)。 /*这段程序之后出错*/ scanf(%d,&flag)。 switch(flag) case 1: for
16、(j=0。jn-1。j+) /*起泡法排序*/ for(i=0。istri+1.num) str10.num=stri.num。 str10.buy_time.day=stri.buy_time.day。 /*t=ai*/ str10.buy_time.month=stri.buy_time.month。 str10.buy_time.year=stri.buy_time.year。 str10.scr_time.year=stri.scr_time.year。 str10.scr_time.month=stri.scr_time.month。 str10.scr_time.day=stri.
17、scr_time.day。 str10.price=stri.price。 str10.scrap=stri.scrap。 strcpy(str10.name,stri.name)。 strcpy(str10.type,stri.type)。 stri.num=stri+1.num。 stri.buy_time.day=stri+1.buy_time.day。 /*ai=ai+1*/ stri.buy_time.month=stri+1.buy_time.month。 stri.buy_time.year=stri+1.buy_time.year。 stri.scr_time.year=str
18、i+1.scr_time.year。 stri.scr_time.month=stri+1.scr_time.month。 stri.scr_time.day=stri+1.scr_time.day。 stri.price=stri+1.price。 stri.scrap=stri+1.scrap。 strcpy(stri.name,stri+1.name)。 strcpy(stri.type,stri+1.type)。 stri+1.num=str10.num。 stri+1.buy_time.day=str10.buy_time.day。 /*ai+1=t*/ stri+1.buy_tim
19、e.month=str10.buy_time.month。 stri+1.buy_time.year=str10.buy_time.year。 stri+1.scr_time.year=str10.scr_time.year。 stri+1.scr_time.month=str10.scr_time.month。 stri+1.scr_time.day=str10.scr_time.day。 stri+1.price=str10.price。 stri+1.scrap=str10.scrap。 strcpy(stri+1.name,str10.name)。 strcpy(stri+1.type
20、,str10.type)。 for(i=0,p=str。inum,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 2: for(j=0。jn-1。j+) /*起泡法排序*/ for(i=0。i=stri+1.price) str10.num=stri.num。 str10.buy_time.day=stri.buy_time.day。 /*t=ai*/ str10.
21、buy_time.month=stri.buy_time.month。 str10.buy_time.year=stri.buy_time.year。 str10.scr_time.year=stri.scr_time.year。 str10.scr_time.month=stri.scr_time.month。 str10.scr_time.day=stri.scr_time.day。 str10.price=stri.price。 str10.scrap=stri.scrap。 strcpy(str10.name,stri.name)。 strcpy(str10.type,stri.typ
22、e)。 stri.num=stri+1.num。 stri.buy_time.day=stri+1.buy_time.day。 /*ai=ai+1*/ stri.buy_time.month=stri+1.buy_time.month。 stri.buy_time.year=stri+1.buy_time.year。 stri.scr_time.year=stri+1.scr_time.year。 stri.scr_time.month=stri+1.scr_time.month。 stri.scr_time.day=stri+1.scr_time.day。 stri.price=stri+1
23、.price。 stri.scrap=stri+1.scrap。 strcpy(stri.name,stri+1.name)。 strcpy(stri.type,stri+1.type)。 stri+1.num=str10.num。 stri+1.buy_time.day=str10.buy_time.day。 /*ai+1=t*/ stri+1.buy_time.month=str10.buy_time.month。 stri+1.buy_time.year=str10.buy_time.year。 stri+1.scr_time.year=str10.scr_time.year。 stri
24、+1.scr_time.month=str10.scr_time.month。 stri+1.scr_time.day=str10.scr_time.day。 stri+1.price=str10.price。 stri+1.scrap=str10.scrap。 strcpy(stri+1.name,str10.name)。 strcpy(stri+1.type,str10.type)。 for(i=0,p=str。inum,p-type,p-name,p-price,p-buy_time.year,p-buy_time.month,p-buy_time.day,p-scrap,p-scr_time.year,p-scr_time.month,p-scr_time.day)。 break。 case 3: /*由于程序过于复杂 需连续用3次起泡法 所以按购买日期排序只对年份排序*/ for(j=0。jn-1。j+) /*起泡法排序*/ for(i=0。in-1-j。i+) if(stri.buy_ti
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2