ACM输入输出--保护继承

来源:互联网 发布:绘制户型图软件 编辑:程序博客网 时间:2024/05/06 13:24
#include <iostream>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_value1()    {        get_value();        cin>>age>>address;    }    void display1()    {        display();        cout<<"age: "<<age<<endl;        cout<<"address: "<<address<<endl;    }    private:    int age;    string address;};/* C++代码 */int main(){    Student1 stud1;    stud1.get_value1();    stud1.display1();    return 0;}

0 0