#include<iostream>
using namespace std;
#include<string>
#pragma warning(disable : 6031)
class timetable
{
public:
void draw(int x,int y);
timetable() {};
private:
const char* years[12] = { "January 1","Feburary 2","March 3","April 4","May 5","June 6"
,"July 7","August 8","September 9","October 10","November 11","December 12"
};
int* days(int x);
const char* weeks [7] = {"sun","mon","tue","wed","thu","fri","sat"};
int suanweek(int y, int i);
};
int* timetable::days(int x)
{
if (x == 365)
{
static int arr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
return arr;
}
else
{
static int arr1[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
return arr1;
}
}
void timetable::draw(int x, int y)//这个x是算出的天数,y是年份
{
int* p = days(x);
int count = 0;
for (int i = 0;i < 12;i++)
{
for (int i = 0;i < 7;i++)
{
printf("%s", weeks[i]);
printf("%c", ' ');
}
printf("\n");
int m = suanweek(y, i);
if (m > 0)
{
while (m - 1)
{
printf("%c", ' ');
m--;
count++;
}
}
else
{
for (int i = 0;i < 6;i++)
{
printf("%c", ' ');
count++;
}
}
for (int j = 1;j <= *(p + i);j++)
{
if (count % 7 == 0)
{
printf("\n");
count = 0;
}
else
{
printf("%d", j);
printf("%c", ' ');
count++;
}
}
}
}
int timetable::suanweek(int y,int i)
{
int J, K=0;
int m[12] = { 13,14,3,4,5,6,7,8,9,10,11,12 };
int q =1 ;
if (i == 0 || i == 1)
{
J = (y-1)/ 100;
K = (y-1)% 100;
}
else
{
J = y / 100;
K = y % 100;
}
int h = (q + (13 * (m[i] + 1)/5) + K + (K / 4) + (J / 4) + 5 * J)%7;
return h;
}
int main()
{
int n = 0;
printf("请输入年份:");
scanf("%d", &n);
printf("\n");
timetable a;
if (n % 4 == 0 && n % 100 != 0)
{
a.draw(366, n);
}
else
{
a.draw(365, n);
}
return 0;
}
帮我修改一下
最新发布