第十一周项目实践1————点—圆类设计
2016-05-05 10:32
183 查看
问题及代码:
学习心得:
本次练习学会了派生类的构造函数和基类的调用
/*copyright(c)2016.烟台大学计算机学院 * All rights reserved, * 文件名称:text.Cpp * 作者:吴敬超 * 完成日期:2016年5月4日 * 版本号:codeblock * * 问题描述: 点-圆类设计 * 输入描述: * 程序输出: 输出结果 */ #include<iostream> using namespace std; class Point { public: Point(double x=0,double y=0); double getX() { return x; } double getY() { return y; } void setPoint(double,double); void show(); protected: double x; double y; }; Point::Point(double x,double y) { this->x=x; this->y=y; } void Point::setPoint(double x,double y) { this->x=x; this->y=y; } void Point::show() { cout<<"该点坐标为"<<x<<","<<y<<endl; } class Circle:public Point { public: Circle(double a=0,double b=0,double r=0); void setRadius(double); void show(); double getRadius( ) const { return rd; } double area()const; protected: double rd; }; Circle::Circle(double a,double b,double r):Point(a,b),rd(r){} void Circle::setRadius(double r) { rd=r; } double Circle::area()const { return 3.14*rd*rd; } void Circle::show() { cout<<"圆的面积为的"<<area()<<endl; } int main() { Circle c(3.5,6.4,5.2); c.show(); c.setPoint(5,5); c.show(); return 0; }运行结果:
学习心得:
本次练习学会了派生类的构造函数和基类的调用
相关文章推荐
- PHP配置文件详解php.ini
- 使用Docker容器的十大误区
- spring专业术语了解
- 【转】oracle authid current_user详解
- linux下vim命令
- 即时聊天工具大集合
- SQL中使用视图的优点和缺点是什么
- svn 命令行下常用的几个命令
- 使用jquery.form.js实现图片上传的方法
- 【转】理解CSS中BFC
- phpexcel的自动加载与其他框架有冲突
- Git使用手册
- 大数据技术之R
- 转载一下看看。很认可这篇文章
- svn学习
- ASP.NET IOS微信支付 完成 跳转
- 常用设计模式总结(转)
- 多目标优化的处理方案及非劣解集探究
- HDU1045 Fire Net(二分匹配)
- 存储过程的优缺点