第十一周 阅读程序(3)
来源:互联网 发布:ip地址查域名 编辑:程序博客网 时间:2024/06/05 09:00
问题及代码:
/** Copyright (c) 2015, 烟台大学计算机学院* All rights reserved.* 文件名称:Project4.cpp* 作 者:吴胜男* 完成日期:2015年5月15日* 版 本 号:v1.0** 问题描述:请将class B:public A 中的public改为protected或者删除,对程序进行编译,解释出现的情况。* 输入描述:略* 程序输出:略*/#include<iostream>using namespace std;class A{private: int x;protected: int y;public: int z; A(int a,int b,int c) { x=a; y=b; z=c; } int Getx() { return x; } int Gety() { return y; } void ShowA() { cout<< "x="<<x<<'\t'; cout<<"y="<<y<<'\t'; cout<<"z="<<z<<'\n'; }};class B:public A //修改点(见后面阅读要求){private: int m,n;public: B(int a,int b,int c,int d,int e):A(a,b,c) { m=d; n=e; } void Show() { cout<<"m="<<m<<'\t'<<"n="<<n<<'\n'; cout<<"x="<<Getx()<<'\t'; cout<<"y="<<y<<'\t'<<"z="<<z<<'\n'; } int Sum() { return (Getx()+y+z+m+n); }};int main(){ B b1(1,2,3,4,5); b1.ShowA(); b1.Show(); cout<< "Sum="<<b1.Sum()<<'\n'; cout<<"x="<<b1.Getx()<<'\t'; cout << "y=" <<b1.Gety()<<'\t'; cout << "z="<<b1.z<<'\n'; return 0;}
运行结果:
0 0
- 第十一周阅读程序(3)
- 第十一周 阅读程序(3)
- 第十一周阅读程序(3)
- 第十一周 阅读程序(3)
- 第十一周 阅读程序 (3)
- 第十一周 阅读程序(3)
- 第十一周阅读程序(3)
- 第十一周阅读程序(3)
- 第十一周阅读程序3
- 第十一周阅读程序3
- 第十周第十一周项目1阅读程序(3)
- 第十一周 阅读程序
- 第十一周阅读程序
- 第十一周阅读程序
- 第十一周阅读程序
- 第十一周阅读程序
- 第十一周程序阅读
- 第十一周阅读程序
- svn Repositories 的导入导出操作
- 实现点击文本时checkbox选中
- Ubuntu 14.04下,安装arm-linux-gcc-4.3.2.tgz
- HashMap,TreeMap与LinkedHashMap的实例
- 【原创】sqlite3数据库“SQL error: database disk image is malformed”问题探究(2)
- 第十一周 阅读程序(3)
- Android 属性汇总
- 机器学习入门的书单(数据挖掘、模式识别等一样)
- 第11周-程序阅读4-多重继承
- Android技术积累:图片异步加载
- https://leetcode.com/problems/search-in-rotated-sorted-array/
- mac 无法连接CMCC_EDU
- Python图像处理(2):图像显示
- eclipse用ctrl + 鼠标左键点击后,回到原来的地方。