gpt4 book ai didi

c++ - C++ 中的玛雅日历

转载 作者:太空狗 更新时间:2023-10-29 21:48:37 25 4
gpt4 key购买 nike

所以我有一个任务,我应该用 C++ 编写玛雅日历,使日历具有以下功能:

argv[1] | argv[2]        |  argv[3]        | output
m+d | Mayan date | number of days | Mayan date
m-d | Mayan date | number of days | Mayan date
m-m | Mayan date | Mayan date | number of days
g= | Gregorian date | | Mayan date
m= | Mayan date | | Gregorian date

The first operation m+d takes a Mayan date and a number of days. The operation adds the number of days to the Mayan date to produce a Mayan date as output. The second operation m-d subtracts the number of days from the Mayan date to produce a Mayan date as output. The third operation m-m calculates the number of days between two Mayan dates. The fourth operation g= converts a Gregorian date to a Mayan date. The final operation m= converts a Mayan date to a Gregorian date.

玛雅日历单位的设置方式是:

Days                  Long Count period         Long Count unit
1 1 Kin
20 20 Kin 1 Uinal
360 18 Uinal 1 Tun
7,200 20 Tun 1 Ka'tun
144,000 20 Ka'tun 1 Bak'tun
2,880,000 20 Bak'tun 1 Pictun
57,600,000 20 Pictun 1 Kalabtun
1,152,000,000 20 Kalabtun 1 K'inchiltun
23,040,000,000 20 K'inchiltun 1 Alautun

我在初始化 Mayan 日历对象时遇到问题。这是我目前所拥有的:

class MayanDate {
// Bak'tun, Ka'tun, etc stuff ...
unsigned int Kin = 1;
unsigned int Uinal = 20;
unsigned int Tun = 360;
unsigned int Katun = 7200;
unsigned int Baktun = 144000;
unsigned int Pictun = 2880000;
unsigned int Kalabtun = 57600000;
unsigned long Kinchiltun = 1152000000;
unsigned long Alautun = 23040000000;


public:

MayanDate();
MayanDate( unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);

void set( unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
MayanDate &operator++();
int operator-( const MayanDate &) const;
MayanDate operator+( unsigned int ) const;
MayanDate operator-( unsigned int) const;
bool operator==( const MayanDate & ) const;
bool operator!=(const MayanDate & m ) const;
void get_string( char*, unsigned int) const;
};

我希望能够在初始化类时将单位设置为它们代表的天数,这样使用它们会更容易。

我上面的代码没有编译,我不明白为什么。对我做错了什么的任何指示都会非常有帮助。

最佳答案

我认为您应该以玛雅风格在类里面保存数据。您必须能够将 Maya 纪元开始的日期转换为它,就像这样:

void toMayan(long long d)
{
kin = d % 20; d /= 20;
unial = d % 18; d /= 18;
tun = d %20; d /= 20;
//...
}

反向转换很简单:kin + 20 * (unial + 18 * (tun + 20 * (...)))

接下来,您应该知道如何计算公历中从某个日期到另一个日期的天数。例如,您可以查看 java 的 Date 类源 ( http://www.docjar.com/html/api/java/util/Date.java.html)。

最后 - 您必须知道公历形式的任何玛雅日期才能计算日历之间的天数差异。将一个日期转换为天数,减去(或添加)差异,然后转换为其他日期。

关于c++ - C++ 中的玛雅日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com