#include <iostream>
#include<cstring>
using namespace std;
struct student
{
char name[20];
int year;
int id;
double height;
double weight;
};
void insetname(student pa[],student *p)
{
int i=0;
for(i;pa[i].name[20]!=NULL;i++);
strcpy(pa[i].name,p->name);
pa[i].height=p->height;
pa[i].id=p->id;
pa[i].weight=p->weight;
pa[i].year=p->year;
}
void deletename(student pa[],student *p)
{
int i;
for(i=0;pa[i].name[20]!=NULL;i++)
if(strcmp(pa[i].name,p->name)==0)
{
for(i;pa[i].name[20]==NULL;i++)
pa[i]=pa[i+1];
break;
}
if(pa[i].name[20]==NULL)
{
cout<<"没有你要删除的姓名"<<endl;
return;
}
for(;pa[i].name[20]!=NULL;i++)
pa[i]=pa[i+1];
}
void showname(student pa[])
{
int i=0;
for(i=0;pa[i].name[20]!=NULL;i++)
{
cout<<pa[i].name[20]<<" "<<pa[i].id<<" "<<pa[i].year<<" "<<pa[i].height<<" "<<pa[i].weight<<endl;
}
}
int main()
{
int num;
int b=0;
student *p;
student iname[100];
for(int i=0;i<100;i++)
iname[i].name[20]=NULL;
cout<<"欢迎进入班级姓名管理系统"<<endl;
cout<<"1—插入,2—删除,3—遍历,4—退出"<<endl;
while(cin>>num)
{
if(num==1)
{
p=new student;
cout<<"请输入姓名"<<endl;
cin>>p->name;
cout<<"请输入ID"<<endl;
cin>>p->id;
cout<<"请输入年龄"<<endl;
cin>>p->year;
cout<<"请输入身高"<<endl;
cin>>p->height;
cout<<"请输入体重"<<endl;
cin>>p->weight;
insetname(iname,p);
}
if(num==2)
{
p=new student;
cout<<"请输入要删除的名字"<<endl;
cin>>p->name;
deletename(iname,p);
}
if(num==3)
{
showname(iname);
}
if(num==4)
break;
cout<<"1—插入,2—删除,3—遍历,4—退出"<<endl;
}
}