vc0207.cpp

来自「VC面向对象的学习教程」· C++ 代码 · 共 63 行

CPP
63
字号
//example 2-7
#include <iostream.h>
#define YES 1
#define NO 0

int isleap(int year)
{
	int leap=NO;
	if(year%4==0&&year%100!=0||year%400==0)
		leap=YES;
	return leap;
}

int week_of_newyears_day(int year)
{
	int n=year-1900;
	n=n+(n-1)/4+1;
	n=n%7;
	return n;
}

void main()
{
	int year,month,day,weekday,len_of_month,i;
	cout<<"Please input year:";
	cin>>year;

	cout<<endl<<year<<endl;
	weekday=week_of_newyears_day(year);
	for(month=1;month<=12;month=month+1)
	{
		cout<<endl<<month<<endl;
		cout<<"---------------------------"<<endl;
		cout<<"SUN MON TUE WED THU FRI SET"<<endl;
		cout<<"---------------------------"<<endl;
		for(i=0;i<weekday;i=i+1)
			cout<<"    ";
		if(month==4||month==6||month==9||month==11)
			len_of_month=30;
		else if(month==2)
		{
			if(isleap(year))
				len_of_month=29;
			else 
				len_of_month=28;
		}
		else len_of_month=31;
		for(day=1;day<=len_of_month;day=day+1)
		{
			if(day>9)
				cout<<day<<"  ";
			else 
				cout<<day<<"   ";
			weekday=weekday+1;
			if(weekday==7)
			{
				weekday=0;
				cout<<endl;
			}
		}
		cout<<endl;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?