建立一个学生类,有学号,姓名,两门课的成绩,要求通过构建函数赋初值,输出一个学生的学号和平均成绩(类名后加123)
#include <iostream>
using namespace std;
class student123 {
private:
string num;
string name;
double cir1;
double cir2;
public:
student123(string num, string name, double cir1, double cir2);
~student123();
double average();
};
student123::student123(string num, string name, double cir1, double cir2) {
this->num = num;
this->name = name;
this->cir1 = cir1;
this->cir2 = cir2;
}
student123::~student123() {}
double student123::average() {
return (cir1 + cir2) / 2.0;
}
int main() {
student123 s("123", "zhoujiel", 80, 82);
cout << s.average() << endl;
return 0;
}