⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circle.cpp

📁 求圆心坐标和圆半径
💻 CPP
字号:
// Point.h文件 Point类的声明
#ifndef POINT_H
#define POINT_H
class Point 
{	int x, y;					//点的x和y坐标
public:
	void SetPoint( int, int );		// 设置坐标
	int GetX() { return x; }		// 取x坐标
	int GetY() { return y; }		// 取y坐标
	void Print();				//输出点的坐标
};
#endif
// Point.cpp文件 Point类的成员函数定义
#include <iostream>
using namespace std;
#include "point.h"
void Point::SetPoint( int a, int b )
{	x = a;
	y = b;
}
void Point::Print()
{	cout << '[' << x << ", " << y << ']';}
// Circle.h文件 Circle类的声明
#ifndef CIRCLE_H
#define CIRCLE_H
#include <iostream>
using namespace std;
#include "point.h"
class Circle
{	double Radius;
	Point Center;
public:
	void SetRadius(double);		//设置半径
	void SetCenter(Point);		//设置圆心坐标
	double GetRadius();		//取半径
	Point GetCenter();			//取圆心
	double Area();				//计算面积
	void Print();				//输出圆心坐标和半径
};
#endif
// Circle.cpp文件 Circle类的成员函数定义
#include <iostream>
using namespace std;
#include "circle.h"
void Circle::SetRadius(double r)
{
	Radius = ( r >= 0 ? r : 0 );
}
void Circle::SetCenter(Point p)
{
	Center = p;
}
Point Circle::GetCenter()
{
	return Center;
}
double Circle::GetRadius()
{
	return Radius;
}
double Circle::Area()
{
	return 3.14159 * Radius * Radius;
}
void Circle::Print()
{
	cout << "Center = ";
	Center.Print();
	cout << "; Radius = " << Radius << endl;
}
// Example9-8.cpp文件: Circle Demo
#include <iostream>
using namespace std;#include "point.h"
#include "circle.h"
int main()
{
	Point p,center;
	p.SetPoint(30,50);
	center.SetPoint(120,80);
	Circle c;
	c.SetCenter(center);
	c.SetRadius(10.0);
	cout << "Point p: ";
	p.Print();
	cout << "\nCircle c: ";
	c.Print();
	cout << "The centre of circle c: ";
	c.GetCenter().Print();
	cout << "\nThe area of circle c: " << c.Area() << endl;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -