您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > C语言课程设计-设备管理系统
#includestdio.h#includestdlib.h#includeconio.h#includestring.hvoidmenu();//功能选择voidlkp();//查看信息voidchng();//修改信息voiddlt();//删除信息voidadd();//添加信息voidread();//读取文件voidwrite();//写入文件voidcount();//统计信息structdvc{chardno[20],dname[20],downer[20],ddpartment[20],damount[20],dtime[20],dprice[20];intdlt;}d[200];inttot,sum;intmain(){system(colorfc);system(modeconcols=146lines=40);puts(************************);puts(*欢迎使用设备管理系统!*);puts(************************);read();//将保存至外存中的文件读进内存menu();//用户功能选择write();//将内存里的所有信息覆写回外存文件中system(cls);puts(感谢您的使用);return0;}voidread(){tot=0;FILE*fp=fopen(D:\\inf.txt,r);if(fp==NULL){fp=fopen(D:\\inf.txt,w);fclose(fp);}while(fscanf(fp,%s%s%s%s%s%s%s,d[tot].dno,d[tot].dname,d[tot].downer,d[tot].ddpartment,d[tot].damount,d[tot].dtime,d[tot].dprice)!=EOF){d[tot++].dlt=0;}fclose(fp);}voidwrite(){inti;FILE*fp=fopen(D:\\inf.txt,w);for(i=0;itot;i++)if(!d[i].dlt)fprintf(fp,%s%s%s%s%s%s%s\n,d[i].dno,d[i].dname,d[i].downer,d[i].ddpartment,d[i].damount,d[i].dtime,d[i].dprice);fclose(fp);}voidmenu(){chara;while(1){puts(★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★请选择需要的功能:★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★);puts(1.查看所有设备信息\n2.修改设备信息\n3.删除设备信息\n4.增加设备信息\n5.统计设备信息\n0.退出系统);a=getch();switch(a){case'0':return;case'1':{lkp();break;}case'2':{chng();break;}case'3':{dlt();break;}case'4':{add();break;}case'5':{count();break;}default:printf(您输入的信息有误!请检查后重新输入\n);}}}voidlkp(){system(cls);inti;printf(设备号设备名称领用人所属部门数量购买时间价格\n);for(i=0;itot;i++){if(d[i].dlt==0)printf(%20s%20s%20s%20s%20s%20s%20s\n,d[i].dno,d[i].dname,d[i].downer,d[i].ddpartment,d[i].damount,d[i].dtime,d[i].dprice);}}voidchng(){system(cls);chars,ch[20];inti,j;printf(请输入您要修改的设备的编号:(0键返回菜单栏)\n);printf(设备号设备名称领用人所属部门数量购买时间价格\n);for(i=0;itot;i++){printf(%4d.%20s%20s%20s%20s%20s%20s%20s\n,i+1,d[i].dno,d[i].dname,d[i].downer,d[i].ddpartment,d[i].damount,d[i].dtime,d[i].dprice);}while(1){scanf(%s,ch);i=atoi(ch);if(i=1&&i=tot)break;elseif(i==0){system(cls);return;}elseputs(您输入的信息有误!请检查后重新输入\n);}if(d[i-1].dlt==1){printf(该设备已经被删除!\n);return;}printf(请输入您要修改的内容的编号:\n1.设备号\n2.设备名称\n3.领用人\n4.所属部门\n5.数量\n6.购买时间\n7.价格\n0.返回菜单栏\n);while(1){scanf(%s,ch);j=atoi(ch);if(j=1&&j=7)break;elseif(i==0){system(cls);return;}elseputs(您输入的信息有误!请检查后重新输入\n);}printf(请输入您要修改的信息:\n);switch(j){case1:{scanf(%s,d[i-1].dno);break;}case2:{scanf(%s,d[i-1].dname);break;}case3:{scanf(%s,d[i-1].downer);break;}case4:{scanf(%s,d[i-1].ddpartment);break;}case5:{scanf(%s,d[i-1].damount);break;}case6:{scanf(%s,d[i-1].dtime);break;}case7:{scanf(%s,d[i-1].dprice);break;}}printf(请问是否要继续修改?(Y/N)\n);while(1){getchar();gets(&s);if(s=='Y'||s=='N'||s=='y'||s=='n')break;elseputs(您输入的信息有误!请检查后重新输入\n);}if(s=='Y'||s=='y')chng();elseif(s=='N'||s=='n')system(cls);}voiddlt(){system(cls);charch[20],s;inti;printf(请输入你要删除的设备的编号:(0键返回菜单烂)\n);printf(设备号设备名称领用人所属部门数量购买时间价格\n);for(i=0;itot;i++){if(d[i].dlt==0)printf(%4d.%20s%20s%20s%20s%20s%20s%20s\n,i+1,d[i].dno,d[i].dname,d[i].downer,d[i].ddpartment,d[i].damount,d[i].dtime,d[i].dprice);}while(1){scanf(%s,ch);i=atoi(ch);if(i=1&&i=tot)break;elseif(i==0){system(cls);return;}elseputs(您输入的信息有误!请检查后重新输入\n);}d[i-1].dlt=1;printf(请问是否要继续删除?(Y/N)\n);while(1){getchar();gets(&s);if(s=='Y'||s=='N'||s=='y'||s=='n')break;elseputs(您输入的信息有误!请检查后重新输入\n);}if(s=='Y'||s=='y')dlt();elseif(s=='N'||s=='n')system(cls);}voidadd(){chars;system(cls);printf(请输入您要添加的设备号:\n);scanf(%s,d[tot].dno);printf(请输入您要添加的设备的名称:\n);scanf(%s,d[tot].dname);printf(请输入您要添加的设备的领用人:\n);scanf(%s,d[tot].downer);printf(请输入您要添加的设备的所属部门:\n);scanf(%s,d[tot].ddpartment);printf(请输入您要添加的设备的数量:\n);scanf(%s,d[tot].damount);printf(请输入您要添加的设备的购买时间:\n);scanf(%s,d[tot].dtime);printf(请输入您要添加的设备的价格:\n);scanf(%s,d[tot].dprice);d[tot].dlt=0;tot+=1;printf(请问是否要继续添加?(Y/N)\n);while(1){getchar();gets(&s);if(s=='Y'||s=='N'||s=='y'||s=='n')break;elseputs(您输入的信息有误!请检查后重新输入\n);}if(s=='Y'||s=='y')add();elseif(s=='N'||s=='n')system(cls);}voidcount(){system(cls);charch[20],temp[20],s;inti,j,n;sum=0;printf(请选择统计的方式:\n1.所有设备的总价值。\n2.设备所属部门。\n3.设备种类。\n0.返回菜单栏\n);while(1){scanf(%s,ch);j=atoi(ch);if(j=1&&j=3)break;elseif(j==0){system(cls);return;}elseputs(您输入的信息有误!请检查后重新输入\n);}system(cls);switch(j){case1:{lkp();for(i=0;itot;i++){if(d[i].dlt==0)sum=atoi(d[i].dprice)*atoi(d[i].damount)+sum;}printf(当前设备的总价值为%d。\n,sum);break;}case2:{lkp();printf(设备所属部门统计结果为:\n所属部门数量总价值\n);for(i=0;itot;i++){sum=0;n=0;strcpy(temp,d[i].ddpartment);for(j=0;jtot;j++){if(strcmp(temp,d[j].ddpartment)==0&&ij)break;elseif(strcmp(temp,d[j].ddpartment)==0&&ij&&d[j].dlt==0){sum=sum+atoi(d[j].damount)*atoi(d[j].dprice);n=n+atoi(d[j].damount);}}if(strcmp(temp,d[j].ddpartment)==0&&ij)continue;if(d[i].dlt==0){sum=sum+atoi(d[i].damount)*atoi(d[i].dprice);n=n+atoi(d[i].damount);}if(sum==0)continue;printf(%20s%20d%20d\n,d[i].ddpartment,n,sum);}break;}case3:{lkp();printf(设备种类统计结果为:\n设备名数量总价值\n);for(i=0;itot;i++){sum=0;n=0;strcpy(temp,d[i].dname);for(j=0;jtot;j++){if(strcmp(temp,d[j].dname)==0&&ij)break;elseif(strcmp(temp,d[j].dname)==0&&ij&&d[j].dlt==0){sum=sum+atoi(d[j].damo
本文标题:C语言课程设计-设备管理系统
链接地址:https://www.777doc.com/doc-5352808 .html