📄 element.h
字号:
#include <math.h>
double const PI=3.14159;
class CElement {
public:
virtual void Show()=0;
virtual double Area() = 0;
CElement *Next;
};
class CPoint:public CElement{
friend class CLine;
protected:
double x,y;
public:
CPoint(){x = 0; y = 0; }
CPoint(double xv,double yv){x = xv;y = yv;}
double Area(){return 0;}
void Show(){
cout<<"x="<<x<<' '<<"y="<<y<<endl;
}
};
class CCircle :public CPoint{
double radius;
public:
CCircle(){ x = 0; y = 0; radius = 0; }
CCircle(double xv,double yv,double vv):CPoint(xv,yv){
radius = vv;
}
double Area(){
return PI*radius*radius;
}
void Show(){
cout<<"x="<<x<<' '<<"y="<<y<<' '<<"radius="<<radius<<' '<<"Area="<<Area()<<endl;
}
};
class CLine:public CElement{
CPoint start,end;
public:
CLine():start(0,0),end(0,0){}
CLine(double xv1,double yv1,double xv2,double yv2):
start(xv1,yv1),end(xv2,yv2){ };
double GetLength(){
return sqrt((start.x-end.x)*(start.x-end.x)+(start.y-end.y)*(start.y-end.y));
}
double Area(){return 0;}
void Show(){
cout<<"start point:\n";
start.Show();
cout<<"end point:\n";
end.Show();
cout<<"Length="<<GetLength()<<endl;
}
};
class CElemList{
protected:
CElement *head; // 链表头指针定义为基类类型
public:
CElemList():head(NULL){}
~CElemList();
void Insert(CElement *); // 插入元素
int Delete(CElement *); // 删除元素
void Show(); // 显示所有元素
CElement* GetHead(){ return head; } // 取得链表头
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -