传统的人工实验室设备管及浪费人力物力财力,在日常管理时,数据管理不清晰,在记录设备相关信息时又容易导致各种错误发生。实验室设备管理还处于较原始的手工阶段,采用在设备购进以后将设备的根本情况和相关信息登记存档。
本题目将建立一个实验室设备管理系统,记录实验室所有的实验设备,并及时反响设备的运转状况,使用情况,设备购进以后及时记录设备相关信息,对彻底损坏的设备进行报废,维修的设备信息及有更改信息的设备进行统计,解决人工管理系统没解决的问题以及实现对用户更方便的功能。本系统以灵活、通用为主要设计思想,开发适合于学校实验室设备管理的信息系统。使用本系统之后,将会提高学校师生做实验和课题的效率和设备可靠性,减少工作人员的劳动强度,减少耗材,提高学校实验室的现代化管理水平
#include
#include
#include
typedef struct equipment{
int num; //编号,
char model[20]; //型号
char factory[20]; //厂家
char buy_date[20]; //购买日期
char baozhqi[20];//保质期
char repair_time[20];//维修时间
double cost; // 费用
char name[20];
char zrr[20];//责任人
char amount[20];//数量
char price[20];//价格
char baofei_time[20];//报废时间
struct equipment *next;
}Equipment;
void fprintE(Equipment *head); //将设备信息输出到文件
void addEquipment(Equipment *head); //添加设备
void deleteEquipment(Equipment *head,int num); //删除设备
void changeEquipment(Equipment *head,int num); //更新设备
void findEquipment(); //设备查找
Equipment* fscanE(); //从文件读取设备信息
void repairEquipment(); // 维修管理
void baofeiEquipment();//报废设备信息管理
void printList(Equipment *head); //输出设备信息列表
int checkNum(Equipment *head, int num);
//将设备信息输出到文件
void addEquipment(Equipment *head){
Equipment *tail = head;
while(tail->next!=NULL) tail = tail->next;
Equipment *newnode = (Equipment*)malloc(sizeof(Equipment));
printf("请输入设备编号:");
scanf("%d",&newnode->num);
if(checkNum(head,newnode->num)){
printf("输入编号已有,输入失败!");
return;
}
printf("请输入设备名称:");
scanf("%s",&newnode->name);
printf("请输入设备型号:");
scanf("%s",&newnode->model);
printf("请输入生产厂家:");
scanf("%s",&newnode->factory);
printf("请输入设备购买日期:");
scanf("%s",&newnode->buy_date);
printf("请输入保质期:");
scanf("%s",&newnode->baozhqi);
printf("请输入责任人:");
scanf("%s",&newnode->zrr);
printf("请输入价格:");
scanf("%s",&newnode->price);
tail->next = newnode;
newnode->next = NULL;
fprintE(head);
printf("录入成功!");
}
//将链表输入到文件
void fprintE(Equipment *head){
FILE *fp=fopen("data.txt","w");
Equipment *current = head->next;
while(current){
fprintf(fp,"%d\n",current->num);
fprintf(fp,"%s\n",current->name);
fprintf(fp,"%s\n",current->model);
fprintf(fp,"%s\n",current->factory);
fprintf(fp,"%s\n",current->buy_date);
fprintf(fp,"%s\n",current->baozhqi );
fprintf(fp,"%s\n",current->zrr);
fprintf(fp,"%s\n",current->price);
printf("%d %s %s %s %s %s %s ",current->num,current->name,current->model,current->factory,current->buy_date,current->baozhqi,current->zrr,current->price);
current = current->next;
}
fclose(fp);
}
//删除设备
void deleteEquipment(Equipment *head,int num){
if(head->next==NULL){
printf("没有设备!请先录入设备!");
return;
}
Equipment *current = head;
Equipment *current_next = current->next;
while(current_next){
if(current_next->num==num){
current->next = current_next->next;
printf("删除成功!");
fprintE(head);
return;
}
current = current->next;
current_next = current_next->next;
}
printf("删除失败,没有找到设备编号!");
}
//设备更新
void changeEquipment(Equipment *head,int num){
if(head->next==NULL){
printf("没有设备!请先录入设备!");
return;
}
Equipment *current = head->next;
while(current && (current->num!=num)){
current = current->next;
}
if(current!=NULL){
printf("请输入更新后的数据:\n");
printf("请输入设备编号:");
scanf("%d",¤t->num);
printf("请输入设备名称:");
scanf("%s",¤t->name);
printf("请输入设备型号");
scanf("%s",¤t->model);
printf("请输入设备厂家:");
scanf("%s",¤t->factory);
printf("请输入设备购买日期:");
scanf("%s",¤t->buy_date);
printf("请输入设备数量:");
scanf("%s",¤t->amount);
printf("请输入设备单价:");
scanf("%s",¤t->price) ;
printf("请输入保质期(xx);");
scanf("%s",¤t->baozhqi);
fprintE(head);
}else{
printf("操作失败,没有找到设备编号!");
}
}
//设备查找
void findEquipment(){
Equipment *head = fscanE();
if(head->next==NULL){
printf("没有设备!请先录入设备!");
return;
}
int num;
printf("请输入查找设备的编号:");
scanf("%d",&num);
while(head){
if(head->num==num){
printf("编号为%d的信息为:\n",num);
printf("编号:%d\n",head->num);
printf("名称:%s\n",head->name);
printf("型号:%s\n",head->model);
printf("厂家:%s\n",head->factory);
printf("价格:%s\n",head->price);
printf("责任人:%s\n",head->zrr);
printf("保质期:%s\n",head->baozhqi);
return;
}
head = head->next;
}
printf("查找失败,没有找到设备编号!");
}
//从文件读取设备信息
Equipment* fscanE(){
Equipment *head1 = (Equipment*)malloc(sizeof(Equipment));
head1->next = NULL;
Equipment *current = head1;
FILE *fp = fopen("data.txt","r");
while(!feof(fp)){
Equipment *newnode = (Equipment*)malloc(sizeof(Equipment));
fscanf(fp,"%d\n",&newnode->num);
fscanf(fp,"%s\n",newnode->name);
fscanf(fp,"%s\n",newnode->model);
fscanf(fp,"%s\n",newnode->factory);
fscanf(fp,"%s\n",newnode->buy_date);
fscanf(fp,"%s\n",newnode->repair_time);
fscanf(fp,"%s\n",newnode->price);
current->next = newnode;
newnode->next = NULL;
current = current->next;
}
fclose(fp);
return head1;
}
//维修信息管理
void repairEquipment(){
int num;
int oper;
int name,factory,zrr;
int cost;
char time[16];
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" 欢迎进入实验室设备管理系统! \n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入维修操作(1~2):\n1.记录\t2.查找\n");
scanf("%d",&oper);
getchar();
switch(oper){
case 1:{
FILE *fp = fopen("myfile.txt","a");
printf("请输入维修编号:");
scanf("%d",&num);
printf("请输入维修时间(xxxx-xx-xx):");
scanf("%s",&time);
printf("请输入设备名:") ;
scanf("%s",&name) ;
printf("请输入修理厂家:");
scanf("%s",&factory);
printf("请输入修理费用:");
scanf("%s",&cost);
printf("请输入责任人:");
scanf("%s",&zrr);
fprintf(fp,"%d\n",num);
fprintf(fp,"%s\n",time);
fprintf(fp,"%s\n",name);
fprintf(fp,"%s\n",factory);
fprintf(fp,"%s\n",cost);
fprintf(fp,"%s\n",zrr);
fflush(fp);
fclose(fp);
printf("记录成功!");
break;
}case 2:{
int t = 0;
printf("请输入查找编号:");
scanf("%d",&num);
int rnum;
FILE *fp = fopen("myfile.txt","r");
while(!feof(fp)){
fscanf(fp,"%d\n",&rnum);
fscanf(fp,"%s\n",&time);
fscanf(fp,"%s\n",&name);
fscanf(fp,"%s\n",&factory);
fscanf(fp,"%s\n",&cost);
fscanf(fp,"%s\n",&zrr);
if(rnum==num){
printf("编号:%d\n维修时间:%s\n设备名:%s\n厂家:%s\n费用:%s\n责任人:%s\n",rnum,time,name,factory,cost,zrr);
t = 1;
}
}
if(t==0){
printf("查询错误,没有找到维修记录!");
}
fclose(fp);
break;
}
default:{
printf("输入有误,操作失败!");
}
}
}
//报废设备信息管理
void baofeiEquipment(){
int num;
int oper;
int name;
char amount[20];
char time[16];
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" 欢迎进入实验室设备管理系统! \n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请选择(1~2):\n1.记录\t2.查找\n");
scanf("%d",&oper);
getchar();
switch(oper){
case 1:{
FILE *fp = fopen("myfile.txt","a");
printf("请输入报废设备编号:");
scanf("%d",&num);
printf("请输入报废时间(xxxx-xx-xx):");
scanf("%s",&time);
printf("请输入设备名:") ;
scanf("%s",&name) ;
printf("请输入数量:");
scanf("%s",&amount);
fprintf(fp,"%d\n",num);
fprintf(fp,"%s\n",time);
fprintf(fp,"%s\n",name);
fprintf(fp,"%s\n",amount);
fflush(fp);
fclose(fp);
printf("记录成功!");
break;
}case 2:{
int t = 0;
printf("请输入查找编号:");
scanf("%d",&num);
int rnum;
FILE *fp = fopen("myfile.txt","r");
while(!feof(fp)){
fscanf(fp,"%d\n",&rnum);
fscanf(fp,"%s\n",&time);
fscanf(fp,"%s\n",&name);
fscanf(fp,"%s\n",&amount);
if(rnum==num){
printf("编号:%d\n报废时间:%s\n设备名:%s\n数量:%s\n",rnum,time,name,amount);
t = 1;
}
}
if(t==0){
printf("查询错误,没有找到报废记录!");
}
fclose(fp);
break;
}
default:{
printf("输入有误,操作失败!");
}
}
}
//输出设备信息列表
void printList(Equipment *head){
if(head->next==NULL){
printf("没有设备,请先录入设备!");
return;
}
Equipment *current = head->next;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" 实验室所有设备及其相关信息为以下: \n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("===============================================================:\n");
printf("编号 名称 型号 厂家 购买日期 责任人 保质期 价格\n");
while(current){
printf("\n%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",current->num,current->name,current->model,current->factory,current->buy_date,current->zrr,current->baozhqi,current->price);
current = current->next;
}
}
//检查设备编号是否相同
int checkNum(Equipment *head, int num){
if(head->next==NULL) return 0;
Equipment *current = head->next;
while(current){
if(current->num == num){
return 1;
}
current = current->next;
}
return 0;
}
int main(){
Equipment *head = (Equipment*)malloc(sizeof(Equipment));
head->next = NULL;
int num = -1;
while(num!=0){
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" 欢迎进入实验室设备管理系统! \n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("~ 请输入想要实现的功能选项: ~\n");
printf("\n");
printf("~ 【1】设备信息录入 ~\n");
printf("\n");
printf("~ 【2】设备信息更改 ~\n");
printf("\n");
printf("~ 【3】设备信息删除 ~\n");
printf("\n");
printf("~ 【4】设备查找 ~\n");
printf("\n");
printf("~ 【5】维修信息管理 ~\n");
printf("\n");
printf("~ 【6】报废设备信息管理 ~\n");
printf("\n");
printf("~ 【7】显示所有设备 ~\n");
printf("\n");
printf("~ 【8】使用手册 ~\n");
printf("\n");
printf("~ 【9】关于系统 ~\n");
printf("\n");
printf("~ 【0】退出系统 ~\n");
printf("\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入选项:");
scanf("%d",&num);
int num1;
system("cls");
switch(num){
case 0:{break;}
case 1:{
addEquipment(head);
break;
}
case 2:{
printf("请输入更改信息的设备编号:");
scanf("%d",&num1);
getchar();
changeEquipment(head,num1);
break;
}
case 3:{
printf("请输入需要删除的设备编号:");
scanf("%d",&num1);
getchar();
deleteEquipment(head,num1);
break;
}
case 4:{
findEquipment();
break;
}
case 5:{
repairEquipment();
break;
}case 6:{
baofeiEquipment();
break;
}case 7:{
printList(head);
break;
}case 8:{
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\t欢迎进入实验室设备管理系统!\n\n");
printf("请用户进入系统后,输入操作对应的数字,即可进行相关操作。\n");
printf("若出现故障或者其它问题请联系工作人员。\n");
printf("tel:12345678999;邮箱:xxx\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
break;
}case 9:{
printf("*************************************\n");
printf("\t名称:实验室设备管理系统\n");
printf("\t系统版本:2.1\n");
printf("\t系统作者:cainiao19\n");
printf("*************************************\n");
break;
}
default:{
printf("输入有误,操作失败!");
}
}
system("Pause");
system("cls");
}
return 0;
}
简要说明
要了解C语言就要从语法基础来学习起,首先要是要了解它的结构,比如变量,首先要了解变量的定义方式(格式),其意义是什么(定义变量有什么用); 其次就是要我要怎么去运用它(我要用什么型式去应用它)。在C语言的命令行中所有的语句都是有它自己的一定格式和形式出现在我们面前,所以我们在学习某种语句或命令时你首先要了解的就是它的规则是什么、有什么用、怎么实现等。这些都是语法基础也是C语言的基础如果把它们都了解很好了,那么你编起程序来就很得心应手了。比如说IF ELSE 和 SWITCH CASE 这两种条件语句都是用来判断执行功能的,那我要什么时侯用IF 什么时侯用 SWITCH呢?如果你很好地了解它们的结构和作用的话那么就知道:若它的条件分支是多个而且条件的值是整数或是一个字符值时就会选SWITCH而不会选IF。因为如果条件分支太多时要用IF语句,这样一定会出现IF的嵌套,如果IF的嵌套越多时程序的开销就会随着增大,这样对整个程序的运行效率就大在降底。而SWITCH就不同,它只要比较一次就可以找出条件的结果比起嵌套IF它的效率就大大的提高了很多。不过SWITCH也有它的约束条件,就是它的条件值一定要是一个整型数或是一个字符值,所以碰到它不能解决的问题时我们也会通常使用IF语句,毕竟IF语句它使用起来也比较方便用
的范围也比较广。所以说了解语法规则是很重要的,如果没有一个良好的语法基础是很难编出一个好的程序!学习好基础后我们就可以开始来编程了。