栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【C++】构建一个正方形类

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【C++】构建一个正方形类

#include
#include
using namespace std;
#define pi 3.14
class point {
	int x, y;
public:
	point() { cout << "point默认构造函数调用" << endl; }
	point(int xx, int yy):x(xx),y(yy) { cout << "point有参构造函数调用" << endl; }
	point(point& p);
	double distance(point& p);
	int getx() { return x; }
	int gety() { return y; }
};
point::point(point& p) {
	x = p.x;
	y = p.y;
	cout << "point复制构造函数调用" << endl;
}
//求两点间距离
double point::distance(point& p) {
	cout << "distance函数的调用" << endl;
	return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}

  


class circle {
public:
	circle() { cout << "circle默认构造函数调用"<= radius + c.radius) {
		cout << "两个圆不相交" << endl;
	}
	else
		cout << "两个圆相交" << endl;
}



int main() {
	point p1(2, 5), p2(3,6);
	circle c1(p1, 3), c2(p2, 3);
	int d_p1_p2 = p1.distance(p2);
	cout << "p1p2之间的距离:" << d_p1_p2 << endl;
	cout << "c1的面积:" << c1.area() <<"   c2的面积:"< 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/935697.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号