#include<iostream>
using namespace std;
#include<iomanip>
int main()
{
void Percent(float allGrades[],int m);
void step(float allGrades[],float aver,int m);
int i,m;
float allGrades[30],aver=0;
cout<<"请输入一个班学生某门课的成绩(每输一次按一下回车,输入的成绩为负数时将结束输入):"<<endl;
for(i=0;i<30;i++)
{
cout<<i+1<<":";
cin>>allGrades[i];
if(allGrades[i]<=0)
break;
}
m=i;
for(i=0;i<m;i++)
{
aver=aver+allGrades[i];
}
aver=aver/m;
step(allGrades,aver,m);
Percent(allGrades,m);
}
void step(float allGrades[],float aver,int m)
{
int i,j=0,k=0,failNum=0,upNum=0;
int failNames[30],upNames[30];
for(i=0;i<m;i++)
{
if(allGrades[i]>=aver)
{
upNames[j++]=i+1;
upNum++;
}
if(allGrades[i]<60)
{
failNames[k++]=i+1;
failNum++;
}
}
cout<<"******************************************************************************************"<<endl;
cout<<"不及格人数:"<<failNum<<endl;
cout<<"不及格名单:";
for(i=0;i<k;i++)
cout<<failNames[i]<<"号 ";
cout<<endl;
cout<<"高于平均分的人数:"<<upNum<<endl;
cout<<"高于平均分的人的名单:";
for(i=0;i<j;i++)
cout<<upNames[i]<<"号 ";
cout<<endl;
}
void Percent(float allGrades[],int m)
{
int i;
float percent[6];
for(i=0;i<m;i++)
{
if(allGrades[i]<60)
(percent[0])++;
if((60<=allGrades[i])&&(allGrades[i]<70))
(percent[1])++;
if((70<=allGrades[i])&&(allGrades[i]<80))
(percent[2])++;
if((80<=allGrades[i])&&(allGrades[i]<90))
(percent[3])++;
if((90<=allGrades[i])&&(allGrades[i]<100))
(percent[4])++;
if(allGrades[i]==100)
(percent[5])++;
}
for(i=0;i<6;i++)
{
percent[i]=(percent[i]/m)*100;
}
cout<<"各个分段的人数:"<<endl;
for(i=0;i<6;i++)
{
cout<<"第"<<i<<"段:"<<fixed<<setprecision(2)<<percent[i]<<"%"<<endl;
}
}