时间限制1s 内存限制128MB
题目描述:
设计一个点类Point,包含属性:x坐标和y坐标,方法:设定坐标(setPoint),获取x坐标(getX),获取y坐标(getY)
设计一个圆类Circle,包含属性:圆心坐标x和y、半径r;方法包括:
1. 设定圆心(setCenter),设置圆心x坐标和y坐标
2. 设定半径(setRadius),设置半径长度
3. 计算面积(getArea),计算公式:面积=3.14*r*r
4. 计算周长(getLength),计算公式:周长=2*3.14*r
5. 包含(contain),判断一个圆是否包含一个点,计算圆心到这个点的距离,然后和半径做比较,大于则不包含,小于等于则包含
注意:提交代码时必须用注释划分出三个区域:类定义、类实现、主函数,如下
//-----类定义------
class XXX
{
// 写类定义代码
};
//----类实现------
void XXX::process()
{
// 写类定义代码
};
//-----主函数-----
int main()
{
//自定义一些变量
//创建一个圆对象和一个点对象
//输入圆对象和点对象的属性数值,并做初始化
//输出圆的面积和圆的周长
//输出圆是否包含点,包含则输出yes,否则输出no
return 0;
}
输入:
第一行输入圆的三个整数参数:圆心的x和y坐标,半径
第二行输入点的两个整数参数:x和y坐标
输出:
第一行输出圆的面积和周长,结果之间用空格隔开,输出精度到小数点后2位
第二行输出圆是否包含点,包含则输出yes,否则输出no
输入样例:
1 1 1
2 2
输出样例:
3.14 6.28
no
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
class point {
float x;
float y;
public:
void setpoint();
float getx();
float gety();
};
void point::setpoint() {
cin >> x >> y;
}
float point::getx() {
return x;
}
float point::gety() {
return y;
}
class circle {
float ox;
float oy;
float r;
public:
void setcenter();
void setr();
float getarea();
float getlength();
void contain(point p);
};
void circle::setcenter() {
cin >> ox >> oy;
}
void circle::setr() {
cin >> r;
}
float circle::getarea() {
return 3.14 * r * r;
}
float circle::getlength() {
return 2 * 3.14 * r;
}
void circle::contain(point p) {
float x1 = p.getx();
float y1 = p.gety();
float distsnce = pow(((x1 - ox) * (x1 - ox) + (y1 - oy) * (y1 - oy)), 0.5);
if (distsnce <= r) {
cout << "yes" << endl;
}
else {
cout << "no" << endl;
}
}
int main()
{
point p;
circle c;
c.setcenter();
c.setr();
p.setpoint();
cout << fixed << setprecision(2) << c.getarea() << " ";
cout << fixed << setprecision(2) << c.getlength() << endl;
c.contain(p);
}