下面的C++程序定义一个Student类,该类包含两个函数,aver函数是求一个学生两门课的平均值,Student函数是带参数的构造函数。请在划线处补充成分使程序完整。 #include(iostream.h) class Student

admin2017-05-04  48

问题 下面的C++程序定义一个Student类,该类包含两个函数,aver函数是求一个学生两门课的平均值,Student函数是带参数的构造函数。请在划线处补充成分使程序完整。
    #include(iostream.h)
    class Student
{
    public:
    Student(noat ma,noat ph)
    {
    ①__________;
    ②__________;
    }
    float avet(float ma,float ph)
    {
    agv=③__________;
    return(agv);
    }
    private:
    noat math:
    noat phy;
    noat agv;
    }
    }

选项

答案①math=ma ②phy=ph ③(math+phy)/2;

解析 因为Student函数是带参数的构造函数,所以用参数表里面的参数ma、ph来初始化类Student里的数据成员math、phy。根据平均函数的公式得出平均数是二者和的一半。
转载请注明原文地址:https://jikaoti.com/ti/z8F9FFFM
0

最新回复(0)