第5题
来源:互联网 发布:vue.js if else 编辑:程序博客网 时间:2024/05/20 08:27
#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 Square:public Shape{public: Square(double s):side(s){} virtual double area() const {return side*side;} protected: double side;};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 Trapezoid:public Shape{public: Trapezoid(double t,double b,double h):top(t),bottom(t),height(h){} virtual double area() const {return 0.5*(top+bottom)*height;} protected: double top,bottom,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; };int main(){ Circle circle(12.6); Square square(3.5); Rectangle rectangle(4.5,8.4); Trapezoid trapezoid(2.0,4.5,3.2); Triangle triangle(4.5,8.4); Shape *pt[5]={&circle,&square,&rectangle,&trapezoid,&triangle}; double areas=0.0; for(int i=0;i<5;i++) {areas=areas+pt[i]->area();} cout<<"totol of all areas="<<areas<<endl; return 0;} <img src="http://img.blog.csdn.net/20150609201654679?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmluZzA1Mjg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
0 0
- 第2章第5题
- 第2章 第5题
- 第3章 第5题
- 第4章 第5题
- 第5章 第1题
- 第5章 第2题
- 第5章第1题
- 第5章 第3题
- 第5章第2题
- 第5章第3题
- 第5章 第9题
- 第5章 第10题
- 第5章第4题
- 第5章第9题
- 第5章第10题
- 第6章 第5题
- 第7章 第5题
- 第7章第5题
- netstat 的10个基本用法
- 线性表的顺序表示——顺序表
- Linux 内核调试之 printk
- Android窗口管理框架解析
- 最大子序列、最长递增子序列、最长公共子串、最长公共子序列、字符串编辑距离
- 第5题
- [leetcode] Basic Calculator
- 使用.net和jquery实现一对一的网页聊天系统
- 集合框架3+System+Runtime+Date+Math
- servlet 多选框 键值对 传action 实例
- 安装rlwrap for linux
- 百度之星 2015 复赛 1001 (数长方形)
- 小玩文件
- UITableViewCell点击时改变文本颜色