第四次作业

6-1 按等级统计学生成绩
1.设计思路
(1)第一步:观察题意了解各个参数与所需函数在题目中的意义;
第二步:设计算法编写函数,让函数的功能实现题目中所需的功能;
第三步:运行程序检测是否错误。
(2)流程图

2.实验代码
、、、

include

define MAXN 10

struct student{
int num;
char name[20];
int score;
char grade;
};

int set_grade( struct student *p, int n );

int main()
{ struct student stu[MAXN], *ptr;
int n, i, count;

ptr = stu;
scanf("%d\n", &n);
for(i = 0; i < n; i++){
   scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].score);
}

count = set_grade(ptr, n);
printf("The count for failed (<60): %d\n", count);
printf("The grades:\n");
for(i = 0; i < n; i++)
printf("%d %s %c\n", stu[i].num, stu[i].name, stu[i].grade);
return 0;
}
int set_grade( struct student *p, int n )
{ int x=0,i;
{for(i=0;i

include

struct student
{
int num;
char name[15];
float score[3];
float sum;
};
void calc(struct student p,int n);
void sort(struct student
p,int n);
int main()
{
struct student stu[5];
int i,j;
float f;
for(i=0;i<5;i++)
{
scanf("%d%s",&stu[i].num,stu[i].name);
for(j=0;j<3;j++)
{
scanf("%f",&f);
stu[i].score[j]=f;
}
}
calc(stu,5);
sort(stu,5);
for(i=0;i<5;i++)
{
printf("%5d%15s",stu[i].num,stu[i].name);
printf(" %.1f %.1f %.1f %.1f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2], stu[i].sum);
}
return 0;
}
void calc(struct student p,int n)
{ int i;
for(i=0;i
p,int n)
{ struct student t;
int i,j;
for(j=0;j<n-1;j++)
for(i=0;i

相关推荐