重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
哈喽,今天又是一起练手代码,表示时间的,他就是c++日历代码,有5中选择,我就是自己编然后发给在座的博客们的,这次也是一个尝试,接下来。
为秭归等地区用户提供了全套网页设计制作服务,及秭归网站建设行业解决方案。主营业务为网站设计、成都网站设计、秭归网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!源代码展示: (纯属猿创)
#include
#include
#include
using namespace std;
int o;
bool prime = 1;
bool prime1 = 1;
bool prime2 = 1;
struct {
int year;
int month;
int day;
}date;
int main()
{
void op1();
void op2();
void op3();
void op4();
void op5();
cout<< "1.显示某一年的全年日历\n";
cout<< "2.显示某年某月的月历\n";
cout<< "3.显示某年某月某日是星期几\n";
cout<< "4.显示某年某月某日是该年度的第几天\n";
cout<< "5.退出\n";
int z;
cout<< "请选择(0-4)"<< endl;
cin >>z;
switch (z)
{
case 1: op1();
break;
case 2: op2();
break;
case 3: op3();
break;
case 4: op4();
break;
case 5: op5();
break;
}
return 0;
}
void op4()
{
int days;
cout<< "输入年月日"<< endl;
cin >>date.year >>date.month >>date.day;
switch (date.month)
{
case 1:days = date.day;
break;
case 2:days = date.day + 31;
break;
case 3:days = date.day + 59;
break;
case 4:days = date.day + 90;
break;
case 5:days = date.day + 120;
break;
case 6:days = date.day + 151;
break;
case 7:days = date.day + 181;
break;
case 8:days =date.day + 212;
break;
case 9:days = date.day + 243;
break;
case 10:days = date.day + 273;
break;
case 11:days = date.day + 304;
break;
case 12:days = date.day + 334;
break;
}
cout<< date.year<< "年"<< date.month<< "月"<< date.day<< "日是本年度的第"<< days<< "天"<< endl;
}
void op3()
{
int xq, d1;
if (prime)
{
cout<< "输入年份"<< endl;
cin >>date.year;
cout<< "输入本月份"<< endl;
cin >>date.month;
cout<< "输入日份"<< endl;
cin >>date.day;
}
else if (prime1)
{
cout<< "输入年份"<< endl;
cin >>date.year;
cout<< "输入本月份"<< endl;
cin >>date.month;
date.day = 1;
}
else if (prime2)
{
cout<< "输入年份"<< endl;
cin >>date.year;
}
d1 = (date.year - 1) * 365 + (date.year - 1) / 4 - (date.year / 100) + (date.year / 400);//百度搜的公式
xq = d1 % 7 + 1;
switch (date.month)
{
case 1:date.day = date.day; break;
case 2:date.day = date.day + 31; break;
case 3:date.day = date.day + 59; break;
case 4:date.day = date.day + 90; break;
case 5:date.day = date.day + 120; break;
case 6:date.day = date.day + 151; break;
case 7:date.day = date.day + 181; break;
case 8:date.day = date.day + 212; break;
case 9:date.day = date.day + 243; break;
case 10:date.day = date.day + 273; break;
case 11:date.day = date.day + 304; break;
case 12:date.day = date.day + 334; break;
}
if (((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0) && date.month >= 3)//判断闰年
date.day += 1;
xq = (xq + (date.day - 1)) % 7;
if (xq == 0) xq = 7;
if (prime)
switch (xq)
{
case 1:cout<< "该天是星期一"<< endl; break;
case 2:cout<< "该天是星期二"<< endl; break;
case 3:cout<< "该天是星期三"<< endl; break;
case 4:cout<< "该天是星期四"<< endl; break;
case 5:cout<< "该天是星期五"<< endl; break;
case 6:cout<< "该天是星期六"<< endl; break;
case 7:cout<< "该天是星期日"<< endl; break;
}
}
void op2()
{
prime = 0;
op3();
int i, s;
int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int m = 0, b = 0;
if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0) a[2] = 29;
cout<< date.year<< "年"<< date.month<< "月"<< endl;
i = date.month;
cout<< "------------------------------------------"<< endl;
cout<< " 日 一 二 三 四 五 六"<< endl;
cout<< "------------------------------------------"<< endl;
if (o == 7) o = 0;
for (m = 0; m< o; m++) cout<< " ";
for (b = 1; b<= a[i]; b++)
{
cout<< setw(6)<< b;
if ((b + o) % 7 == 0) cout<< endl;
}
if (b< 33) cout<< endl;
for (m = 0; m< o; m++) cout<< " "<< endl;
prime = 0;
}
void op1()
{
prime1 = 0;
for (date.month = 1; date.month<= 12; date.month++)
{
op2();
prime2 = 0;
}
}
void op5()
{
cout<< "byebye\n";
}
‘随时随的看日历’(红眼),古德白。
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧