我想请教一下,这个程序应该怎么改,才能得到正确的答案。
#include"iostream"using namespace std;
class Student/*构造一个学生类*/
{
private:
int num;
protected:
char name[12];
char sex;
int age;
public:
void display()
{
cout<<"学号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"年龄:"<<age<<endl;
}
void Set_data()
{
cout<<"请输入学号:"<<endl;
cin>>num;
cout<<"请输入姓名:"<<endl;
cin>>name;
cout<<"请输入性别:"<<endl;
cin>>sex;
cout<<"请输入年龄:"<<endl;
cin>>age;
}
};
class CollegeStudent:private Student/*私有继承学生类*/
{
private:
char department[20];
char speciafy[20];
public:
void display1(CollegeStudent stu1)
{
stu1.display();
cout<<"姓名:"<<name<<endl;
cout<<"院系:"<<department<<endl;
cout<<"专业:"<<speciafy<<endl;
}
void Set_data1(CollegeStudent &stu2)
{
stu2.Set_data();
cout<<"请输入院系:"<<endl;
cin>>department;
cout<<"请输入专业:"<<endl;
cin>>speciafy;
}
};
void main()
{
CollegeStudent stu;
stu.Set_data1(stu);
stu.display1(stu);
}
运行的时候,没有得到相应的结果。帮忙看一下,谢谢!!