当前位置首页 > 生活休闲 > 其它生活相关文档
搜柄,搜必应! 快速导航 | 使用教程  [会员中心]

《C++面向对象程序设计答案》-第六章--谭浩强-清华大学出版社

文档格式:DOCX| 6 页|大小 10.35KB|积分 3|2022-09-16 发布|文档ID:152618188
第1页
下载文档到电脑,查找使用更方便 还剩页未读,继续阅读>>
1 / 6
此文档下载收益归作者所有 下载文档
  • 版权提示
  • 文本预览
  • 常见问题
  • 1://xt6-1/cpp#include //如用VC++应改为∶#include using namespace std; //如用VC++应取消此行#include "cylinder.h"#include "point.cpp"#include "circle.cpp"#include "cylinder.cpp"int main(){Cylinder cy1(3.5,6.4,5.2,10); cout<<"\noriginal cylinder:\nx="<using namespace std;class Point{public: Point(float a,float b):x(a),y(b){} ~Point(){cout<<"executing Point destructor"<using namespace std;class Point{public: Point(float a,float b):x(a),y(b){} ~Point(){cout<<"executing Point destructor"<using namespace std;class Point{public: Point(float a,float b):x(a),y(b){} virtual ~Point(){cout<<"executing Point destructor"<using namespace std;//定义抽象基类Shapeclass Shape{public: virtual double area() const =0; //纯虚函数};//定义Circle类class Circle:public Shape{public:Circle(double r):radius(r){} //结构函数 virtual double area() const {return 3.14159*radius*radius;}; //定义虚函数 protected: double radius; //半径};//定义Rectangle类class Rectangle:public Shape{public: Rectangle(double w,double h):width(w),height(h){} //结构函数 virtual double area() const {return width*height;} //定义虚函数 protected: double width,height; //宽与高};class Triangle:public Shape{public: Triangle(double w,double h):width(w),height(h){} //结构函数 virtual double area() const {return 0.5*width*height;} //定义虚函数 protected: double width,height; //宽与高};//输出面积的函数void printArea(const Shape &s){cout<点击阅读更多内容

    卖家[上传人]:细水长流999
    资质:实名认证