开始学C++的第五天(我之前会一点C但只会一点点

 主体

#include <iostream>
#include <string>
#include "Circle.h"
#include "Point.h"
using namespace std;

void judge(Circle &c,Point &p )
{
	int distance =
		(c.getCenter().getX() - p.getX()) * (c.getCenter().getX() - p.getX()) +
		(c.getCenter().getY() - p.getY()) * (c.getCenter().getY() - p.getY());
	
	int rd = c.getR() * c.getR();
	if (rd < distance)
	{
		cout << "点在园外" << endl;
	}
	else if (rd > distance)
	{
		cout << "点在园内" << endl;
	}
	else
	{
		cout << "点在圆上" << endl;
	}
}
int main()
{
	Circle C;
	C.setR(10);
	Point Center;
	Center.setX(10);
	Center.setY(0);
	C.setCenter(Center);

	Point P;
	P.setX(10);
	P.setY(9);
	judge(C, P);
	system("pause");
	return 0;
};

Point副文件

#include "Point.h"

void Point::setX(int x)
{
	m_X = x;
}

int Point::getX()
{
	return m_X;
}

void Point::setY(int y)
{
	m_Y = y;
}

int Point::getY()
{
	return m_Y;
}

Circle副文件

#include "Point.h"
#include "Circle.h"


	void Circle::setR(int r)
	{
		m_R = r;
	}
	int Circle::getR()
	{
		return m_R;
	}
	void Circle::setCenter(Point center)
	{
		m_Center = center;
	}
	Point Circle::getCenter()
	{
		return m_Center;
	}

	int m_R;
	Point m_Center;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值