# pta第四次作业

1 实验设计思路

2 流程图

3实验代码


#include <stdio.h>
#define MAXN 10

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

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);
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;
int i;
{for(i=0;i<n;i++,p++)
if(p->score>=85&&p->score<=100)
else if(p->score<85&&p->score>=70)
else if(p->score<70&&p->score>=60)
else if(p->score<60&&p->score>=0)
x++;}
}
return x;
}


4 本题遇到的问题

5 git地址 https://git.coding.net/hxc980203/123.git

4.2
1 实验设计思路：

2 流程图

3实验代码

#include <stdio.h>
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<n;i++,p++)
{
p->sum=p->score[0]+p->score[1]+p->score[2];
}
}
void sort(struct student *p,int n)
{   struct	student t;
int i,j;
for(j=0;j<n-1;j++)
for(i=0;i<n-1-j;i++)
if((p+i)->sum<(p+i+1)->sum)
{t=*(p+i);
*(p+i)=*(p+1+i);
*(p+1+i)=t;
}
}


4 本题中遇到的问题

5 git地址 https://git.coding.net/hxc980203/566.git

posted @ 2018-04-24 19:23  黄学超  阅读(143)  评论(0编辑  收藏  举报