| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 965 人关注过本帖
标题:在workhard兄弟基础上改编
只看楼主 加入收藏
ye9724069
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-12-21
收藏
 问题点数:0 回复次数:1 
在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;
}
/////////////////////////////////////////
搜索更多相关主题的帖子: workhard 兄弟 基础 改编 
2004-12-22 22:59
renyihehe
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2004-12-19
收藏
得分:0 

恩,挺好!如果在中间部分再来点注释就完美了!

赞一个!

2004-12-23 16:00
快速回复:在workhard兄弟基础上改编
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014668 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved