面向对象与面向过程思想比较

//以面向对象和面向过程两种思想来判断一个点是在圆内还是在圆外
#include<iostream>
using namespace std;


class Point
{
private:
int x0;
int y0;
public:
void setxy(int _x0, int _y0)
{
x0 = _x0;
y0 = _y0;
}
int getx()
{
return x0;
}
int gety()
{
return y0;
}


};


class Circle
{
public:
void setxyr(int _x1, int _y1, int _r)
{
x1 = _x1;
y1 = _y1;
r = _r;
}
void judge(int x0, int y0)
{
int a = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) - r*r;
if (a > 0)
{
cout << "it is out  of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
}
void judge(Point &p)
{
int a = (x1 - p.getx())*(x1 - p.getx()) + (y1 - p.gety())*(y1 - p.gety()) - r*r;
if (a > 0)
{
cout << "it is out  of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
}
private:
int x1;
int y1;
int r;




};
//面向过程
void main0()
{
int x0 = 1;
int y0 = 1;
int x1 = 2;
int y1 = 2;
int r = 3;
int a = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) - r*r;


if (a > 0)
{
cout << "it is out  of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
system("pause");
}
//面向对象
void main()

{  
Point myp;
myp.setxy(1,1);
Circle c1;
c1.setxyr(2,2,3);
c1.judge(myp);

system("pause");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值