C++类嵌套类练习
#include<iostream> #include<string> using namespace std; class point { private: int x; int y; public: void setx(int x) { this->x=x; } int getx() { return x; } void sety(int y) { this->y=y; } int gety() { return y; } }; class circle { private: int r; point center; public: void setr(int r) { this->r=r; } int getr() { return r; } void setc(point center) { this->center=center; } point getc() { return center; } void judge(point &p) { if(((center.getx()-p.getx())*(center.getx()-p.getx()))+((center.gety()-p.gety())*(center.gety()-p.gety()))==r*r) { cout<<"在圆上"<<endl; } else if(((center.getx()-p.getx())*(center.getx()-p.getx()))+((center.gety()-p.gety())*(center.gety()-p.gety()))>r*r) { cout<<"在圆外"<<endl; } else { cout<<"在圆内"<<endl; } } }; int main() { point p1; p1.setx(0); p1.sety(0); circle c; c.setc(p1); c.setr(1); point p; p.setx(0); p.sety(1); c.judge(p); return 0; }