c语言实践实验设备管理完整.docx

上传人:b****4 文档编号:4071855 上传时间:2023-05-06 格式:DOCX 页数:17 大小:17.52KB
下载 相关 举报
c语言实践实验设备管理完整.docx_第1页
第1页 / 共17页
c语言实践实验设备管理完整.docx_第2页
第2页 / 共17页
c语言实践实验设备管理完整.docx_第3页
第3页 / 共17页
c语言实践实验设备管理完整.docx_第4页
第4页 / 共17页
c语言实践实验设备管理完整.docx_第5页
第5页 / 共17页
c语言实践实验设备管理完整.docx_第6页
第6页 / 共17页
c语言实践实验设备管理完整.docx_第7页
第7页 / 共17页
c语言实践实验设备管理完整.docx_第8页
第8页 / 共17页
c语言实践实验设备管理完整.docx_第9页
第9页 / 共17页
c语言实践实验设备管理完整.docx_第10页
第10页 / 共17页
c语言实践实验设备管理完整.docx_第11页
第11页 / 共17页
c语言实践实验设备管理完整.docx_第12页
第12页 / 共17页
c语言实践实验设备管理完整.docx_第13页
第13页 / 共17页
c语言实践实验设备管理完整.docx_第14页
第14页 / 共17页
c语言实践实验设备管理完整.docx_第15页
第15页 / 共17页
c语言实践实验设备管理完整.docx_第16页
第16页 / 共17页
c语言实践实验设备管理完整.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

c语言实践实验设备管理完整.docx

《c语言实践实验设备管理完整.docx》由会员分享,可在线阅读,更多相关《c语言实践实验设备管理完整.docx(17页珍藏版)》请在冰点文库上搜索。

c语言实践实验设备管理完整.docx

c语言实践实验设备管理完整

中国地质大学(武汉)机械设计制造及其自动化专业072105——陈乾

#include

#include

#defineAMOUNT50

typedefstruct{

intyear。

intmonth。

intday。

}DATE。

structEQU{

intnum。

/*本程序默认设备编号各不相同且不为0*/

chartype[20]。

charname[20]。

intprice。

DATEbuy_time。

intscrap。

/*0表示报废1表示不报废*/

DATEscr_time。

}equ[AMOUNT]。

/*公共函数保存与加载函数*/

voidsave()

{

FILE*fp。

inti。

if((fp=fopen("record","wb"))==NULL)

printf("cannotopenfile\n")。

for(i=0。

i

i++)

if(fwrite(&equ[i],sizeof(structEQU),1,fp)!

=1)

printf("filewriteerror\n")。

fclose(fp)。

}

voidload()

{

FILE*fp。

inti。

if((fp=fopen("record","rb"))==NULL)

printf("cannotopenfile\n")。

for(i=0。

i

i++)

if(fread(&equ[i],sizeof(structEQU),1,fp)!

=1)

{

if(feof(fp))fclose(fp)。

printf("filereaderror\n")。

}

fclose(fp)。

}

/*录入模块*/

voidadd()

{

intflag。

structEQU*p。

load()。

/*程序缺陷如果record文件中存储数据不足将重复输出多个filereaderror原因在于for语句对其进行循环AMOUNT次循环如不写本行记录将被覆盖*/

p=equ。

do

{

if(p->num!

=0)p++。

printf("请输入设备编号\n")。

scanf("%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以下记录录入成功\n")。

printf("编号:

%d设备种类:

%s设备名称:

%s\n价格:

%d购买日期:

%d%d%d\n是否报废:

%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,退出请按2\n")。

scanf("%d",&flag)。

}while(flag==1)。

save()。

}

/*修改模块*/

voidchange()

{

intflag,n,i=0。

structEQU*p。

p=equ。

load()。

printf("请输入要更改的设备编号\n")。

scanf("%d",&flag)。

for(i=0,p=equ。

i

i++,p++)

{

if(p->num==flag){

do

{

printf("请输入要更改的信息:

\n1设备编号\n2设备种类\n3设备名称\n4设备价格\n5购买日期\n6是否报废\n7退出\n")。

scanf("%d",&n)。

switch(n)

{

case1:

printf("请输入新的设备编号\n")。

scanf("%d",&p->num)。

break。

case2:

printf("请输入新的设备种类\n")。

scanf("%s",p->type)。

break。

case3:

printf("请输入新的设备名称\n")。

scanf("%s",p->name)。

break。

case4:

printf("请输入新的价格\n")。

scanf("%d",&p->price)。

break。

case5:

printf("请输入新的设备购买日期年月日\n")。

scanf("%d%d%d",&p->buy_time.year,&p->buy_time.month,&p->buy_time.day)。

break。

case6:

printf("请输入是否报废设备\n")。

scanf("%d",&p->scrap)。

printf("请输入报废日期\n")。

scanf("%d%d%d",&p->scr_time.year,&p->scr_time.month,&p->scr_time.day)。

break。

case7:

break。

}

}while(n!

=7)。

printf("修改后的记录为:

")。

printf("编号:

%d设备种类:

%s设备名称:

%s\n价格:

%d购买日期:

%d%d%d\n是否报废:

%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)。

}

}

save()。

}

/*查询模块*/

voidsearch()

{

intn,num,i,year,month,day。

chars[20]。

structEQU*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){

case1:

printf("请输入要查询的设备编号\n")。

scanf("%d",&num)。

for(i=0,p=equ。

i

i++,p++){

if(p->num==num)

printf("编号:

%d设备种类:

%s设备名称:

%s\n价格:

%d购买日期:

%d%d%d\n是否报废:

%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。

case2:

printf("请输入要查询的设备种类\n")。

scanf("%s",s)。

for(i=0,p=equ。

i

i++,p++){

if(strcmp(s,p->type)==0)

printf("编号:

%d设备种类:

%s设备名称:

%s价格:

%d购买日期:

%d%d%d是否报废:

%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。

case3:

printf("请输入要查询的设备名称\n")。

scanf("%s",s)。

for(i=0,p=equ。

i

i++,p++){

if(strcmp(s,p->name)==0)

printf("编号:

%d设备种类:

%s设备名称:

%s价格:

%d购买日期:

%d%d%d是否报废:

%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。

case4:

printf("请输入要查询的设备购买日期年月日\n")。

scanf("%d%d%d",&year,&month,&day)。

for(i=0,p=equ。

i

i++,p++){

if(year==p->buy_time.year&&month==p->buy_time.month&&day==p->buy_time.day)

printf("编号:

%d设备种类:

%s设备名称:

%s价格:

%d购买日期:

%d%d%d是否报废:

%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。

case5:

printf("未报废的设备有:

\n")。

for(i=0,p=equ。

i

i++,p++){

if(p->scrap==1)

printf("编号:

%d设备种类:

%s设备名称:

%s价格:

%d购买日期:

%d%d%d是否报废:

%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。

case6:

break。

}

}while(n!

=6)。

}

/*统计模块*/

voidstatis()

{

intflag,n,i,j,k=0。

chars[20]。

structEQU*p。

structEQUstr[AMOUNT],str1[1]。

p=equ。

load()。

printf("请输入要查询的设备种类\n")。

scanf("%s",&s[0])。

for(i=0,n=0,p=equ。

i

i++,p++){

if(strcmp(s,p->type)==0){

str[n].num=p->num。

str[n].price=p->price。

strcpy(str[n].name,p->name)。

str[n].scrap=p->scrap。

strcpy(str[n].type,p->type)。

str[n].buy_time.year=p->buy_time.year。

str[n].buy_time.month=p->buy_time.month。

str[n].buy_time.day=p->buy_time.day。

str[n].scr_time.day=p->scr_time.day。

str[n].scr_time.month=p->scr_time.month。

str[n].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){

case1:

for(j=0。

j

j++)/*起泡法排序*/

for(i=0。

i

i++)

if(str[i].num>str[i+1].num)

{

str1[0].num=str[i].num。

str1[0].buy_time.day=str[i].buy_time.day。

/*t=a[i]*/

str1[0].buy_time.month=str[i].buy_time.month。

str1[0].buy_time.year=str[i].buy_time.year。

str1[0].scr_time.year=str[i].scr_time.year。

str1[0].scr_time.month=str[i].scr_time.month。

str1[0].scr_time.day=str[i].scr_time.day。

str1[0].price=str[i].price。

str1[0].scrap=str[i].scrap。

strcpy(str1[0].name,str[i].name)。

strcpy(str1[0].type,str[i].type)。

str[i].num=str[i+1].num。

str[i].buy_time.day=str[i+1].buy_time.day。

/*a[i]=a[i+1]*/

str[i].buy_time.month=str[i+1].buy_time.month。

str[i].buy_time.year=str[i+1].buy_time.year。

str[i].scr_time.year=str[i+1].scr_time.year。

str[i].scr_time.month=str[i+1].scr_time.month。

str[i].scr_time.day=str[i+1].scr_time.day。

str[i].price=str[i+1].price。

str[i].scrap=str[i+1].scrap。

strcpy(str[i].name,str[i+1].name)。

strcpy(str[i].type,str[i+1].type)。

str[i+1].num=str1[0].num。

str[i+1].buy_time.day=str1[0].buy_time.day。

/*a[i+1]=t*/

str[i+1].buy_time.month=str1[0].buy_time.month。

str[i+1].buy_time.year=str1[0].buy_time.year。

str[i+1].scr_time.year=str1[0].scr_time.year。

str[i+1].scr_time.month=str1[0].scr_time.month。

str[i+1].scr_time.day=str1[0].scr_time.day。

str[i+1].price=str1[0].price。

str[i+1].scrap=str1[0].scrap。

strcpy(str[i+1].name,str1[0].name)。

strcpy(str[i+1].type,str1[0].type)。

}

for(i=0,p=str。

i

i++,p++)

printf("编号:

%d设备种类:

%s设备名称:

%s价格:

%d购买日期:

%d%d%d是否报废:

%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。

case2:

for(j=0。

j

j++)/*起泡法排序*/

for(i=0。

i

i++)

if(str[i].price>=str[i+1].price)

{

str1[0].num=str[i].num。

str1[0].buy_time.day=str[i].buy_time.day。

/*t=a[i]*/

str1[0].buy_time.month=str[i].buy_time.month。

str1[0].buy_time.year=str[i].buy_time.year。

str1[0].scr_time.year=str[i].scr_time.year。

str1[0].scr_time.month=str[i].scr_time.month。

str1[0].scr_time.day=str[i].scr_time.day。

str1[0].price=str[i].price。

str1[0].scrap=str[i].scrap。

strcpy(str1[0].name,str[i].name)。

strcpy(str1[0].type,str[i].type)。

str[i].num=str[i+1].num。

str[i].buy_time.day=str[i+1].buy_time.day。

/*a[i]=a[i+1]*/

str[i].buy_time.month=str[i+1].buy_time.month。

str[i].buy_time.year=str[i+1].buy_time.year。

str[i].scr_time.year=str[i+1].scr_time.year。

str[i].scr_time.month=str[i+1].scr_time.month。

str[i].scr_time.day=str[i+1].scr_time.day。

str[i].price=str[i+1].price。

str[i].scrap=str[i+1].scrap。

strcpy(str[i].name,str[i+1].name)。

strcpy(str[i].type,str[i+1].type)。

str[i+1].num=str1[0].num。

str[i+1].buy_time.day=str1[0].buy_time.day。

/*a[i+1]=t*/

str[i+1].buy_time.month=str1[0].buy_time.month。

str[i+1].buy_time.year=str1[0].buy_time.year。

str[i+1].scr_time.year=str1[0].scr_time.year。

str[i+1].scr_time.month=str1[0].scr_time.month。

str[i+1].scr_time.day=str1[0].scr_time.day。

str[i+1].price=str1[0].price。

str[i+1].scrap=str1[0].scrap。

strcpy(str[i+1].name,str1[0].name)。

strcpy(str[i+1].type,str1[0].type)。

}

for(i=0,p=str。

i

i++,p++)

printf("编号:

%d设备种类:

%s设备名称:

%s价格:

%d购买日期:

%d%d%d是否报废:

%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。

case3:

/*由于程序过于复杂需连续用3次起泡法所以按购买日期排序只对年份排序*/

for(j=0。

j

j++)/*起泡法排序*/

for(i=0。

i

i++)

if(str[i].buy_ti

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2