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

📄 main.cpp

📁 this a good book.
💻 CPP
字号:
#include <iostream.h>
#include <math.h>

#define  PI    3.1415926

class CPoint {
public:
    int x,y;
	CPoint(int tx,int ty):x(tx),y(ty){}
};  

class CShape
{
public:
	CShape(){cout<<"构造CShape 类"<<endl;} 
	//**** 1 ****
	
	//**** 2 ****
	
protected:
};

class CCircle: public CShape
{
public:
	CCircle(CPoint i,double j):CShape(),center(i),r(j){
		cout<<"构造CCircle类"<<endl;
	}
	double Area()
	{
		return PI*r*r;
	}
	double Girth()
	{
		return 2*PI*r;
	}
private:
	CPoint center;
	double r;
};


class CRectangle: public CShape
{
public:
	CRectangle(CPoint lt,CPoint rb):leftTop(lt),rightBottom(rb),CShape(){
		cout<<"构造CRectangle类"<<endl;
	}
	double Area()
	{
		int width=abs(rightBottom.x-leftTop.x);
		int height=abs(rightBottom.y-leftTop.y);
		return width*height;
	}
	double Girth()
	{
		int width=abs(rightBottom.x-leftTop.x);
		int height=abs(rightBottom.y-leftTop.y);
		return 2*(width+height);
	}
private:
	CPoint leftTop,rightBottom;
};

void main()
{
	CShape *Shape=NULL;
	CCircle *Circle=new CCircle(CPoint(100,100),50);
	CRectangle *Rectangle = new CRectangle(CPoint(0,0),CPoint(100,100));
	
    //**** 3 ****
	
	cout<<"Circle:"<<"Area="<<Shape->Area()<<"\t"<<"Girth="<<Shape->Girth()<<endl;
	
	//**** 4 ****
	
	cout<<"Rectangle:"<<"Area="<<Shape->Area()<<"\t"<<"Girth="<<Shape->Girth()<<endl;
}

⌨️ 快捷键说明

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