【C++谭浩强版】【第5章 继承与派生】【习题1】公用继承方式数据的输入与输出
#include<iostream>
#include<string>
using namespace std;
class student
{public:
void get_value()
{
cin>>num>>name>>sex;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
private:
int num;
string name;
char sex;
};
class student1:public student
{
public:
void get_value_1()
{
cin>>age>>addr;
}
void display_1()
{
cout<<"age:"<<age<<endl;
cout<<"adress:"<<addr<<endl;
}
private:
int age;
string addr;
};
void main()
{
student1 stu;
stu.get_value();
stu.get_value_1();
stu.display();
stu.display_1();
}