wangjiejob1.cpp
来自「一个数据库的小例子 实现了查询修改更新闪出各种操作 并能对基本表进行删除」· C++ 代码 · 共 57 行
CPP
57 行
//上机试题--成绩文件
#include <stdio.h>
#include <stdlib.h>
#define num 5;
struct stud_type
{
int no;
char name[20];
float score;
};
main()
{
struct stud_type student [5];
int i,j,m=0,n=0;
float total=0,average,percentage1,percentage2;
FILE *fp;
if((fp = fopen("d:\\project1\wangjiejob1.txt","r"))==NULL)
{
printf("the file is error");
fgetch();
exit(0);
}
else
{
for(j =0; j<num; j++)
fscanf(fp,"%d %s %f" ,&student[i].no,ststudent[i].name,&student[i].score);
printf("\n");
}
for(j =0; j<num; j++)
{
total += student[j].score ;
if(student[j++].score >= 90)m++;
if(student[j++].score < 60)m++;
average =(float)(total/num);
printf("the average score is: %f \n", average);
percentage1 =(float) (m/num);
printf("优秀率是:\n", percentage1 );
percentage2 =(float)(n/num);
printf("不及格率是:\n", percentage2 );
fclose(fp);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?