#include
#include
struct student
{
char name[20];
int age;
char sex;
int height;
}; //定义一个结构体(student 学生),包含姓名(最大长度为20)、年龄、性别、体重
int i;
struct student stu[100]; //结构体数组,可定义100个结构体
void delestu(); //删除学生
int menu(); //主菜单
struct student getstu(void); //查找学生
void selectbyname(); // 按姓名查找
void selectbyage(); // 按年龄查找
void selectbysex(); // 按性别查找
void selectbyheight(); // 按体重查找
void showstu(struct student s); //显示学生
////下面为显示学生,包括其姓名、年龄、性别、体重等信息
void showstu(struct student s)
{
printf("a student:\n");
printf("name:%s\n",s.name);
printf("age:%d\n",s.age);
printf("sex:%s\n",s.sex);
printf("height:%d\n",s.height);
}
//主菜单,可输入数字选择:1、添加学生 2、显示所有学生姓名 3、显示所有学生信息 4-7 分别按姓名、年龄、性别、体重来查找学生 8、删除学生 9、退出
int menu()
{
int i;
i=0;
while (1)
{
printf("pelase select a menu:\n");
printf("1:add a student.\n");
printf("2:list the name all the student.\n");
printf("3:list informations of all the student.\n");
printf("4:select a student by name.\n ");
printf("5:select student by age.\n");
printf("6:select student by sex.\n");
printf("7:select student by height.\n");
printf("8:deleta a student.\n");
printf("9:exit.\n");
scanf("%d",&i);
if(i==9)
{
printf("byebye.\n");
exit(1);
}
if(i<1||i>9)
{
printf("error.\n");
continue;
}
else
{
return(i);
}
}
}
//查找学生
struct student getstu (void)
{
struct student stu;
char name[20];
printf("pelase input age:\n");
scanf("%d",&stu.age);
printf("pelse input height:\n");
scanf("%d",&stu.height);
printf("please input sex:\n");
scanf("%d",&stu.sex);
printf("please input name:\n");
scanf("%s",name);
strcpy(stu.name,name);
return(stu);
}
//按姓名查找学生
void selectbyname()
{
int j,n;
char name[20];
n=0;
printf("please input a name;\n");
scanf("%s",name);
for(j=0;j=i;j++)
{
if(strcmp(stu[j].name,name))
{
showstu (stu[j]);
n++;
}
}
if(n==0)
{
printf("there is no such a student.\n ");
}
}
void delestu()
{
int j,n;
char name [20];
n=0;
printf("delete a student:\n");
printf("please input a name :\n");
scanf("%s",name);
for(j=0;j{
if(strcmp(stu[j].name,name))
{
for(;j
stu[j]=stu[j+1];
}
n++;
i--;
break;
}
}
if(n==0)
{
printf("there is no such a student.\n");
}
}
//按年龄查找学生
void selectbyage()
{
int j,k,t,n;
n=0;
printf("please input a top age:\n");
scanf("%d",&j);
printf("please input a bottom age:\n");
scanf("%d",&k);
for(t=0;t{
if(stu[t].age<=j &&stu[t].age>k)
{
showstu(stu[t]);
n++;
}
}
if(n==0)
{
printf("there is no such a student.\n");
}
}
//按体重查找学生
void selectbyheight()
{
int j,k,t,n;
n=0;
printf("please input a top height:\n");
scanf("%d",&j);
printf("please input a bottom height:\n");
scanf("%d",&k);
for(t=0;t{
if(stu[t].height<=j &&stu[t].height>=k)
{
showstu(stu[t]);
n++;
}
}
if(n==0)
{
printf("there is no such a student.\n");
}
}
晕,这是啥啊?