栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++程序设计(第四版)例题11.8

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++程序设计(第四版)例题11.8

#include
#include
using namespace std;
class Teacher
{
public://公用部分
    Teacher(string nam, int a, string t)
    {
        //构造函数
        name = nam;
        age = a;
        title = t;
    }

    void display()
    {
        cout << " name:" << name << endl;
        cout << " age" << age << endl;
        cout << " title:" << title << endl;
    }
protected:

    string name;
    int age;
    string title;
};

class Student
{
public:
    Student(string nam, char s, float sco)
    {
        name1 = nam;
        sex = s;
        score = sco;
    }

    //构造函数
    void displayl()
    {
        cout << " name:" << name1 << endl;
        cout << " sex:" << sex << endl;
        cout << " score:" << score << endl;
    }
protected:

    string name1;
    char sex;
    float score;
};

class Graduate :public Teacher, public Student
{
public:
    Graduate(string nam, int a, char s, string t, float sco, float w) :

        Teacher(nam, a, t), Student(nam, s, sco), wage(w) { }
    void show()
    {
        cout << " name:" << name1 << endl;
        cout << " age:" << age << endl;
        cout << " sex:" << sex << endl;
        cout << " score:" << score << endl;
        cout << " title:" << title << endl;
        cout << " wages:" << wage << endl;
    }

private:
    float wage;
};
int main()
{
    Graduate gradl("Wang_li", 24, 'f', "asistant", 89.5, 1200);
    gradl.show();
    return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/928900.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号