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

2021-11-15

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

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!

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

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

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