函数题:继承与派生
裁判测试程序给出父类People、派生类Student以及测试两个类的相关C++代码。
### 函数接口定义:
c++
Student::Student(string id, string name, string major, int score);
在这里解释接口参数。例如:其中 N 和 D 都是用户传入的参数。 N 的值不超过int的范围; D 是[0, 9]区间内的个位数。函数须返回 N 中 D 出现的次数。
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <iostream>
#include <string>
using namespace std;
class Person {
protected:
string id;
string name;
public:
Person(string id, string name) {
this->id = id;
this->name = name;
}
};
class Student : public Person {
private:
string major;
int score;
public:
Student(string id, string name, string major, int score);
friend ostream& operator <<(ostream &out, Student &s);
};
/* 请在这里填写答案 */
ostream& operator <<(ostream &out, Student &s) {
out << "ID:" << s.id
<< " 姓名:" << s.name
<< " 专业:" << s.major
<< " 成绩:" << s.score;
return out;
}
int main() {
Student a("ypc202101", "胡莘涵", "电子信息专业", 95);
cout << a << endl;
return 0;
}
### 输入样例:
in
无
### 输出样例:
out
ID:ypc202101 姓名:胡莘涵 专业:电子信息专业 成绩:95
答案:若无答案欢迎评论
### 函数接口定义:
c++
Student::Student(string id, string name, string major, int score);
在这里解释接口参数。例如:其中 N 和 D 都是用户传入的参数。 N 的值不超过int的范围; D 是[0, 9]区间内的个位数。函数须返回 N 中 D 出现的次数。
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <iostream>
#include <string>
using namespace std;
class Person {
protected:
string id;
string name;
public:
Person(string id, string name) {
this->id = id;
this->name = name;
}
};
class Student : public Person {
private:
string major;
int score;
public:
Student(string id, string name, string major, int score);
friend ostream& operator <<(ostream &out, Student &s);
};
/* 请在这里填写答案 */
ostream& operator <<(ostream &out, Student &s) {
out << "ID:" << s.id
<< " 姓名:" << s.name
<< " 专业:" << s.major
<< " 成绩:" << s.score;
return out;
}
int main() {
Student a("ypc202101", "胡莘涵", "电子信息专业", 95);
cout << a << endl;
return 0;
}
### 输入样例:
in
无
### 输出样例:
out
ID:ypc202101 姓名:胡莘涵 专业:电子信息专业 成绩:95
答案:若无答案欢迎评论