龙空技术网

C|与日期有关的算法:闰年、干支年、星期

小智雅汇 392

前言:

此时各位老铁们对“c语言闰年判断条件”都比较讲究,小伙伴们都想要知道一些“c语言闰年判断条件”的相关内容。那么小编也在网上汇集了一些对于“c语言闰年判断条件””的相关内容,希望同学们能喜欢,看官们一起来了解一下吧!

1 对话框

2 对应的头文件

头文件.h提供声明信息,包括函数、类等的声明以及宏定义。

#include "stdafx.h"

#include "calc.h"

#include "math.h"

#include<string>

#include<iostream>

using namespace std;

3 对应的源文件

源文件提供实现信息使程序的逻辑结构更清晰,源文件包括头文件的引用以及相关函数或类方法的实现。

BOOL calc::OnInitDialog()

{

CDialog::OnInitDialog();

para3 = "32";

para2 = "56";

para1 = "24";

return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

void calc::OnButton7()

{

UpdateData(1);

int s;

int y;

int m;

int d;

intarr[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

int n = 0;

int week;

CString strtemp = "";

y = atoi(para1);

m = atoi(para2);

d = atoi(para3);

if(y % 4 == 0 && y%100!=0 || y%400==0)

arr[1]=29;

for( int i = 0; i < m-1; i = i + 1 )

{

n = n + arr[i];

}

n = n+d;

s = y -1 + int((y-1)/4) - int((y-1)/100) + int((y-1)/400) + n;

week = s % 7;

strtemp.Format("%d",week);

result ="公元" + para1 + "年" + para2 + "月" + para3 + "日是星期" + strtemp ;

UpdateData(0);

}

void calc::Onganzhi()

{

UpdateData(1);

string gan[10] = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};

string zhi[12] = {"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};

string animal[12] = {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};

int i;

int j;

i = atoi(para1);

j = atoi(para1);

if(i == 0)

{

para1 = "不能是0值,请重新输入!";

}

else

{

if(i > 0)

{

i = i%10;

if(i >= 4)

{

i = i - 4;

}

else

{

i = i -4 +10;

}

j = j%12;

if(j >= 4)

{

j = j - 4;

}

else

{

j = j -4 +12;

}

}

else//公元前的算法

{

i = atoi(para1);

i = abs(i);

i = i%10;

if(i <= 7)

{

i = 7 - i;

}

else

{

i = 7 - i +10;

}

j = atoi(para1);

j = abs(j);

j = j%12;

if(j <= 9)

{

j = 9 - j;

}

else

{

j = 9 - j +12;

}

}

CString strgz;

strgz = gan[i].c_str();

para2 = "公元" + para1 + "年是 " + strgz + zhi[j].c_str()+ " " + animal[j].c_str() + "年";

para3 = zhi[j].c_str() ;

para3 = para3 + ",对应的就是";

para3 = para3 + animal[j].c_str();

para3 = para3 + "年" ;

result = "公元后的第一个甲子年是公元4年。用十二种动物分别与十二地支相配成为“十二生肖年”。";

}

UpdateData(0);

}

-End-

标签: #c语言闰年判断条件