6-5
来源:互联网 发布:软件模块设计文档 编辑:程序博客网 时间:2024/06/04 17:59
#include <iostream.h>class Shape{public:virtual double area()const =0;};class Circle:public Shape{public:Circle(double r):radius(r){}virtual double area() const{ return 3.1415*radius*radius;}protected:double radius;};class Rectangle :public Shape{public:Rectangle(double l,double w):length(l),width(w){}virtual double area()const{ return length*width;}protected:double length;double width;};class Triangle:public Shape{public:Triangle(double d,double h):dibian(d),height(h){}virtual double area() const{ return 0.5*dibian*height;}protected:double dibian;double height;};class Square:public Shape{public:Square(double s):side(s){}virtual double area() const{ return side*side;}protected:double side;};class Trapezoid:public Shape{public:Trapezoid(double t,double b,double h):top(t),bottem(b),height(h){}virtual double area() const{ return 0.5*(top+bottem)*height;}protected:double top,bottem,height;};void display(const Shape &s){ cout<<s.area()<<endl;}int main(){ Circle c(4); Rectangle r(2,4); Triangle t(1,2); Square s(2); Trapezoid tt(1,2,3); Shape *p[5]={&c,&r,&t,&s,&tt}; double area=0.0; for(int i=0;i<5;i++) { area=area+p[i]->area(); } cout<<"the sum of area is "<<area<<endl; return 0;}
<img src="http://img.blog.csdn.net/20150616194739894?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaV8zdW1tZXI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
0 0
- 5 - 6
- 5-6
- 6-5
- 5-6
- 6-5
- 5-6
- 2,3,5,6,6,6
- 2005-5-6
- 2006-6-5
- 6+5=7
- 5月6日瞎想
- 2008-6-5
- //程序5-6 WhatSize
- 5月6号
- 2011-5-6
- 5,6、位运算
- apue chapter [5-6]
- course 5 6 knapsack
- 有用的代码片段2
- 一个基于jQuery的图片裁剪插件:Cropper
- leetcode[191]:Number of 1 Bits
- Radius Sever - Dynamic Vlan and Rate Limit Configuration
- 人口普查(20)
- 6-5
- 商品详情的图片选项展示
- Java如何对HashMap按值进行排序
- C 语言变长数组 struct 中 char data[0] 的用法
- QT stylesheet 操作
- Django开发问题总结
- EMC测试开发实习生面试记录
- leetcode--CountCompleteTreeNodes
- lvs(+keepalived)、haproxy(+heartbeat)、nginx 负载均衡的比较分析