该程序运行时有错误,请修改程序,使程序能正确运行,并输出如下结果:
num:1001
name:zhang
num:1002
name:Li
age:20
注意:不能更改程序结构。
#include
#include
using namespace std;
class Student
{
public:
void display();
Student(int n, string nam) : num(n), name(nam) {};
private:
int num;
string name;
};
void Student::display()
{
cout << "num:" << num << endl;
cout << "name:" << name << endl;
}
class Student1 : protected Student
{
public:
void display1();
Student1(int n, string nam, int ag) : num(n), name(nam), age(ag) {};
private:
int age;
};
void Student1::display1()
{
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "age:" << age << endl;
}
int main()
{
Student stud(1001, "zhang");
stud.display();
Student1 stud1(1002, "Li", 20);
stud1.display1();
return 0;
}
查看答案和解析【26考研辅导课程推荐】:26考研集训课程,VIP领学计划,26考研VIP全科定制套餐(公共课VIP+专业课1对1) , 这些课程中都会配有内部讲义以及辅导书和资料,同时会有教研教辅双师模式对大家进行教学以及督学,并配有24小时答疑和模拟测试等,可直接咨询在线客服老师领取大额优惠券。
启航教育热门私房课
MORE小班面授 名额有限 抢先体验
编辑推荐
最新内容