c++的问题!

来源:百度知道 编辑:UC知道 时间:2024/06/02 00:26:39
#include <iostream>
#include <string>
using namespace std;
class student
{public:
student(int n, string nam )
{num=n;
name=nam;
}
void display()
{cout<<"num:"<<num<<endl<<"name:"<<nam<<endl;}
protected:
int num;
string name;
};
class student1:public student
{public:
student1(int n,string nam,int n1,string nam1,int a,string ad):
student(n,nam),monitor(n1,nam1)
{age=a;
addr=ad;
}
void show()
{cout<<"this student is:"<<endl;
display();
cout<<"age:"<<age<<endl;
cout<<"address:"<<addr<<endl<<endl;
}
void show_monitor()
{cout<<endl<<"class monitor is:"<<endl;
monitor.display();
}

void display()
{cout<<"num:"<<num<<endl<<"name:"<<name<<endl;}
protected:
int num;
string name;
};
//拼写错误“nam”

正确的程序是这样的:嘿嘿

#include <iostream>
#include <string>
using namespace std;
class student
{public:
student(int n, string nam )
{num=n;
name=nam;
}
void display()
{cout<<"num:"<<num<<endl<<"name:"<<name<<endl;}
protected:
int num;
string name;
};

class student1:public student
{public:
student1(int n,string nam,int n1,string nam1,int a,string ad):
student(n,nam),monitor(n1,nam1)
{age=a;
addr=ad;
}
void show()
{cout<<"this student is:"<<endl;
display();
cout<<"age:"<<age<<endl;
cout<<"add