设计三个图形类:Point(点)、Circle(圆)、Triangle(三角形);c++
时间: 2023-06-12 12:05:08 浏览: 213
以下是三个图形类的示例代码:
```c++
class Point {
private:
int x, y;
public:
Point(int x, int y) {
this->x = x;
this->y = y;
}
int getX() const {
return x;
}
int getY() const {
return y;
}
void setX(int x) {
this->x = x;
}
void setY(int y) {
this->y = y;
}
};
class Circle {
private:
Point center;
int radius;
public:
Circle(Point center, int radius) {
this->center = center;
this->radius = radius;
}
Point getCenter() const {
return center;
}
int getRadius() const {
return radius;
}
void setCenter(Point center) {
this->center = center;
}
void setRadius(int radius) {
this->radius = radius;
}
};
class Triangle {
private:
Point a, b, c;
public:
Triangle(Point a, Point b, Point c) {
this->a = a;
this->b = b;
this->c = c;
}
Point getA() const {
return a;
}
Point getB() const {
return b;
}
Point getC() const {
return c;
}
void setA(Point a) {
this->a = a;
}
void setB(Point b) {
this->b = b;
}
void setC(Point c) {
this->c = c;
}
};
```
这里定义了三个类,Point 表示一个点,Circle 表示一个圆,Triangle 表示一个三角形。每个类中都有一些成员变量和成员函数,用于表示和操作该图形对象。需要注意的是,这里只是一个示例,实际应用中可能需要增加更多的功能。
阅读全文