#include <stdio.h>
#include<string.h>
#include<iostream.h>
#define max 100
typedef struct Lab
{
char name,kind,people;
int num;
struct Lab *next;
}Lab,*Labb;
void InitLab(Labb &l)
{
l = new Lab;
l->next = NULL;
}
void creatlab(Labb &l,int n)
{
Labb p,s;
s=l;
int i,d;
char a,b,c;
for(i=1;i<=n;i++)
{cin>>a;cin>>b;cin>>c;cin>>d;
p=new Lab;
p->name=a;
p->kind=b;
p->people=c;
p->num=d;
p->next = NULL;
l->next=p;
l=p;
}
l=s;
}
void insertlab(Labb &l,int i,char a,char b,char c,int d)
{
Labb p,q,s;
int m=0;
if(i==1)
{
p=new Lab;
p->name=a;
p->kind=b;
p->people=c;
p->num=d;
p->next=l->next;
l->next=p;
}
else
{s=l;
while(m!=i-1)
{
s=s->next;
m++;
}
q=new Lab;
p->name=a;
p->kind=b;
p->people=c;
p->num=d;
q->next=s->next;
s->next=q;
}
}
void xiugai(Labb &l,int i ,char a,char b,char c,int d)
{Labb s;
int m=0;
s=l;
while(i!=m)
{s=s->next;
}
s->name=a;
s->kind=b;
s->people=c;
s->num=d;
}
void chaxun(Labb &l,char a)
{Labb s;
s=l;
while(s->name!=a)
{
s=s->next;
}
printf("%s\n",s->name);
printf("%s\n",s->kind);
printf("%s\n",s->people);
printf("%s\n",s->num);
}
void Printlab(Labb l ) {
Labb s=l->next;
cout<<"The laborary is:"<<endl;
while(s)
{
cout<<s->name<<" ";
cout<<s->kind<<" ";
cout<<s->people<<" ";
cout<<s->num<<" ";
s=s->next;
}
cout<<endl;
}
void ListDelete_L(Labb &l,int i ) {
Labb p,s;
int m=0;
if (i==1)
{
p=l;
l=l->next;
delete p;
}
else
{
p=l;
while (m!=i-1)
{p=p->next;
m++;
}
s=p->next;
p->next=p->next->next;
delete s;
}
}
void main()
{
Labb La;
int n;
InitLab(La);
printf("请输入实验室原有的器材和不同器材的数");
cin>>n;
creatlab(La, n);
printf("1 2 3 4 6\n");
printf("添加 删除 修改 查询 显示\n");
printf("请选择:\n");
scanf("%d",&n);
switch(1)
{
case 1:
printf("请输入 插入位置 设备的名字 种类 管理人 数量");
char q,w,e;
int d,i;
cin>>q;cin>>w;cin>>e;cin>>d;cin>>i;
insertlab(La,i,q,w,e,d);
break;
case 2:
printf("请输入删除的位置");
int j;
cin>>j;
ListDelete_L(La,j);
break;
case 3:
printf("请输入设备的名字 种类 管理人 数量和插入位置");
char z1,z2,z3;
int d1,i1;
cin>>z1;cin>>z2;cin>>z3;cin>>d1;cin>>i1;
xiugai(La,i,q,w,e,d);
break;
case 4:
printf("请输入设备的名字");
char a;
chaxun(La,a);
break;
case 6:
Printlab(La);
break;
}
} |