OJ第三批——Problem E:C++習題 輸入輸出--私有繼承

問題及代碼:

 

#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 Student;
class Student1:public Student
{
public:
    void get_value_1()
    {
        get_value();
        cin>>age>>addr;
    }
    void display_1()
    {
        display();
        cout<<"age: "<<age<<endl;
        cout<<"address: "<<addr<<endl;
    }
private:
    int age;
    string addr;
};
int main()
{
    Student1 stud1;
    stud1.get_value_1();
    stud1.display_1();
    return 0;
}


 

運行結果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章