学生成绩管理程序设计
发布网友
发布时间:2022-12-05 05:30
我来回答
共1个回答
热心网友
时间:2024-12-05 17:16
这个是C语言的编程
程序代码
#include<stdio.h>
struct student_type
{
char name[10];
char num[12];
char class[20];
float score[3];
float ave;
}stud[4];
void main()
{
void display();
void save();
int i;
float sum[4];
system("cls");
printf("Welcome!\n");
printf("Please input one student's name number class and score:\n");
for (i=0;i<4;i++)
{
scanf("%s%s%s%f%f%f",stud[i].name,stud[i].num,
stud[i].class,&stud[i].score[0],&stud[i].score[1],
&stud[i].score[2]);
sum[i]=stud[i].score[0]+stud[i].score[1]+stud[i].score[2];
stud[i].ave=sum[i]/3;
}
printf("\n");
save();
display();
}
void save()
{
FILE *fp;
int i;
if((fp=fopen("score.txt","wb"))==NULL)
{
printf("The file can not open\n");
return;
}
for(i=0;i<4;i++)
if(fwrite(&stud[i],sizeof(struct student_type),1,fp)!=1)
{printf("file write error\n");
return;
}
fclose(fp);
}
void display()
{
FILE *fp1;
int i;
fp1=fopen("score.txt","rb");
for(i=1;i<=28;i++)
printf("%c ",1);
printf("\n");
printf("\n name No. class score1 score2 score3 ave\n");
printf("\n");
for(i=0;i<4;i++)
{
fread(&stud[i],sizeof(struct student_type),1,fp1);
printf("%-6s %.12s %s %7.2f %7.2f %7.2f %7.2f\n",stud[i].name,stud[i].num,stud[i].class,
stud[i].score[0],stud[i].score[1],stud[i].score[2],stud[i].ave);
}
fclose(fp1);
}追问大哥!一运行29个错误啊!!!!