|
|
|
@ -829,104 +829,123 @@ end
|
|
|
|
|
|
|
|
|
|
//函数功能:按姓名查找学生成绩并显示查找结果
|
|
|
|
|
```
|
|
|
|
|
function SearchbyName(STU stu[],int n,int m) do
|
|
|
|
|
void SearchbyName(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
char x[MAX_LEN];
|
|
|
|
|
int i,j;
|
|
|
|
|
printf "Input the name you want to search:"
|
|
|
|
|
input x
|
|
|
|
|
for from i=0 to n-1 do
|
|
|
|
|
if strcmp(stu[i].name,x)==0 do
|
|
|
|
|
printf "%ld\t%s\t",stu[i].num,stu[i].name"
|
|
|
|
|
for from j=0 to m-1 do
|
|
|
|
|
printf "%.0f\t"
|
|
|
|
|
end
|
|
|
|
|
printf ".0f\t%.0f\n"
|
|
|
|
|
printf("Input the name you want to search:");
|
|
|
|
|
scanf("%s", x);
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(stu[i].name,x)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("%ld\t%s\t",stu[i].num,stu[i].name);
|
|
|
|
|
for(j=0;j<m;j++)
|
|
|
|
|
{
|
|
|
|
|
printf("%.0f\t",stu[i].score[j]);
|
|
|
|
|
}
|
|
|
|
|
printf(".0f\t%.0f\n",stu[i].sum,stu[i].aver);
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
printf "\nNot found!\n"
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\nNot found!\n");
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//函数功能:统计各分数段的学生人数及所占的百分比
|
|
|
|
|
```
|
|
|
|
|
funtion StatisticAnalysis(STU stu[],int n,int m) do
|
|
|
|
|
void StatisticAnalysis(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
int i,j,t[6];
|
|
|
|
|
for from j=0 do m-1 do
|
|
|
|
|
printf "For course %d:\n"
|
|
|
|
|
for(j=0;j<m;j++)
|
|
|
|
|
{
|
|
|
|
|
printf("For course %d:\n",j+1);
|
|
|
|
|
memset(t,0,sizeof(t)); //将数组 t 的全部元素初始化为0
|
|
|
|
|
for from i=0 to n-1 do
|
|
|
|
|
if stu[i].score[j]>=0&&stu[i].score[j]<60 set t[0]++
|
|
|
|
|
else if stu[i].score[j]<70 set t[1]++;
|
|
|
|
|
else if stu[i].score[j]<80 set t[2]++;
|
|
|
|
|
else if stu[i].score[j]<90 set t[3]++;
|
|
|
|
|
else if stu[i].score[j]<100 set t[4]++;
|
|
|
|
|
else if stu[i].score[j]==100 set t[5]++;
|
|
|
|
|
end
|
|
|
|
|
for from i=0 to 4 do
|
|
|
|
|
if i==0 printf "<60\t%d\t%.2f%%\n"
|
|
|
|
|
else if i==5 printf "%d\t%d\t%.2f%%\n"
|
|
|
|
|
else printf "%d-%d\t%d\t%.2f%%\n"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if(stu[i].score[j]>=0&&stu[i].score[j]<60) t[0]++;
|
|
|
|
|
else if(stu[i].score[j]<70) t[1]++;
|
|
|
|
|
else if(stu[i].score[j]<80) t[2]++;
|
|
|
|
|
else if(stu[i].score[j]<90) t[3]++;
|
|
|
|
|
else if(stu[i].score[j]<100) t[4]++;
|
|
|
|
|
else if(stu[i].score[j]==100) t[5]++;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<=5;i++)
|
|
|
|
|
{
|
|
|
|
|
if(i==0) printf("<60\t%d\t%.2f%%\n",t[i],(float)t[i]/n*100);
|
|
|
|
|
else if(i==5) printf("%d\t%d\t%.2f%%\n",(i+5)*10,t[i],(float)t[i]/n*100);
|
|
|
|
|
else printf("%d-%d\t%d\t%.2f%%\n",(i+5)*10,(i+5)*10+9,t[i],(float)t[i]/n*100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//函数功能:打印学生成绩
|
|
|
|
|
```
|
|
|
|
|
function PrintScore(STU stu[],int n,int m) do
|
|
|
|
|
void PrintScore(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
for from i=0 to n-1 do
|
|
|
|
|
printf "%ld\t%s\t"
|
|
|
|
|
for from j=0 to m-1 do
|
|
|
|
|
printf "%.0f\t"
|
|
|
|
|
end
|
|
|
|
|
printf "%.0f\t%.0f\n"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
printf("%ld\t%s\t", stu[i].num, stu[i].name);
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
{
|
|
|
|
|
printf("%.0f\t", stu[i].score[j]);
|
|
|
|
|
}
|
|
|
|
|
printf("%.0f\t%.0f\n", stu[i].sum, stu[i].aver);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//输出 n 个学生的学号、姓名及 m 门课程的成绩到文件 student.txt 中
|
|
|
|
|
```
|
|
|
|
|
function WritetoFile(STU stu[],int n,int m) do
|
|
|
|
|
void WritetoFile(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
if fp = fopen("student.txt","w") == NULL do
|
|
|
|
|
printf "Failure to open score.txt!\n"
|
|
|
|
|
if((fp = fopen("student.txt","w")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Failure to open score.txt!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp, "%d\t%d\n", n, m); //将学生人数和课程门数写入文件
|
|
|
|
|
for from i=0 to n-1 do
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fp, "%10ld%10s", stu[i].num, stu[i].name);
|
|
|
|
|
for from j=0 to m-1 do
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fp, "%10.0f", stu[i].score[j]);
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp, "%10.0f%10.0f\n", stu[i].sum, stu[i].aver);
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//从文件中读取学生的学号、姓名及成绩等信息写入到结构体 stu 中
|
|
|
|
|
```
|
|
|
|
|
function ReadfromFile(STU stu[],int *n,int *m) do
|
|
|
|
|
void ReadfromFile(STU stu[],int *n,int *m)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int i, j;
|
|
|
|
|
if fp = fopen("student.txt","r") == NULL do
|
|
|
|
|
printf "Failure to open score.txt!\n"
|
|
|
|
|
if ((fp = fopen("student.txt","r")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Failure to open score.txt!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
fscanf(fp, "%d\t%d", n, m); //从文件中读出学生人数,课程门数
|
|
|
|
|
for from i=0 to *n-1 do //学生人数保存在n指向的储存单元
|
|
|
|
|
for (i=0; i<*n; i++) //学生人数保存在n指向的储存单元
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp, "%10ld", &stu[i].num);
|
|
|
|
|
fscanf(fp, "%10s", stu[i].name);
|
|
|
|
|
for form j=0 to *m-1 do //课程门数保存在m指向的储存单元
|
|
|
|
|
for (j=0; j<*m; j++) //课程门数保存在m指向的储存单元
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp, "%10f", &stu[i].score[j]); //不能用%10.0f
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
fscanf(fp, "%10f%10f", &stu[i].sum, &stu[i].aver); //不能用%10.0f
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
```
|