您的位置:首页 > 其它

第11周上机阅读程序

2013-05-10 10:28 113 查看
/*
* 程序的版权和版本声明部分
* Copyright (c) 2013, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:Complex.cpp
* 作 者: 李全港
* 完成日期:2013 年 5月 10日
* 版 本 号: V 1.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;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: