c语言课程设计(教学设备管理系统)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define NULL 0
#define LEN sizeof(struct equipment)
struct equipment
{long number;
char name[20];
char adr[20];
long date;
long taishu;
long price;
long money;
char other[20];
struct equipment *next;
};
struct equipment *head,*equip,*p5,*p;
int n;
struct equipment *del1,*del2,*del3;
struct equipment*insert(struct equipment *head,struct equipment *p);
/*输入函数*/
struct equipment* creat(void)
{struct equipment *p1,*p2;
n=0;
p1=p2=(struct equipment*)malloc(LEN);
printf("\n教学设备编号为0时,退出输入!\n");
printf("输入教学设备编号 :");
scanf("%ld",&p1->number);
printf("\n输入设备名称:");
scanf("%s",p1->name);
printf("\n输入生产厂家:");
scanf("%s",p1->adr);
printf("\n输入购置日期:");
scanf("%ld",&p1->date);
printf("\n输入台数:");
scanf("%ld",&p1->taishu);
printf("\n输入单价:");
scanf("%ld",&p1->price);
p1->money=(p1->taishu)*(p1->price);
printf("\n输入备注:");
scanf("%s",p1->other);
head=NULL;
while(p1->number!=0)
{n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct equipment*)malloc(LEN);
printf("\n输入教学设备编号:");
scanf("%ld",&p1->number);
if(p1->number==0) break;
else
{printf("\n输入设备名称:");
scanf("%s",p1->name);
printf("\n输入生产厂家:");
scanf("%s",p1->adr);
printf("\n输入购置日期:");
scanf("%ld",&p1->date);
printf("\n输入台数:");
scanf("%ld",&p1->taishu);
printf("\n输入单价:");
scanf("%ld", &p1->price);
p1->money=(p1->taishu)*(p1->price);
printf("\n输入备注:");
scanf("%s",p1->other);}
}
p2->next=NULL;
return(head);
}
void print()
{clrscr();
gotoxy(33,0);
printf("\16[{-80|10@30,30=4(2)5****中南工业大学教学设备明细账****}]");
gotoxy(3,5);
printf("设备编号 设备名称 生产厂家 购置日期 台数 单价 金额 备注\n");}
void print1()
{int i,j;
for(i=0;i<=8;i++)
line(70*i+16,60,70*i+16,60+36*(n+1));
for(j=0;j<=n+1;j++)
line(16,60+36*j,70*8+16,60+36*j);}
/*显示函数*/
void output(struct equipment* head)
{struct equipment*p;
p=head;
print();
if(head!=NULL)
do
{printf("\n %-9ld%-9s%-9s%-9ld%-9ld%-9ld%-9ld%-9s \n",p->number,p->name,p->adr,p->date,p->taishu,p->price,p->money,p->other);
p=p->next;}while(p!=NULL);
print1();
getch();}
/*修改函数*/
void change(struct equipment* head)
{struct equipment *p;
long nu
m;
cleardevice();
for(;;)
{
printf("\n请输入要修改的设备编号:");
scanf("%ld",&num);
p=head;
while(num!=p->number&&p->next!=NULL)
{p=p->next;}
if(num!=p->number)
{printf("\n对不起,无此记录!按任意键返回!");
getch();
break;}
else
{printf("\n请输入新的设备记录:");
printf("\n输入教学设备编号:");
scanf("%ld",&p->number);
printf("\n输入教学设备名称:");
scanf("%s",p->name);
printf("\n输入生产厂家:");
scanf("%s",p->adr);
printf("\n输入购置日期:");
scanf("%ld",&p->date);
printf("\n输入台数:");
scanf("%ld",&p->taishu);
printf("\n输入单价:");
scanf("%ld",&p->price);
p->money=(p->taishu)*(p->price);
printf("\n输入备注:");
scanf("%s",p->other);
printf("\n是否继续退出,Y/N?");
if(getch()!='y') break;
}}}
/*查找函数*/
void search(struct equipment* head)
{ struct equipment *p;
char choice;
long key;
do
{clrscr();
if(head==NULL)
printf("\n 无此记录!");
printf("\n请输入要查找的设备编号:");
scanf("%ld",&key);
p=head;
while(key!=p->number&&p->next!=NULL)
{p=p->next;}
if(key==p->number)
{print();
print1();
printf("\n %-9ld%-9s%-9s%-9ld%-9ld%-9ld%-9ld%-9s",p->number,p->name,p->adr,p->date,p->taishu,p->price,p->money,p->other);
printf("\n");}
else
{printf("\n无此编号,请按任意键返回!");
getch();}
printf("\n您是否需要继续查找?(y/n)\n");
choice=getch();
}while(choice=='y');
}
/*删除函数*/
struct equipment *del(struct equipment *head)
{ struct equipment *p1,*p2;
long number;
int b=0;
do
{clrscr();
if(head==NULL)
{printf("\n无此记录!\n");
return(head);}
else
{b=0;
if(del1==NULL) b=b+1;
if(del2==NULL) b=b+1;
if(del3==NULL) b=b+1;
if(b!=0)
printf("\n回收站还有%d的空间!",b);
else
printf("\n回收站已满,无法再删除!");
printf("\n请输入要删除的教学设备编号:");
scanf("%ld",&number);
p1=head;
while(number!=p1->number&&p1->next!=NULL)
{p2=p1;
p1=p1->next; }
if(number==p1->number)
{printf("\n进行逻辑删除还是物理删除,Y/N?");
if(getch()=='y')
{if(del1==NULL) del1=p1;
else if(del2==NULL) del2=p1;
else del3=p1;}
if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("\n已删除设备编号%ld记录!",number);
b=b-1;}
else
{printf("\n无此设备记录!");
getch();}
printf("\n是否继续删除/Y/N?");
}
}while(getch()=='y');
getch();
return(h
ead);
}
/*恢复函数*/
struct equipment *recover(struct equipment* head)
{ struct equipment *p0,*p1,*p2;
long rec_num,a=0;
cleardevice();
gotoxy(1,3);
do{printf("\n可恢复的设备编号:");
if(del1!=NULL)
{a=a+1;printf("\n%ld",del1->number); }
if(del2!=NULL)
{a=a+1;printf("\n%ld",del2->number);}
if(del3!=NULL)
{a=a+1;printf("\n%ld",del3->number); }
if(a==0)
{printf("\n没有可恢复的数据,请按任意键退出!");
getch();
return(head); }
printf("\n请输入要恢复的教学设备编号:");
scanf("%ld",&rec_num);
if(rec_num==del1->number)
{p0=del1;
del1=NULL;}
else if(rec_num==del2->number)
{p0=del2;
del2=NULL;}
else if(rec_num==del3->number)
{p0=del3;
del3=NULL;}
else {printf("\n输入错误,按任意键返回!");
getch();
return(head);}
p1=head;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->number>p1->number)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;}
if(p0->number<p1->number)
{if(head==p1){head=p0;p0->next=p1;}
else p2->next=p0;
p0->next=p1;
} else
{p1->next=p0;
p0->next=NULL;}}
n=n+1;
output(head);
printf("\n恢复成功,请按任意键返回!");
printf("\n是否继续进行恢复Y/N?");
}while(getch()=='y');
getch();
return(head);
}
/*添加函数*/
struct equipment *insert(struct equipment* head,struct equipment *p)
{
char choice;
p=(struct equipment*)malloc(LEN);
do
{
clrscr();
printf("\n请输入新的教学设备资料:");
printf("\n输入编号:");
scanf("%ld",&p->number);
printf("\n输入名称:");
scanf("%s",p->name);
printf("\n输入生产厂家:");
scanf("%s",p->adr);
printf("\n输入购置日期:");
scanf("%ld",&p->date);
printf("\n输入台数:");
scanf("%ld",&p->taishu);
printf("\n 输入单价:");
scanf("%ld",&p->price);
p->money=(p->taishu)*(p->price);
printf("\n输入备注:");
scanf("%s",p->other);
printf("\n");
if(n==0)
{ n=n+1;
head=p; }
else
{p->next=head;head=p;n++;}
printf("\n您是否要继续添加?(y/n)\n");
}while(getch()=='y');
return(head);
}
/*统计函数*/
void count(struct equipment* head)
{ int sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,sum6=0,sum7=0,sum8=0;
struct equipment* p;
p=head;
while(p)
{ for(p=head;p!=NULL;p=p->next)
{ sum1+=p->taishu;
sum2+=p->money;
if(p->money<200)
{ sum3+=p->taishu;sum4+=p->money; }
else
if(p->price<800)
{ sum5+=p->taishu;sum6+=p->money; }
else
{ sum7+=p->taishu;sum8+=p->money; }
}
}
output(head);
printf("\n 合计 %d
%d\n",sum1,sum2);
n=n+1;
print1();
n=n-1;
printf("\n");
printf("\n");
printf("\n 200元以下的设备总台数及总金额: %d %d",sum3,sum4);
printf("\n 200--800元之间的设备总台数及总金额: %d %d",sum5,sum6);
printf("\n 800元以上的设备总台数及总金额: %d %d",sum7,sum8);
getch();
}
/*保存函数*/
void save(struct equipment *head)
{ FILE *fp;
struct equipment *p;
char name[20];
p=head;
cleardevice();
printf("\n请输入要保存的文件名:");
scanf("%s",name);
if((fp=fopen(name,"wb"))==NULL)
{printf("\n对不起!不能
建立新文件!按任意键返回!");
getch();
return;}
while(p->number!=NULL)
{fwrite(p,LEN,1,fp);
p=p->next;}
printf("\n保存结束,请按任意键返回!");
fclose(fp);
getch();}
/*打开函数*/
struct equipment *dakai(void)
{ struct equipment *head, *p1,*p2 ;
char name[20];
FILE *fp=NULL;
cleardevice();
p1=p2=(struct equipment *)malloc(LEN);
printf("\n请输入要打开的文件名:");
head=p1;
scanf("%s",name);
if((fp=fopen(name,"rb"))==NULL)
{printf("\n对不起,没有该文件!请按任意键返回!");
getch();}
fread(p1,LEN,1,fp);
while(!feof(fp))
{p2->next=p1;
p2=p1;
p1=(struct equipment*)malloc(LEN);
fread(p1,LEN,1,fp);n++;};
p2->next=NULL;
fclose(fp);
output(head);
printf("\n文件已输出,请按任意键返回!");
getch();
return(head);
}main()
{
char i;
long key ,a;
int drive=DETECT,mode;
initgraph(&drive,&mode,"");
cleardevice();
setbkcolor(9);
printf("\16[co4st8e320,130,0,360,300,70,2,4]");
printf("\16[{-3|3@48,24=2(14)9**大学}]");
printf("\16[{-90|100@60,60=11(13)9教学设备管理系统}]");
printf("\16[{-400|400@17,17=8(12)9设计者:自动化0411 xxx}]");
printf("\16[{-250|250@20,20=8(4)9请按Enter键进入}]");
getch();
for(;;)
{
cleardevice();
setbkcolor(9);
printf("\16[{-80|1@45,36=4(2)6* * * * * *菜单* * * * * *}]");
printf("\16[{-100|50@48,48=3(7)6a输入}]");
printf("\16[{-400|50@48,48=3(7)6b显示}]");
printf("\16[{-100|110@48,48=3(7)6c修改}]");
printf("\16[{-400|110@48,48=3(7)6d查找}]");
printf("\16[{-100|170@48,48=3(7)6e删除}]");
printf("\16[{-400|170@48,48=3(7)6f恢复}]");
printf("\16[{-100|230@48,48=3(7)6g添加}]");
printf("\16[{-400|230@48,48=3(7)6h统计}]");
printf("\16[{-100|290@48,48=3(7)6i保存}]");
printf("\16[{-400|290@48,48=3(7)6j打开}]");
printf("\16[{-100|350@48,48=3(7)6k退出}]");
printf("\16[{-350|400@24,24=3(7)4请选择a至j}]");
i=getch();
if(i=='k')
break;
else switch(i)
{
case'a':clear
device(); creat();break;
case'b':cleardevice(); output(head);break;
case'c':cleardevice(); change(head);break;
case'd':cleardevice(); search(head);break;
case'e':cleardevice(); head=del(head);break;
case'f':cleardevice(); head=recover(head);break;
case'g':cleardevice(); head=insert(head,p);break;
case'h':cleardevice(); count(head);break;
case'i':cleardevice(); save(head);getch();break;
case'j':cleardevice(); head=dakai(); break;
}}}
<PIXTEL_MMI_EBOOK_2005>1 </PIXTEL_MMI_EBOOK_2005>