c++万年历小样一枚
程序编辑
#include<iostream.h>
#include<iomanip.h>
void fn0()
{
cout<<" ----------------------------"<<endl;
cout<<" * *"<<endl;
cout<<" 欢迎进入万年历查询系统 "<<endl;
cout<<" * *"<<endl;
cout<<" ----------------------------"<<endl<<endl<<endl;
cout<<" 请选择你要查询的内容"<<endl<<endl;
cout<<" 1.显示一年的日历"<<endl;
cout<<" 2.显示某一天是星期几"<<endl;
cout<<" 3.退出"<<endl;
cout<<"请选择按键<1-3>"<<endl;
}
//*****************************************************//
//*********************元旦的星期数********************//
int yuandan(int year)
{
int n = year-1900; //相差n年
n = n+(n-1)/4+1; //n年多n天,(n-1)/4个闰年数,再加 1900年元旦的星期序号1 因为7*52=364。
n = n%7;//每年多的一天+闰年数+1900年的星期 //序号
return n; //求出最后的星期数
}
//***********************//
//****当年每月的天数*********//
int monthday(int year,int month)
{
if(month==2)
{
if((year%4==0)&&(year%100!=0)||(year%400==0))
return 29;
else return 28;
}
else if(month==4||month==6||month==9||month==11)
return 30;
else
return 31;
}
//**********************************************************//
//*********************算年第几月第几天的天数//*******************//
int sum_day(int year, int month,int day) //算年第几月的天数;
{
int day_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=1;i<month;i++)
day+=day_month[i];
if((year%4==0)&&(year%100!=0)||(year%400==0))
if(month>2)
day+=1;
return day;
}
//*******************************************************//
//*********************输出一年的日历********************//
void fn1()
{
int year,k,n;
cout<<"请输入您要查询的年份"<<endl;
cin>>year;
n=yuandan(year);
for(k=1;k<=12;k++)
{
cout<<k<<"月"<<endl;
cout<<setw(6)<<"日"<<setw(6)<<"一"<<setw(6)<<"二"<<setw(6)
<<"三"<<setw(6)<<"四"<<setw(6)<<"五"<<setw(6)<<"六"<<endl;
cout<<setw(n*6)<<"";
for(int i=1;i<=monthday(year,k);i++)
{
cout<<setw(6)<<i<<setw(6);
if((i+n)%7==0)
cout<<endl;
}
n=(n+monthday(year,k)%7)%7;//每月进行累加。除余,算月一号星期数
cout<<endl;
}
}
//******************************************************//
//**********查询当天的星期数*******************
*********//
void fn2()
{
int year,month,date,sum,n;
char *s[]={ "星期日", "星期一","星期二","星期三","星
程序编辑
期四","星期五","星期六"};
cout<<"请输入你想查询的年份:";
cin>>year;
cout<<"输入月份(0~12) ";
cin>>month;
cout<<"输入此年当月日期 ";
cin>>date;
while(date>monthday(year,month))
{
cout<<"您输入有误,请重新输入该月日期 ";
cin>>date;
}
sum=yuandan(year)+sum_day(year,month,date)-1;
n=sum%7;
cout<<s[n]<<endl;
}
void select()
{int number;
cin>>number;
if(number!=1&&number!=2&&number!=3)
{
cout<<"你输入的数字有误,请重新输入"<<endl;
fn0();select();}
else if(number==1)
fn1();
else if(number==2)
fn2();
else
cout<<"谢谢使用本程序"<<endl;
}
void main()
{
int t=4;
while(t
==4)
{
fn0();
select();
cout<<"重新查询请按4。";
cin>>t;
}
}
部分借用·········
- 基于PLC控制的航空电镀生产线自动输送
- 中考预测课内外文言文对比阅读2
- 2018-2023年中国商业智能(BI)产业市场
- 中国金融体制改革研究2011new
- 外窗淋水试验方案
- 精益生产(Lean Production)
- 学校安全事故处置和信息报送制度
- Chapter 5 Human Resources Management
- 【小学数学】人教版小学六年级上册数学
- 初中数学解题方法与技巧
- 山东省创伤中心建设与管理指导原则(试
- 函数与数列的极限的强化练习题答案
- 10分钟淋巴按摩消脂
- 网络应急演练预案
- 服装设计入门基础知识
- 初二数学分式计算题练习
- (人教新课标)高二数学必修5第二章 数列
- 最新自主创业项目
- 北京大学 无机化学课件 4第4章 配合物
- 贸易公司业务管理制度




