屏蔽类在 C++ 中的内部实现

屏蔽类的内部实现

头文件:Point.h(公共接口)

class Point {
public:
  void Set(double x, double y);
  double GetX();
  double GetY();
  double GetAngle();
  double GetRadius();
protected:
  double x;
  double y;
};

源文件:Point.cpp

#include "Point.h"

void Point::Set(double x, double y) {
  this->x = x;
  this->y = y;
}

double Point::GetX() {
  return x;
}

double Point::GetY() {
  return y;
}

double Point::GetAngle() {
  // 计算极坐标角度
  return (180 / 3.14159) * atan2(y, x);
}

double Point::GetRadius() {
  // 计算极坐标半径
  return sqrt(x * x + y * y);
}
ppt 文件大小:2.25MB