6-8 你好,自定义类型的输入输出
分数 15
全屏浏览
切换布局
作者 向训文
单位 惠州学院
完善程序,使程序正确运行:
Student
类为Person
类的派生类
裁判测试程序样例:
#include <iostream>
#include <string>
using namespace std;
class Person {
public:
Person(const string &name, int age):
m_name(name), m_age(age) {}
protected:
string m_name;
int m_age;
};
// 请将答案填写在这里
int main() {
Student s; // 默认名字为unknown,年龄和分数都为0
cout << s << endl;
cin >> s; // 输入名字(纯字母,无空格),输入年龄,输入分数
cout << s << endl;
return 0;
}
输入样例:
在这里给出一组输入。例如:
tom 18 80
输出样例:
在这里给出相应的输出。例如:
unknown 0 0
tom 18 80