学位的回报类型是什么 [英] What is the return type of a Degree

查看:70
本文介绍了学位的回报类型是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以度,分,秒,秒为单位的值的返回类型是什么?

What is the return type of a value that is in degrees minutes seconds format?

推荐答案

该函数声明的任何类型.如果这是您的功能,那么您必须知道类型是什么.如果是其他人,则查看定义.但是,从上面的评论来看,您正在寻找一个字符串.
Whatever type the function declares. If this is your function then you must know what the type is. If it is someone else''s then look at the definition. However, judging by your comment above you are looking for a string.


最好为这些值使用自己的数据类型.您可以使用具有以下定义的结构来简化对这些数据的操作.
It is better you use your own data types for these value. You can use a structure which has following definition for the ease of operation on these datas.
struct Coordinate
{
    int Degree;
    int Minute;
    float Seconds;
};
// function that returns Coordinate
Coordinate GetCoordinate()
{
    Coordinate CoordObj;
    CoordObj.Degree = 28;
    CoordObj.Minute = 36;
    CoordObj.Seconds = 40.5;
    return CoordObj;
}


我会说返回类型应该是Angle(或方位角,..).创建一个要使用的角度类.在内部,它可以使用浮点成员作为十进制值.然后添加一个字符串格式化成员函数,以在需要时获取所需的字符串.

优点:易于执行计算,并且可以降低混合单位(例如度和弧度)的风险.

如果有任何帮助,我会使用以下内容
I would say the return type should be an Angle (or Bearing, ..). Create a class Angle to use. Internally it can use a floating point member for the decimal value. Then add a string formating member function to get the desired string when needed.

Advantages: Easy to perform calculations, and you can reduce the risk of mixing units, such as degrees and radians.

I use the following if it helps you in any way
class angle
{
public:
	enum unit
	{
		rad = 0,
		deg = 1
	};
	angle() : r(0.) {}
	explicit angle(double a, unit u = rad) {
		if (u == rad) r = a; else r = a*M_PI/180;
	}
	angle(const angle& fi) : r(fi.r) {}
	double radians() const { return r; }
	double degrees() const { return r*180/M_PI; }

	// -pi <= a < pi
	void normalize() {
		while(r<-M_PI)r+=2*M_PI;while(r>=M_PI)r-=2*M_PI;
	}
	// 0 <= a < 2pi
	void normalize_positive() {
		while(r<0.)r+=2*M_PI;while(r>=2*M_PI)r-=2*M_PI;
	}

	angle& operator=  (const angle &fi) { if (&fi != this) r = fi.r; return *this; }
	angle& operator+= (const angle &fi) { r += fi.r; return *this; }
	angle& operator-= (const angle &fi) { r -= fi.r; return *this; }
	bool   operator== (const angle &fi) { return r == fi.r; }
	bool   operator>  (const angle &fi) { return r > fi.r; }
	bool   operator<  (const angle &fi) { return r < fi.r; }
	bool   operator>= (const angle &fi) { return r >= fi.r; }
	bool   operator<= (const angle &fi) { return r <= fi.r; }
	angle  operator-  () { return angle(-r); }
	angle  operator-  (const angle& fi) { return angle(r-fi.r); }
protected:
	double r;
};


您可以轻松地将格式化函数添加到此类,或者更好的是,创建一个在角度实例上执行此工作的格式化类.


You can easily add your formating functions to this class, or better yet, create a formating class that does the job on an angle instance.


这篇关于学位的回报类型是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆