C语言课程设计设备管理系统.docx
《C语言课程设计设备管理系统.docx》由会员分享,可在线阅读,更多相关《C语言课程设计设备管理系统.docx(26页珍藏版)》请在冰豆网上搜索。
C语言课程设计设备管理系统
一份可以在vc6.0等软件上运行的C语言代码清单,其中一个主函数,设置多个调用函数,分别实现排序,输入,读取等功能模块。
#include
#include
#include
#include
#definefeipeineicun(p)do{p=(shebei*)malloc(sizeof(shebei));if(p==NULL){printf("内存分配失败!
");exit(-1);}}while(0)
#definelensizeof(shebei)
typedefstructtime
{
intyear;
intmouth;
intday;
}time;
typedefstructshebei
{
intbianhao;
charmingcheng[15];
charzhonglei[15];
intdanjia;
intniandai;
charchanjia[15];
charbaofei[10];
timetime;
structshebei*next;
}shebei;
//externint
//函数声明下面
voidcaidan(shebei*top);
intxuanze();
shebei*xinxiluru(shebei*top);
voidneirongxianshi(shebei*top);
voidxinxichazhao(shebei*top);
shebei*xinxixiugai(shebei*top);
shebei*xinxishanchu(shebei*top);
shebei*shebeibaofei(shebei*top);
shebei*xinxipaixu(shebei*top);
voidfenleitongji(shebei*top);
voidtongmingguibing(shebei*top);
voidbaocun(shebei*top);
//#include"头文件.h"
voidmain()
{
shebei*top;
printf("\t**********************************************************\n");
printf("\t----------------------------------------------------------\n");
printf("\t**********************************************************\n");
printf("\t--------\n");
printf("\t****欢迎进入单位仪器设备基本信息管理系统****\n");
printf("\t--------\n");
printf("\t**********************************************************\n");
printf("\t----------------------------------------------------------\n");
printf("\t**********************************************************\n");
do{top=(shebei*)malloc(sizeof(shebei));if(top==NULL){printf("内存分配失败!
");exit(-1);}}while(0);
top->next=NULL;
caidan(top);
}
//#include"头文件.h"
voidcaidan(shebei*top)
{
while
(1)
{
switch(xuanze())
{
case1:
top=xinxiluru(top);
break;
case2:
neirongxianshi(top);
break;
case3:
xinxichazhao(top);
break;
case4:
top=xinxixiugai(top);
break;
case5:
top=xinxishanchu(top);
break;
case6:
top=shebeibaofei(top);
break;
case7:
top=xinxipaixu(top);
break;
case8:
tongmingguibing(top);//先同名合并
fenleitongji(top);
break;
case9:
baocun(top);
break;
default:
printf("退出操作,拜拜!
\n");
exit(0);
}
}
}
intxuanze()
{
intn;
printf("\n1.增加记录\n");
printf("2.查看信息\n");
printf("3.查找信息\n");
printf("4.修改信息\n");
printf("5.删除信息\n");
printf("6.设备报废\n");
printf("7.信息排序\n");
printf("8.分类统计\n");
printf("9.保存信息\n");
printf("按0退出\n");
for(;;)
{
scanf("%d",&n);
if(n<0||n>9)
printf("\n输入错误,请重新输入:
");
else
break;
}
returnn;
}
//#include"头文件.h"
shebei*shebeibaofei(shebei*top)
{
shebei*p;
charb[15],c;
p=top->next;
if(top->next==NULL)
{
printf("没有信息记录,返回菜单选择\n");
returntop;
}
printf("请输入要报废的设备名称:
");
scanf("%s",b);
while(p)
{
if(strcmp(b,p->mingcheng)==0)
{
if(strcmp(p->baofei,"是")!
=0)
{
printf("将要报废的设备信息如下:
\n");
printf("设备编号设备名称设备种类设备单价购进年代生产厂家是否报废\n");
printf("%d%s%s%d%d%s%s\n",
p->bianhao,p->mingcheng,p->zhonglei,p->danjia,p->niandai,p->chanjia,p->baofei);
printf("是否确认报废?
(Y/N):
");
scanf("%c",&c);
scanf("%c",&c);
if(c=='y'||c=='Y')
{
strcpy(p->baofei,"是");
printf("此设备已被报废\n");
}
}
else
printf("此设备已经为报废状态\n");
break;
}
p=p->next;
}
if(p==NULL)
printf("没有找到该设备信息\n");
printf("按任意键返回主菜单\n");
getchar();
getchar();
returntop;
}
//#include"头文件.h"
shebei*xinxiluru(shebei*top)
{
intn;
shebei*p,*q;
p=top;
while(p->next!
=NULL)
{
p=p->next;
}
printf("请输入设备信息:
\n输入0则结束\n");
do
{
feipeineicun(q);
printf("请输入设备的编号");
scanf("%d",&q->bianhao);
if(q->bianhao==0)
break;
printf("请输入设备的名称");
scanf("%s",q->mingcheng);
printf("请输入设备的种类");
scanf("%s",q->zhonglei);
printf("请输入设备的单价");
scanf("%d",&q->danjia);
printf("请输入设备的年代");
scanf("%d",&q->niandai);
printf("请输入设备的生产产家");
scanf("%s",q->chanjia);
printf("请输入设备的报废情况\n");
printf("0.没有报废\n1.已经报废\n");
for(;;)
{
scanf("%d",&n);
if(n!
=0&&n!
=1)
printf("输入错误,请重新输入:
\n");
else
break;
}
if(n==0)
{
strcpy(q->baofei,"否");
q->time.year=q->time.day=q->time.day=0;
}
else
{
strcpy(q->baofei,"是");
printf("请输入报废时间(格式为20151012):
");
scanf("%d%d%d",&q->time.year,&q->time.mouth,&q->time.day);
}
p->next=q;
p=q;
p->next=NULL;
}while
(1);
free(q);
printf("录入完毕,按任意键返回主菜单\n");
getchar();
getchar();
returntop;
}
//#include"头文件.h"
voidneirongxianshi(shebei*top)
{
shebei*p;
p=top->next;
if(top->next)
{
printf("设备信息如下:
\n");
printf("设备编号设备名称设备种类设备单价购进年代生产厂家是否报废\n");
}
else
printf("记录为空,返回菜单\n");
while(p)
{
printf("%d%s%s%d%d%s%s\n",
p->bianhao,p->mingcheng,p->zhonglei,p->danjia,p->niandai,p->chanjia,p->baofei);
p=p->next;
}
printf("按任意键返回主菜单\n");
getchar();
getchar();
}
//#include"头文件.h"
voidbaocun(shebei*top)
{
FILE*fp;
shebei*p;
p=top->next;
if(top->next==NULL)
{
printf("没有东西可存!
\n");
return;
}
if((fp=fopen("shebei.txt","wb"))==NULL)
{
printf("\n");
exit
(1);
}
while(p)
{
fwrite(p,len,1,fp);
p=p->next;
}
fclose(fp);
printf("信息已经存入文件,请继续\n");
}
//#include"头文件.h"
voidxinxichazhao(shebei*top)
{
shebei*p;
inta,n;
charb[15];
p=top->next;
if(top->next==NULL)
{
printf("没有记录信息,返回菜单选择\n");
return;
}
printf("查找方式:
\n");
printf("1.按编号查找\n2.按名称查找\n");
for(;;)
{
scanf("%d",&n);
if(n!
=2&&n!
=1)
printf("输入错误,请重新输入:
\n");
else
break;
}
if(n==1)
{
printf("请输入设备编号:
");
scanf("%d",&a);
while(p)
{
if(a==p->bianhao)
{
printf("查找到的设备信息如下:
\n");
printf("设备编号设备名称设备种类设备单价购进年代生产厂家是否报废\n");
printf("%d%s%s%d%d%s%s\n",
p->bianhao,p->mingcheng,p->zhonglei,p->danjia,p->niandai,p->chanjia,p->baofei);
break;
}
p=p->next;
}
}
else
if(n==2)
{
printf("请输入设备名称:
");
scanf("%s",b);
while(p)
{
if(strcmp(b,p->mingcheng)==0)
{
printf("查找到的设备信息如下:
\n");
printf("设备编号设备名称设备种类设备单价购进年代生产厂家是否报废");
printf("%d%s%s%d%d%s%s\n",
p->bianhao,p->mingcheng,p->zhonglei,p->danjia,p->niandai,p->chanjia,p->baofei);
break;
}
p=p->next;
}
}
if(p==NULL)
printf("没有找到该信息\n");
printf("按任意键返回主菜单\n");
getchar();
getchar();
}
//#include"头文件.h"
shebei*xinxipaixu(shebei*top)
{
shebei*p,*q,*s,*t;
t=top;
s=p=top->next;
if(p==NULL)
{
printf("内容为空,按任意键返回菜单选择");
getchar();
getchar();
returntop;
}
if(p->next==NULL)
{
printf("排序完毕,返回主菜单\n");
returntop;
}
while(p)
{
q=p->next;
while(q)
{
if(p->danjia>q->danjia)
{
s->next=q->next;
t->next=q;
q->next=p;
p=q;
q=q->next;
}
else
{
s=s->next;
q=q->next;
}
}
t=t->next;
s=p=p->next;
}
printf("排序完毕,返回主菜单\n");
returntop;
}
//#include"头文件.h"
shebei*xinxishanchu(shebei*top)
{
shebei*p,*q;
inta;
p=top->next;
q=top;
if(top->next==NULL)
{
printf("没有可删除的信息,按任意键返回菜单选择\n");
getchar();
getchar();
returntop;
}
printf("请输入要删除的设备编号:
");
scanf("%d",&a);
while(p)
{
if(a==p->bianhao)
{
printf("\n删除的设备信息如下:
\n");
printf("设备编号设备名称设备种类设备单价购进年代生产厂家是否报废\n");
printf("%d%s%s%d%d%s%s\n",
p->bianhao,p->mingcheng,p->zhonglei,p->danjia,p->niandai,p->chanjia,p->baofei);
if(p->next==NULL)
{
q->next=NULL;
free(p);
}
else
{
q->next=p->next;
free(p);
}
break;
}
q=q->next;
p=p->next;
}
if(p==NULL)
printf("此设备不存在,按任意键返回\n");
else
printf("----删除成功,按任意键返回----\n");
getchar();
getchar();
returntop;
}
//#include"头文件.h"
voidtongmingguibing(shebei*top)
{
shebei*p,*q,*s,*t,*j,*k;
intflag;
t=top;
s=p=top->next;
if(p==NULL)
{
//printf("内容为空,按任意键返回上级");
getchar();
getchar();
return;
}
if(p->next==NULL)
{
//printf("排序完毕,返回上级\n");
return;
}
while(p)
{
flag=0;
q=p->next;
while(q)
{
if(strcmp(p->mingcheng,q->mingcheng)==0)
{
s->next=q->next;
t->next=q;
q->next=p;
p=q;
q=s->next;
}
else
{
if(flag==0)
{
j=q;
k=s;
flag++;
}
s=s->next;
q=q->next;
}
}
if(flag!
=0)
{
p=j;
t=s;
}
else
{
//printf("归并完毕,返回主菜单\n");
return;
}
}
//printf("归并完毕,返回主菜单\n");
return;
}
voidfenleitongji(shebei*top)
{
shebei*p,*q,*s;
intflag,n=0;
p=top->next;
s=p;
if(top->next==NULL)
{
printf("内容为空,按任意键返回菜单选择");
getchar();
getchar();
return;
}
//tongmingguibing(top);
while(p)
{
flag=0;
n=1;
q=p->next;
while(q)
{
if(strcmp(p->mingcheng,q->mingcheng)==0)
n++;
else
{
if(flag==0)
s=q;
flag++;
}
q=q->next;
}
printf("名称为%s的设备数量为%d\n",p->mingcheng,n);
if(flag!
=0)
p=s;
else
return;
}
}
//#include"头文件.h"
shebei*xinxixiugai(shebei*top)
{
shebei*p;
inta,m,n;
charb[15];
p=top->next;
if(top->next==NULL)
{
printf("没有可供修改的信息,返回菜单选择\n");
returntop;
}
printf("请输入修改方式:
\n");
printf("1.按编号\n2.按名称\n");
for(;;)
{
scanf("%d",&n);
if(n!
=2&&n!
=1)
printf("输入错误,请重新输入:
\n");
else
break;
}
if(n==1)
{
printf("请输入要修改的设备编号:
");
scanf("%d",&a);
while(p)
{
if(a==p->bianhao)
{
printf("查找到要修改的设备信息如下:
\n");
printf("设备编号设备名称设备种类设备单价购进年代生产厂家是否报废\n");
printf("%d%s%s%d%d%s%s\n",
p->bianhao,p->mingcheng,p->zhonglei,p->danjia,p->nianda