- UID
- 65325
注册时间2010-2-1
阅读权限20
最后登录1970-1-1
以武会友
TA的每日心情 | 郁闷 2017-1-19 11:18 |
---|
签到天数: 6 天 [LV.2]偶尔看看I
|
发表于 2010-12-4 21:35:04
|
显示全部楼层
本帖最后由 komany 于 2010-12-4 21:38 编辑
//sousce
- #include "Head.h"
- int main()
- {
- int month=0;
- Calendar a;
- long int year=0;
- system("cls");
- do
- {
- cout<<"\n\nPlease input one integer number as 'year'(0~3000):\n";
- cin>>year;
- if (year<0||year>3000) printf ("ERROR,please input again!");
- }
- while (year<0||year>3000);
- cout<<"\n\n";
- do
- {
- cout<<"please input the month(1~12)\n\n"<<endl;
- cin>>month;
- if (month<1||month>12) printf ("please input again!");
- }
- while (month<1|month>=12);
- //printf ("\n\n\n");
- cout<<endl;
- cout<<endl;
- cout<<endl;
- //printf("\t\t\t\t%ld\t%d\n\n",year,month);
- cout<<"\t"<<"\t"<<"\t"<<year<<"\t"<<"\t"<<month<<endl;
- cout<<"\n********************************************************************************\n"<<endl;
- cout<<"\t\t Sun\t Mon\t Tue\t Wen\t Thu\t Fri\t Sat"<<endl;
- a.Calendar::monthprint(year,month);
- printf("\n\n");
- return 0;
- }
复制代码- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
复制代码- #include "Headech.h"
- class Calendar
- {
- public:
- int leap_year(int y);
- int count_leap(long year);
- int monthdays(int month,long year);
- int monthprint(long year,int month);
- };
- int Calendar:: leap_year(int y)
- {
- return (y%4==0&&y%100!=0||y%400==0);
- }
- int Calendar:: count_leap(long year)
- {
- int i=0,j,min,max;
- if(year>2006) {min=2006;max=year;}
- else {min=year+1;max=2006;}
- for(j=min;j<max;j++)
- if(leap_year(j)) i++;
- return i;
- }
- int Calendar::monthdays(int month,long year)
- {
- int sum=0,i,j;
- if(year>=2006)
- { int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
- j=month-1;
- if(leap_year(year)) t[1]=29;
- else t[1]=28;
- for(i=0;i<j;i++)
- sum=sum+t[i];
- }
- else
- { int t1[12]={31,30,31,30,31,31,30,31,30,31,0,31};
- j=12-month;
- if(leap_year(year)) t1[10]=29;
- else t1[10]=28;
- for(i=0;i<=j;i++)
- sum=sum+t1[i];
- }
- return sum;
- }
- int Calendar::monthprint(long year,int month)
- {
- int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
- int i,y,weekday=0;
- long days=0;
- if(leap_year(year)) t[1]=29;
- else t[1]=28;
- y=t[month-1];
- if(year>2006)
- {
- days=(year-2006)*365+count_leap(year)+monthdays(month,year);
- weekday=days%7;
- }
- else if(year<2006)
- {
- days=(2005-year)*365+count_leap(year)+monthdays(month,year);
- weekday=7-days%7;
- }
- else
- {
- days=monthdays(month,year);weekday=days%7;
- }
- for (i=1;i<=weekday+2;i++)
- cout<<"\t";
- for (i=1;i<=y;i++)
- {
- if ((i+weekday-1)%7==0) printf ("\n\n\t\t%3d\t",i);
- else printf ("%3d\t",i);
- };
- cout<<"\n********************************************************************************\n\n"<<endl;
- return 0;
- }
复制代码 |
|