DOC

EXAMPLE2_4_10

By Barry Peterson,2014-04-01 01:54
17 views 0
EXAMPLE2_4_10

2.4-10 学生成绩处理

    输入10个学生的成绩;求平均成绩;并将低于平均成绩的分数打印出来。

#include <iostream.h>

    #include <iomanip.h>

    void readdata(float score[10]) {

     cout<<"Please input 10 student's score:"<<endl;

     for(int i=0;i<10;i++)

     cin>>score[i];

     return;

    }

    float aver(float score[10]) {

     float sum=0; int i;

     for(i=0;i<10;i++)

     sum+=score[i];

     return(sum/10);

    }

    void print(float score[10],float ave) {

     int i;

     cout<<"the scores which are below the average:";

     for(i=0;i<10;i++)

     if(score[i]<ave)

     cout<<score[i]<<" ";

     cout<<endl;

     return;

    }

void main()

    {

     void readdata(float score[10]);

     float aver(float score[10]);

     void print(float score[10],float ave);

     float ave,score[10];

     readdata(score);

     ave=aver(score);

     cout<<"average="<<ave<<endl;

     print(score,ave);

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com