文件中english.dat中给出的是2012级10000名新生入学英语分级考试全校同学的成绩 练习1:从文件中读出学生的成绩,输出最高、最低,以及平均成绩(平均成绩为小数)。
练习2:从文件中读出学生的成绩,统计90分以上学生的人数并输出。
练习3:从文件中读出学生的成绩,将超过90分的成绩输出/写入到文件good.dat中。
练习4:编程序,求出这次考试的平均成绩,并统计各分数段的人数(优秀:≥90,良好:≥80,中等:≥70,及格:≥60,不及格:<60)。
/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者:高古尊
* 完成日期:2013 年 12 月1 日
* 版 本 号:v1.0
*
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
* 算法设计:
*/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i;
double a[10000],max=0,min=100,sum=0;
ifstream infile("english.dat",ios::in);
if(!infile)
cerr<<"open error!"<<endl;
for(i=0; i<100; i++)
{
infile>>a[i];
sum+=a[i];
max=(max>a[i])?max:a[i];
min=(min<a[i])?min:a[i];
}
infile.close();
cout<<"平均成绩:"<<sum/100<<endl;
cout<<"最高分:"<<max<<endl;
cout<<"最低分:"<<min<<endl;
ofstream outfile("good.dat",ios::out);
if(!outfile)
{
cerr<<"open error!"<<endl;
}
int n=0,l=0,e=0;
for(i=0; i<100; i++)
{
if(a[i]>=90)
{
n++;
outfile<<a[i]<<endl;
}
else
{
if(a[i]<60)
l++;
else
e++;
}
}
outfile.close();
cout<<"优秀人数:"<<n<<endl;
cout<<"良好人数:"<<e<<endl;
cout<<"不及格人数:"<<l<<endl;
return 0;
}