十进制度转换为度分秒
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
struct DMS
{
DMS(double value)
{
degrees = floor(value);
double rem = (value - degrees) * 60;
minutes = floor(rem);
seconds = (rem - minutes) * 60;
}
operator double() const
{
return degrees + minutes / 60 + seconds / 3600;
}
double degrees;
double minutes;
double seconds;
};
int main()
{
DMS dms = DMS(12.35);
cout << dms.degrees<< "°"<< dms.minutes <<"′" << dms.seconds<<"″"<<endl;
cout << double(dms) << endl;
return 0;
}