文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C++程序习题-保护继承[5.3]

C++程序习题-保护继承[5.3]

时间:2010-11-25  来源:chengxiaopeng

    将例5.3的程序修改,补充,写成一个完整,正确的程序,用保护继承方式。在程序中应包括输入数据的函数。

#include <iostream>
using namespace std;
class Student
{
    public:
    void get_value();
    void display();
        
    protected:
    int num;
    string name;
    char sex;
};

void Student :: get_value()
{
    cin >> num >> name >> sex;
}

void Student :: display()
{
    cout << "num:" << num << endl;
    cout << "name:" << name << endl;
    cout << "sex:" << sex << endl;
}

class Student1:protected Student
{
    public:
    void display_1();
    void get_value1();
     
    private:
    int age;
    string addr;
};

void Student1 :: display_1()
{
    cout << "num:" << num << endl;
    cout << "name:" << name << endl;
    cout << "sex:" << sex << endl;
    cout << "age:" << age << endl;
    cout << "address:" << addr << endl;
}

void Student1 :: get_value1()
{
     cin >> num >> name >> sex >> age >> addr;
}

int main()
{
    Student1 stu;
    stu.get_value1();
    stu.display_1();
    system("pause");
    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载