应该是怎样的结果呢?发代码出来分析一下
# define N 5
#include"stdio.h"
#include"stdlib.h"
struct student_score
{
long num;
char name[20];
float score[4];
float total;
float aver;
}s[N];
main()
{
FILE *fp1;
struct student_score getdata(struct student_score st, int x);
int putsgraph(int sa, int sb, int sc, int sd, int se);
int i = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0;
fp1 = fopen("c:\\turboc2\\filr1.rec", "w+");
for (i = 0;i < N;i++)
s[i] = getdata(s[i], i);
for (i = 0;i < N;i++)
fprintf(fp1, "%-7ld%-10s%10.1f%10.1f%10.1f%10.1f%10.1f%10.1f\n",
s[i].num, s[i].name, s[i].score[1], s[i].score[2], s[i].score[3], s[i].total, s[i].aver);
rewind(fp1);
{long num;
char name[20];
float e, f, g, h, total, aver;
for (i = 0;i < N;i++)
{
fscanf(fp1, "%ld&s%f%f%f%f%f%f\n", &num, &name, &e, &f, &g, &h, &total, &aver);
printf("%-7ld%-20s%10.1f%10.1f\n", num, name, total, aver);
if (aver < 60) s1++;
else if (aver < 70) s2++;
else if (aver < 80) s3++;
else if (aver < 90) s4++;
else if (aver <= 100) s5++;
}
}
fclose(fp1);
putsgraph(s1, s2, s3, s4, s5);
}
struct student_score getdata(struct student_score st, int x)
{
int y;
printf("\nEnter student%d\'s num:\n", x + 1);
scanf("%ld", &st.num);
getchar();
printf("\nEnter name:\n");
gets_s(st.name);
st.total = 0;
printf("\nEnter 4 scores:\n");
for (y = 0;y < 4;y++)
{
scanf("%f", &st.score[y]);
getchar();
st.total += st.score[y];
}
st.aver = st.total / 4;
return st;
}
int putsgraph(int sa,int sb,int sc,int sd,int se)
{
int i, j;
char graph[16][80];
for(i=0;i<16;i++)
{
for (j = 0;j < 79;j++)graph[i][j] = '0';
graph[i][79] = '\0';
}
for (j = 0;j < 79;j++) graph[11][j] = '-';
for (j = 3;j <= 15;j += 4)
{
graph[12][j] = '<';
graph[12][j + 2] = '0';
}
graph[12][4] = '6';
graph[12][8] = '7';
graph[12][12] = '8';
graph[12][16] = '9';
graph[12][19]='<';
graph[12][20]=' =' ;
graph[12][21]='1' ;
graph[12][22] = '0';
graph[12][23] = '0';
for (i = 10;i > (10 - sa);i--) graph[i][4] = 'o';
for (i = 10;i > (10 - sb);i--) graph[i][8] = 'o';
for (i = 10;i > (10 - sc);i--) graph[i][12] = 'o';
for (i = 10;i > (10 - sd);i--) graph[i][16] = 'o';
for (i = 10;i > (10 - se);i--) graph[i][20] = 'o';
for(i=0;i<16;i++) puts(graph[i]);
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y