oj成绩处理

来源:互联网 发布:python环境变量配置 编辑:程序博客网 时间:2024/06/05 16:01

问题:

//小平帮老师处理期末成绩时遇到了问题。他需要计算每个同学的平均成绩,//并判断他们是否通过了期末考试不及格成绩(<60),若都通过才能pass,//若没通过要说明是哪几科未通过。因此他需要两个函数,一个求平均成绩(不考虑小数),//另一个判断是否通过考试,通过输出pass,否则输出未通过的科目。请你们帮帮他!//期末包括Chinese,Math,English三门课程。

程序:

#include <iostream>using namespace std;class Student{protected:    int num,chinese,math,english;public:    Student(int n,int c,int m,int e):num(n),chinese(c),math(m),english(e){}    void aver()    {        cout<<((chinese+math+english)/3)<<endl;    }    void pass();    void printnum()    {        cout<<"student:"<<num<<endl;    }};void Student::pass()    {        int n=0;        if(chinese>=60)        {            n+=1;        }        else        {            cout<<"chinese is fail."<<endl;        }        if(math>=60)        {            n+=1;        }        else        {            cout<<"math is fail."<<endl;        }        if(english>=60)        {            n+=1;        }        else        {            cout<<"english is fail."<<endl;        }        if(n==3)        {            cout<<"pass"<<endl;        }    }int main(){    int num,chinese,math,english;    cin>>num>>chinese>>math>>english;    Student stu(num,chinese,math,english);    stu.printnum();    stu.aver();    stu.pass();    return 0;}

结果:

0 0
原创粉丝点击