日历

#ifndef _rili_
#define _rili_
#include <iostream>
using namespace std;


class Calendar
{
private:
    int year;
    int month[12];
  
public:
    void setyear(int m_year);
    int getyear();
    void setmonth(int m_month[12]);
    int* getmonth();
   


};


void print_month();
int judge(int r_year);
void leapyear(int left);
void commonyear(int left);
void searchleapmonth(int left1, int r_month1);
void searchcommonmonth(int left1, int r_month2);





#endif


#include "head.h"


int main()
{
    long count = 1;


    int r_year;
    cin>>r_year;
    int m ;
for(m  = 1; m < r_year; m++)
{
if((m % 4 == 0 && m % 100 != 0) || m % 400 == 0)
{
count = (count + 366) % 7; 

}
else
{
count = (count + 365) % 7;
}

}
cout<<count<<endl;

    int ret = judge(r_year);
cout<<ret<<endl;
    if(ret == 1)
    {

       leapyear(count);
  cout<<"input month"<<endl;
  int r_month1;
  cin>>r_month1;
  searchleapmonth(count, r_month1);
  
    }


    if(ret == 0)
    {
        commonyear(count);
cout<<"input month"<<endl;
   int r_month2;
   cin>>r_month2;
searchcommonmonth(count, r_month2);
}






    return 0;
}




void Calendar :: setmonth(int m_month[12])
{
    int i = 0;
for(i = 0; i <12; i++)
{
month[i] = m_month[i];
}
}   


int* Calendar :: getmonth()
{
    return month;
}


void Calendar :: setyear(int m_year)
{
    year = m_year;
}   


int Calendar :: getyear()
{
    return year;
}


int judge(int r_year)
{
    if((r_year % 4 == 0 && r_year % 100 != 0) || (r_year % 400 == 0))
    {
        return 1;
    }
    else
    {
        return 0;
    }


}


void leapyear(int left)
{
   int a[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

Calendar cal;
        cal.setmonth(a);
        int* b;
b = cal.getmonth();
        int i, j,k;
int count1 = left;
int count2 = left;
for(i = 0; i < 12; i++)
{
   cout<<i+1<<"--- "<<"月"<<endl;
cout<<"SUN "<<"MON "<<"TUE "<<"WED "<<"THR "<<"FRI "<<"SAT"<<endl;
for(k = 0; k < count2; k++ )
{
cout<<"    ";

}
for(j = 1; j <= b[i]; j++)
   {
if(j > 0 && j < 10)
{
cout<<"  ";
}
else
{
cout<<" ";
}

cout<<j<<" ";
count1++;
count2++;
if(count1 % 7 == 0)
{
cout<<endl;
}
}
             if((count2 % 7) != 0)
             {  
   count2 = count2 % 7;
   count1 = count2;
   cout<<endl;
}
else
{
count1 = 0;
count2 = 0;
}
}
cout<<endl;
  
}


void commonyear(int left)
{
   int c[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Calendar cal;
        cal.setmonth(c);
        int* d;
d = cal.getmonth();

int i, j,k;
int count1 = left;
int count2 = left;
for(i = 0; i < 12; i++)
{
   cout<<i+1<<"--- "<<"月"<<endl;
cout<<"SUN "<<"MON "<<"TUE "<<"WED "<<"THR "<<"FRI "<<"SAT"<<endl;
for(k = 0; k < count2; k++ )
{
cout<<"    ";

}
for(j = 1; j <= d[i]; j++)
   {
if(j > 0 && j < 10)
{
cout<<"  ";
}
else
{
cout<<" ";
}

cout<<j<<" ";
count1++;
count2++;
if(count1 % 7 == 0)
{
cout<<endl;
}
}
             if((count2 % 7) != 0)
             {  
   count2 = count2 % 7;
   count1 = count2;
   cout<<endl;
}
else
{
count1 = 0;
count2 = 0;
}
}
cout<<endl;
}


void searchleapmonth(int left1, int r_month1)
{
   int a[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Calendar cal;
        cal.setmonth(a);
        int* b;
b = cal.getmonth();
cout<<"SUN "<<"MON "<<"TUE "<<"WED "<<"THR "<<"FRI "<<"SAT"<<endl;
   int i, k, j, count3 = 0;
int p = 0;
for(i = 0; i < r_month1 - 1; i++)
{
   p += b[i];

}

p += left1;
p = p % 7;

count3 = p;
for(k = 0; k < p; k++ )
{
   cout<<"    ";

}
for(j = 1; j <= b[r_month1-1]; j++)
   {
if(j > 0 && j < 10)
{
cout<<"  ";
}
else
{
cout<<" ";
}

cout<<j<<" ";
count3++;
if(count3 % 7 == 0)
{

cout<<endl;
}
   }
cout<<endl;

}


void searchcommonmonth(int left1, int r_month2)
{
   int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Calendar cal;
        cal.setmonth(a);
        int* b;
b = cal.getmonth();
cout<<"SUN "<<"MON "<<"TUE "<<"WED "<<"THR "<<"FRI "<<"SAT"<<endl;
   int i, k, j, count3 = 0;
int p = 0;
for(i = 0; i < r_month2 - 1; i++)
{
   p += b[i];

}

p += left1;
p = p % 7;

count3 = p;
for(k = 0; k < p; k++ )
{
   cout<<"    ";

}
for(j = 1; j <= b[r_month2-1]; j++)
   {
if(j > 0 && j < 10)
{
cout<<"  ";
}
else
{
cout<<" ";
}

cout<<j<<" ";
count3++;
if(count3 % 7 == 0)
{

cout<<endl;
}
   }
cout<<endl;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值