第4题
来源:互联网 发布:如何用图片在淘宝搜索 编辑:程序博客网 时间:2024/05/22 05:21
#include <iostream>using namespace std;class Shape{public: virtual double area() const =0; };class Circle:public Shape{public:Circle(double r):radius(r){} virtual double area() const {return 3.14159*radius*radius;}; protected: double radius; };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<<s.area()<<endl;} int main(){ Circle circle(10); cout<<"圆形的面积 ="; printArea(circle); Rectangle rectangle(4,8); cout<<"矩形的面积 ="; printArea(rectangle); Triangle triangle(4,7); cout<<"三角形的面积 ="; printArea(triangle); return 0;}
0 0
- 第4章 第4题
- 第2章第4题
- 第2章 第4题
- 第3章 第4题
- 第4章 第1题
- 第4章 第2题
- 第4章 第3题
- 第4章 第5题
- 第4章 第6题
- 第4章 第7题
- 第5章第4题
- 第7章第4题
- 第7章 第4题
- 第10章第4题
- p27第4题
- 第一章第4题
- 第4题作业
- P51 第4题
- android Graphics:canvas变换与操作
- 软件工程的基本概念
- char* str和char str[]的区别
- hdu1150 最小点覆盖集的一个小小的变形
- 快速排序算法
- 第4题
- 如何写系统分析书
- android&Bluetooth
- 20150525进制转换_Xcode
- 软件文档知多少?
- 队列实现 java版本
- 管家婆进销存7.2最完美的破解免安装版(已整合最新打印管理器)
- 设计模式之十五:组合模式(Composite)
- Java学习篇之---Gson(Maven)