2021-11-15

2021-11-15,第1张

2021-11-15 Coordinate坐标

using namespace std;
class Coordinate {
public:
Coordinate()
{
times = 2;
cout << “Coordinate construction1 called!” << endl;

}
Coordinate(int times1)
{
	times = times1;
	cout << "Coordinate construction2 called!" << endl;
}
~Coordinate()
{
	cout << "Coordinate destruction called!" << endl;
}
void InputCood()
{
	for (int i = 0; i < times; i++)
	{
		cout << "Please Input x:" << endl;
		cin >> Coord[i][1];
		cout << "Please Input y:" << endl;
		cin >> Coord[i][2];
	}
}
void ShowCoord()
{
	cout << "The coord is:" << endl;
	for (int i = 0; i < times; i++)
	{
		cout << "(" << Coord[i][1] << "," << Coord[i][2] << ")" << endl;
	}
}
void ShowArgCoord()
{
	float avgx = 0;
	float avgy = 0;
	for (int i = 0; i < times; i++)
	{
		avgx = avgy + Coord[i][1];
		avgy = avgx + Coord[i][2];
	}
	avgx = avgx / times;
	avgy = avgy / times;
	cout << "The AVG coord is:" << endl;
	cout << "(" << avgx << "," << avgy << ")" << endl;
}

private:
float Coord[100][100];
int times;
};
int main()
{
Coordinate x;
x.InputCood();
x.ShowCoord();
x.ShowArgCoord();
return 0;
}
写入Coordinate y(5);
y.InputCood();
y.ShowCoord();
y.ShowArgCoord();
之前x语句可以输入两组x,y数据,产生两个坐标,输出的是Coordinate construction1 called!
单独执行y语句可以输入5组x,y数据,产生5个坐标,输出的是
Coordinate construction2 called!
一起执行先执行x语句,再执行y语句输出两次Coordinate destruction called!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5504360.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存