11-阅读程序1
来源:互联网 发布:淘宝客服培训视频 编辑:程序博客网 时间:2024/05/18 23:54
/* * Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 文件名称:11-阅读程序1* 作 者:孙红蕾* 完成日期:2013 年 5 月 10 日* 版 本 号:v1.0** 输入描述:无* 问题描述:阅读下面的程序,写出程序运行结果,上机时再运行,对比结果是否有* 差异,仔细领会继承,以及基类、派生类中构造函数的写法及执行过程* 程序输出:按要求输出* 算法设计:略*/#include <iostream>#include <string>using namespace std;//声明基类class Student {public: Student(int n,string nam) //基类构造函数 { num=n; name=nam; } void display() { cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; }protected: int num; string name;};//声明公用派生类class Student1:public Student{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(); cout<<"age:"<<age<<endl; cout<<"address:"<<addr<<endl<<endl; } void show_monitor() { cout<<endl; cout<<"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;}
运行结果:
- 11-阅读程序1
- 第11周项目 程序阅读(1)
- 第11周阅读程序(1)
- 第10、 11 周--阅读程序1
- 11-阅读程序2
- noip2012 阅读程序1
- 阅读程序1
- 阅读程序1
- 12程序阅读1
- 阅读程序1
- 阅读程序(1)
- 程序阅读1
- 阅读程序1、2
- 阅读程序补充-1
- 阅读程序1
- 阅读程序(1)
- 阅读程序1
- 阅读程序(1)
- EditPlus正则表达式替换字符串详解
- 离散函数 ural-1010
- 关于登录模块的编写(新手模块化编程)
- Cocos2d-x 设置竖屏的方法 2.0以上版本
- 关于Wubi安装增加容量以及移至真实分区的解决方法!
- 11-阅读程序1
- 第35天的交易(2013-5-8)(-100)(-487)
- 2013-5-10.1~阅读程序
- mac 下编译 yasm
- Android 工具之TraceView
- 11gR2 Grid Infrastructure Installation prerequisites On LINUX
- JAVA坏境变量中的JAVA_HOME path classpath 的设置与作用
- 第11周项目3-Cperson
- eclispse swing swt