》》》Step1:创建头文件和源文件
建议拿以下代码尝试分文件编写:
#include<iostream> using namespace std; class Point { public: int getx() { return m_x; } void setx(int x) { m_x = x; } int gety() { return m_y; } void sety(int y) { m_y = y; } private: int m_x; int m_y; }; class Circle { public: Point get_center() { return m_center; } void set_center(Point center) { m_center = center; } int get_r(){ return m_r; } void set_r(int x) { m_r = x; } private: int m_r; Point m_center; }; void ispic(Circle& c, Point a) { int R = c.get_r() * c.get_r(); int distance = (c.get_center().getx() - a.getx()) * (c.get_center().getx() - a.getx()) + (c.get_center().gety() - a.gety()) * (c.get_center().gety() - a.gety()); if (R > distance ){ cout << "点在圆内" << endl; }else { if (R = distance){ cout << "点在圆上" << endl; }else { cout << "点在圆外" << endl; }} } int main() { Point a; a.setx(2); a.sety(0); Circle c; Point c1; c1.setx(1); c1.sety(0); c.set_center(c1); c.set_r(1); //圆心:(1,0),半径:1 ;点:(2,0) ispic(c, a); system("pause"); return 0;
原笔记记录于Notion,这里由于格式原因,传图片方便.