2013.5.22.1~阅读程序。。。

/* 
* 程序的版权和版本声明部分 
* Copyright (c)2013, 烟台大学计算机学院学生 
* All rightsreserved. 
* 作    者:王筱菀 
* 完成日期: 2013 年5月22 日 
* 版本号: v1.0 
* 输入描述: 
* 问题描述: 
* 输出: 
*/  
#include <iostream>
#include <string>
using namespace std;
class Student//声明基类
{
public:                                  //公用部分
    Student(int n, string nam)             //基类构造函数,与例.5相同
    {
        num=n;
        name=nam;
    }
    void display()                           //成员函数,输出基类数据成员
    {
        cout<<"num:"<<num<<endl<<"name:"<<name<<endl;
    }
protected:                               //保护部分
    int num;
    string name;
};

class Student1: public Student              //声明公用派生类Student1
{
public:
    Student1(int n,string nam,int n1,string nam1,int a,string ad):Student(n,nam),monitor(n1,nam1) //派生类构造函数
    {
        age=a;
        addr=ad;
    }
    void show()
    {
        cout<<"This student is:"<<endl;
        display();                               //输出num和name
        cout<<"age: "<<age<<endl;                //输出age
        cout<<"address: "<<addr<<endl<<endl;     //输出addr
    }

    void show_monitor( )                        //成员函数,输出子对象
    {
        cout<<endl<<"Class monitor is:"<<endl;
        monitor.display( );                       //调用基类成员函数
    }
private:                                      //派生类的私有数据
    Student monitor;                          //定义子对象(班长)
    int age;
    string addr;
};

int main( )
{
    Student1 stud1(10010,"Wang-li",10001,"Li-sun",19,"115 Beijing Road,Shanghai");
    stud1.show( );                       //输出学生的数据
    stud1.show_monitor();                //输出子对象的数据
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值