编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

在workhard兄弟基础上改编

在workhard兄弟基础上改编

#include<iostream.h>
#include<iomanip.h>
////////////////////////////////
//下面是函数
void print_month(int n);//////打印出第n月的图表
int calculate_n_days(int n);/////计算第n月的天数
int IsPrimer(int year);////判断是否是闰年
int TheFirstDay_of_theYear(int year);///计算这年中的第一天是星期几
///////////////////////////////////////////////////////
////下面是变量
int year;
int firstDay;
/////////////////////////////////////////////
int main(void)
{
int day;
cout<<"please input the year:";
cin>>year;
if(year<1)
{ cout<<"your input is wrong!"<<endl;
exit(0);
}
////
firstDay=TheFirstDay_of_theYear(year);
for(int i=1;i<13;i++)
{ cout<<"\n\n"<<setw(2)<<i<<"月      SUN      MON      TUE      WED      THU      FRI      SAT\n";
day=calculate_n_days(i);
print_month(day);
}
////
cout<<endl;
return 0;
}
///////////////////////////////////////////////
int IsPrimer(int year)
{
if((year%4==0&&year%100!=0)||(year%400==0))
  return 1;
else
  return 0;
}
//////////////////////////////////////////////////
int calculate_n_days(int n)
{
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:return(28+IsPrimer(year));
}
return 0;
}
/////////////////////////////////////////////////////
int TheFirstDay_of_theYear(int year)
{
long m;
m=(year-1)*365;
for(int i=1;i<year;i++)
  m+=IsPrimer(i);
return((m+1)%7);
}
////////////////////////////////////////////////////////
void print_month(int n)
{ cout<<"    ";
for(int i=0;i<firstDay;i++)
  cout<<"         ";
for(int j=1;j<=n;j++)
{ cout<<setw(9)<<j;
     if((j+firstDay)%7==0)
   cout<<"\n    ";
}
firstDay=(firstDay+n)%7;
}
/////////////////////////////////////////

TOP

发新话题