⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p8_2.cpp

📁 相当丰富的C++源码
💻 CPP
字号:
/************************************
* p8_2.cpp                         *
* 从circle类派生出圆柱类(Cylinder) *
************************************/
#include"point2.h"
const double PI=3.14159;
class Circle :protected Point
{
protected:
	double radius;   //半径
public:
	Circle(double R, int X, int Y):Point(X,Y)
	{	
		radius=R;   
	}
	double area()   //求面积
	{
		return PI*radius*radius; 
    }
	void ShowCircle()
	{
       cout<<"Centre of circle:";
       ShowXY();
       cout<<"radius:"<<radius<<endl;
	}
};
class Cylinder: protected Circle
{
private:
	double height;
public:
    Cylinder(int X, int Y, double R, double H):Circle(R,X,Y)
	{  
		height=H;    
	}
	double area()
	{  
       return 2*Circle::area()+2*PI*radius*height;
	}
    double volume()
	{
	   return Circle::area()*height;
	}
	void ShowCylinder()
	{
         ShowCircle();
	     cout<<"height of cylinder:"<<height<<endl;
	}
};
void main() 
{
    Cylinder CY(100,200,10,50);
	CY.ShowCylinder();
	cout<<"total area:"<<CY.area()<<endl;
	cout<<"volume:"<<CY.volume();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -