#include <iostream>
#include <cmath>
using namespace std;
const double PI=3.1415926535;
class Geometric_shape{//几何图形
public:
virtual double perimeter()=0; //周长
virtual double area()=0; //面积
virtual double volume()=0; //体积
virtual void Show(){};
};
class Circle :public Geometric_shape{//圆
double radius;
public:
Circle(){radius = 0; }
Circle(double vv){radius = vv;}
double perimeter(){return 2.0*PI*radius;} //周长
double area(){return PI*radius*radius;} //面积
double volume(){return 0;} //体积
void Show(){cout<<"radius="<<radius<<endl;}
};
class Rectangle:public Geometric_shape{//矩形
double width,length;
public:
Rectangle(){width=0; length=0;}//长宽
Rectangle(double wid,double len){
width = wid;
length= len;
}
Rectangle(Rectangle& rr){
width = rr.width;
length = rr.length;
}
double perimeter(){return 2.0*(width+length);} //周长
double area(){return width*length;} //面积
double volume(){return 0;} //体积
void Show(){cout<<"width="<<width<<'\t'<<"length="<<length<<endl;}
};
class Triangle:public Geometric_shape{//三角形
double a,b,c;
public:
Triangle(){a=0;b=0;c=0;}
Triangle(double v1,double v2,double v3){a = v1;b = v2;c = v3;}
double perimeter(){return a+b+c;} //周长
double area(){
double s=(a+b+c)/2.0;
return sqrt(s*(s-a)*(s-b)*(s-c));
} //面积
double volume(){return 0;} //体积
void Show(){cout<<"a="<<a<<'\t'<<"b="<<b<<'\t'<<"c="<<c<<endl;}
};
class Box:public Rectangle{//长方体
double height;
public:
Box(){height=0;}
Box(double wid,double len,double heg):Rectangle(wid,len){height=heg;}
double volume(){return area()*height;} //体积
};
class Cylinder:public Circle {//圆柱体
double height;
public:
Cylinder(){height=0;}
Cylinder(double vv,double heg):Circle(vv){height=heg;}
double volume(){return area()*height;} //体积
};
class Cone: public Circle {//圆锥
double height;
public:
Cone(){height=0;}
Cone(double vv,double heg):Circle(vv){height=heg;}
double volume(){return area()*height/3;} //体积
};
class T_pyramid:public Triangle{//三棱锥
double height;
public:
T_pyramid(){height=0;}
T_pyramid(double v1,double v2,double v3,double heg):Triangle(v1,v2,v3){height=heg;}
double volume(){return area()*height/3;} //体积
};
class T_prism:public Triangle{//三棱柱
double height;
public:
T_prism(){height=0;}
T_prism(double v1,double v2,double v3,double heg):Triangle(v1,v2,v3){height=heg;}
double volume(){return area()*height;} //体积
};
int main(){
Geometric_shape * gs;
Circle cc1(10);
Rectangle rt1(6,8);
Triangle tg1(3,4,5);
Box bx1(6,8,3);
Cylinder cl1(10,3);
Cone cn1(10,3);
T_pyramid tpy1(3,4,5,3);
T_prism tpr1(3,4,5,3);
cc1.Show();//静态
cout<<"圆周长:"<<cc1.perimeter()<<'\t';
cout<<"圆面积:"<<cc1.area()<<'\t';
cout<<"圆体积:"<<cc1.volume()<<endl;
gs=&rt1;//动态
gs->Show();
cout<<"矩形周长:"<<gs->perimeter()<<'\t';
cout<<"矩形面积:"<<gs->area()<<'\t';
cout<<"矩形体积:"<<gs->volume()<<endl;
gs=&tg1;//动态
gs->Show();
cout<<"三角形周长:"<<gs->perimeter()<<'\t';
cout<<"三角形面积:"<<gs->area()<<'\t';
cout<<"三角形体积:"<<gs->volume()<<endl;
gs=&bx1;//动态
gs->Show();
cout<<"长方体底周长:"<<gs->perimeter()<<'\t';
cout<<"长方体底面积:"<<gs->area()<<'\t';
cout<<"长方体体积:"<<gs->volume()<<endl;
gs=&cl1;//动态
gs->Show();
cout<<"圆柱体底周长:"<<gs->perimeter()<<'\t';
cout<<"圆柱体底面积:"<<gs->area()<<'\t';
cout<<"圆柱体体积:"<<gs->volume()<<endl;
gs=&cn1;//动态
gs->Show();
cout<<"圆锥体底周长:"<<gs->perimeter()<<'\t';
cout<<"圆锥体底面积:"<<gs->area()<<'\t';
cout<<"圆锥体体积:"<<gs->volume()<<endl;
gs=&tpy1;//动态
gs->Show();
cout<<"三棱锥底周长:"<<gs->perimeter()<<'\t';
cout<<"三棱锥底面积:"<<gs->area()<<'\t';
cout<<"三棱锥体积:"<<gs->volume()<<endl;
gs=&tpr1;//动态
gs->Show();
cout<<"三棱柱底周长:"<<gs->perimeter()<<'\t';
cout<<"三棱柱底面积:"<<gs->area()<<'\t';
cout<<"三棱柱体积:"<<gs->volume()<<endl;
return 0;
}
钱亚锋
- 粉丝: 106
- 资源: 1万+
最新资源
- 基于Java和Vue的kopsoftKANBAN车间电子看板设计源码
- 影驰战将PS3111 东芝芯片TT18G23AIN开卡成功分享,图片里面画线的选项很重要
- 【C++初级程序设计·配套源码】第1期-语法基础
- 基于JavaScript、CSS、HTML的简易DOM版飞机游戏设计源码
- 基于Java开发的日程管理FlexTime应用设计源码
- SM2258XT-BGA144-4BGA180-6L-R1019 三星KLUCG4J1CB B0B1颗粒开盘工具 , EC, 3A, 94, 43, A4, CA 七彩虹SL300这个固件有用
- GJB 5236-2004 军用软件质量度量
- 30天开发操作系统 第 8 天 - 鼠标控制与切换32模式
- spice vd interface接口
- 安装Git时遇到找不到`/dev/null`的问题
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈