文档库 最新最全的文档下载
当前位置:文档库 › 二实验题(改)文本

二实验题(改)文本

#include "stdio.h"
#include "string.h"
struct stu
{ int num;
char name[20];
char sex;
float score;
};
int main()
{
struct stu boy[6]={{101,"li ping ",'m',45},
{102,"zhang ping",'m',62.5},
{103,"he fang",'m',92.5},
{104,"cheng ling",'f',87},
{106,"wang ming",'m',58}};
struct stu *p;
void aaa(struct stu *p);
void join(struct stu boy[],struct stu *p);
void del(struct stu boy[],struct stu *p);
p=boy;
aaa(p);
printf("\n");
join(boy,p);
printf("\n");
del(boy,p);
}

//计算不及格人数
void aaa(struct stu *p)
{
int c=0,i;
float aaa,s=0;
for(i=0;i<5;i++,p++)
{s+=p->score;
if(p->score<60) c+=1;
}
printf("不及格人数为%d\n",c);
}

//插入信息
void join(struct stu boy[],struct stu *p)
{
printf("请输入要加在谁的前面?\n");
char q[20];
gets(q);
int k=0;
while(strcmp(p->name,q)!=0)
{
k++;
p++;
if(k>=5)
{ printf("此人不存在\n");
break;
}
}
if(k<5)
{
int a=5,b=4;
for(;;a--,b--)
{boy[a]=boy[b];
if(b==k)
break;}
printf("请输入要插入的学生的学号和姓名(逗号隔开):");
int w;
float e;
char r[20];
char t;
scanf("%d,",&w);
gets(r);
printf("请输入要插入的学生的性别和分数(逗号隔开):");
scanf("%c,%f",&t,&e);
boy[k].num=w;
strcpy(boy[k].name,r);
boy[k].sex=t;
boy[k].score=e;
for(int i=0;i<6;i++)
printf("num=%d,name=%s,sex=%c,score=%.2f\n",boy[i].num,boy[i].name,boy[i].sex,boy[i].score);
}
}

//删除信息
void del(struct stu boy[],struct stu *p)
{
printf("请输入要删除的信息的姓名:");
scanf("\n");
char o[20];
gets(o);
int k=0;
while(strcmp(p->name,o)!=0)
{
k++;
p++;
if(k>5)
{ printf("此人不存在\n");
break;
}
}
if(k<=5)
{ int c;
c=k+1;
while(k<=4)
{boy[k]=boy[c];k++;c++;}
for(int i=0;i<5;i++)
printf("num=%d,name=%s,sex=%c,score=%.2f\n",boy[i].num,boy[i].name,boy[i].sex,boy[i].score);
}
}

相关文档
相关文档 最新文档