设计一一个名为 student 学生类,其中有数据成员:姓名( name )、性别( sex )、学号( num )、分数( score );类中的成员函数:设置带有3个参数的构造函数和无参构造函数、输出学生信息的函数 display (),更改学生信息的函数 modify
(1)完成 student 类的定义和相应成员函数的实现;
(2)创建﹣个 student 对象st1。 st 的信息为"张三,男,1234567",将st1学生分数更新为78,显示更新后学生的信息。
(3)创建一﹣个 student 对象st2,实现学生st2=st1;并输出st2的信息。
#include <iostream>
#include <string>
using namespace std;
class student {
private:
string name;
string sex;
string num;
int score;
public:
student() {}
student(string n, string s, string no, int sc) {
name = n;
sex = s;
num = no;
score = sc;
}
void display() {
cout << "姓名:" << name << ",性别:" << sex << ",学号:" << num << ",分数:" << score << endl;
}
void modify(int sc) {
score = sc;
}
};
int main() {
student st1("张三", "男", "1234567", 0);
st1.modify(78);
st1.display();
student st2 = st1;
st2.display();
return 0;
}