所以我有一个任务,我应该用 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
第一个操作 m+d 需要一个玛雅日期和天数。该操作将天数添加到 Mayan 日期以生成 Mayan 日期作为输出。第二个操作 md 从玛雅日期中减去天数以生成玛雅日期作为输出。第三个操作 mm 计算两个玛雅日期之间的天数。第四个操作 g= 将公历日期转换为玛雅日期。最后的操作 m= 将玛雅日期转换为公历日期。
玛雅历法单位的设置方式如下:
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
我在初始化玛雅日历对象时遇到问题。这是我到目前为止所拥有的:
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;
};
我希望能够将单位设置为等于我初始化课程时它们所代表的天数,因此使用它们会更容易。
我上面的代码没有编译,我不知道为什么。任何指向我做错了什么的指针都会非常有帮助。