"C + + Institute" (5) object-oriented programming exercises--H and CPP are written separately

Source: Internet
Author: User

Abstract a point, a circle, and determine the relationship between points and circles. (inside or outside the circle)


h file for the Declaration of class;

CPP file is the implementation details of the class, the main attention details are:


=============================================================================================================== ==================


The project code is as follows:

Mycircle.h#pragma once#include "MyPoint.h" Class Mycircle{public:void Setcir (Double x, double y, double R);p Ublic:char * Judge (double x, double y); char * judge (MyPoint &p);p rivate:double x1, y1; Center coordinate double R1;  Circle radius};

Mypoint.h#pragma onceclass mypoint{private:double x0, y0;//Point coordinates public:void setpoint (double x, double y);d ouble getX0 () ;d ouble getY0 ();};

Mycircle.cpp#include "MyCircle.h" void Mycircle::setcir (Double x, double y, double r) {x1 = x; y1 = y; r1 = r;} char* Mycircle::judge (double x, double y) {double s = (x1-x) * (x1-x) + (y1-y) * (y1-y)-r1*r1;if (S > 0) {return ' in Round out ";} Else{return "within the Circle";}} char* Mycircle::judge (MyPoint &p) {double s = (x1-p.getx0 ()) * (x1-p.getx0 ()) + (Y1-p.gety0 ()) * (Y1-p.gety0 ())-R 1*r1;if (S > 0) {return "Outside the Circle";} Else{return "within the Circle";}}

Mypoint.cpp#include "MyPoint.h" void Mypoint::setpoint (Double x, double y) {x0 = X;y0 = y;} Double mypoint::getx0 () {return x0;} Double Mypoint::gety0 () {return y0;}

Maintestclass.cpp#include "iostream" #include "MyCircle.h" #include "MyPoint.h" using namespace Std;void main () { Mycircle C1; MyPoint  P1;c1.setcir (2, 2, 3);p 1.setPoint (1, 1); cout << C1.judge (p1.getx0 (), P1.gety0 ()) << Endl;cout & lt;< C1.judge (p1) << endl;system ("pause");}




"C + + Institute" (5) object-oriented programming exercises--H and CPP are written separately

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.