学生の試験成績に対する処理
3566 ワード
/*
* Copyright (c) 2012,
* All rights reserved.
* :
* :2012 12 07
* :v1.0
*
* :
* : ,5 ,1、
2、 , , ;
3、 90 85
* :
* :
* :
*/
#include<iostream>
using namespace std;
int main()
{
void avsco(float *pscore,float *paver);
void avcour1(char(*pcourse)[10],float *pscore);
void fail2(char course[5][10],int num[],float *pscore,float aver[4]);
void good(char course[5][10],int num[4],float *pscore,float aver[4]);
int i,j,*pnum,num[4];
float score[4][5],aver[4],*pscore,*paver;
char course[5][10],(*pcourse)[10];
cout<<"input course:"<<endl;
pcourse=course;
for(i=0;i<5;i++)
{
cin>>course[i];
}
cout<<"input NO.and score:"<<endl;
cout<<"NO.";
for(i=0;i<5;i++)
{
cout<<","<<course[i];
}
cout<<endl;
pscore=&score[0][0];
pnum=&num[0];
for(i=0;i<4;i++)
{
cin>>*(pnum+i);
for(j=0;j<5;j++)
{
cin>>*(pscore+5*i+j);
}
}
paver=&aver[0];
cout<<endl<<endl;
avsco(pscore,paver); //
avcour1(pcourse,pscore);//
cout<<endl<<endl;
fail2(pcourse,pnum,pscore,paver);// ,
cout<<endl<<endl;
good(pcourse,pnum,pscore,paver);//
return 0;
}
//
void avsco(float *pscore,float *paver)
{
int i,j;
float sum,average;
for(i=0;i<4;i++)
{
sum=0.0;
for(j=0;j<5;j++)
{
sum=sum+(*(pscore+5*i+j)); //
}
average=sum/5; //
*(paver+i)=average;
}
}
//
void avcour1(char(*pcourse)[10],float *pscore)
{
int i;
float sum,average1;
sum=0.0;
for(i=0;i<4;i++)
{
sum=sum+(*(pscore+5*i)); //
}
average1=sum/4;
cout<<"course1:"<<*pcourse<<",averge score:"<<average1<<endl;
}
//
void fail2(char course[5][10],int num[],float *pscore,float aver[4])
{
int i,j,k,labe1;
cout<<"===========Student who failed in two courses======="<<endl;
cout<<"NO. ";
for(i=0;i<5;i++)
{
cout<<course[i]<<" ";
}
cout<<" averge"<<endl;
for(i=0;i<4;i++)
{
labe1=0;
for(j=0;i<5;j++)
{
if(*(pscore+5*i+j)<60.0)
{
labe1++;
}
}
if(labe1>=2)
{
cout<<num[i]<<" ";
for(k=0;k<5;k++)
{
cout<<*(pscore+5*i+j)<<" ";
}
cout<<" "<<aver[i]<<endl;
}
}
}
// ( 85 90 )
void good(char course[5][10],int num[4],float *pscore,float aver[4])
{
int i,j,k,n;
cout<<"=======Student whose score is good========"<<endl;
cout<<"NO. ";
for(i=0;i<5;i++)
{
cout<<course[i]<<" ";
}
cout<<" averge"<<endl;
for(i=0;i<4;i++)
{
n=0;
for(j=0;j<5;j++)
{
if(*(pscore+5*i+j)>85.0)
{
n++;
}
}
if((n==5)||(aver[i]>=90))
{
cout<<num[i]<<" ";
for(k=0;k<5;k++)
{
cout<<*(pscore+5*i+k)<<" ";
}
cout<<" "<<aver[i]<<endl;
}
}
}