#include <iostream.h> //1 class POINT { public:  OINT (double x=0,double y=0,double z=0); //构造函数  OINT (const POINT& other); //拷贝构造函数 void print(); //显示函数 POINT operator + (const POINT& other); //重载加法  OINT operator - (const POINT& other); //重载减法  OINT operator = (const POINT& other); //重载赋值 ~POINT (); //析构函数 protected: double the_x,the_y,the_z; }; POINT:OINT (double x,double y,double z) { the_x=x; the_y=y; the_z=z; return; } POINT:OINT (const POINT& other) { the_x=other.the_x; the_y=other.the_y; the_z=other.the_z; return; } void POINT::print () { cout<<'('<<the_x<<','<<the_y<<','<<the_z<<')'<<endl; } POINT POINT:perator + (const POINT& other) {  OINT temp; temp.the_x=the_x+other.the_x; temp.the_y=the_y+other.the_y; temp.the_z=the_z+other.the_z; return temp; } POINT POINT:perator - (const POINT& other) {  OINT temp; temp.the_x=the_x-other.the_x; temp.the_y=the_y-other.the_y; temp.the_z=the_z-other.the_z; return temp; } POINT POINT:perator = (const POINT& other) { this->the_x=other.the_x; this->the_y=other.the_y; this->the_z=other.the_z; return *this; } POINT::~POINT () {} //2 class SHAPE { public: void set_size (double x,double y=0) { x_size=x; y_size=y; } virtual double GetArea ()=0; virtual double GetPerim ()=0; protected: double x_size,y_size; }; class RECTOANLE:public SHAPE { public: virtual double GetArea () { return (x_size*y_size); } virtual double GetPerim () { return (2*x_size+2*y_size); } }; class CIRCLE:public SHAPE { public: virtual double GetArea () { return (3.14*x_size*x_size); } virtual double GetPerim () { return (2*3.14*x_size); } }; |