| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1082 人关注过本帖
标题:全年版万年历,请高手指教
取消只看楼主 加入收藏
tinx
Rank: 2
等 级:论坛游民
帖 子:24
专家分:29
注 册:2008-10-19
结帖率:0
收藏
 问题点数:0 回复次数:1 
全年版万年历,请高手指教
//全年版万年历源代码
#include <iostream.h>
#include <iomanip.h>
#include <windows.h>
#include <math.h>
int week (int y, int m, int d) //日期转换星期的函数,返回0是周一,1是周二,以此类推,6是周日   
{
    if (m==1||m==2)  y=y-1,m=m+12;
    return ((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7);
}
bool leap(int y) //判断是否闰年
{
    return ((y%4==0&&y%100!=0)||(y%400==0));
}
int Day (int year,int month) //计算某月天数
{
    int day;
    bool leap(int y);
    if (month==4||month==6||month==9||month==11) day=30;
    else
        if(month==2)
            if(leap(year)==1) day=29;
            else day=28;
        else day=31;
    return day;
}
void print( int y,int m,int d)  //输出控制函数
{
    int a,t;
    int week (int y, int m, int d);
    int Day (int year,int month);
    t=week(y,m,d);
    if(d<=Day(y,m))
    {
    if(d==1)
    {
        for(a=1;a<=3*t;a++) cout<<" ";
        cout<<setw(2)<<d<<" ";
    }
    else cout<<setw(2)<<d<<" ";
    if(t==6)
    {
        if(m%3==0) cout<<"*"<<endl;
        else cout<<"* ";
    }
    if(d==Day(y,m)&&t!=6)
    {
        for(a=1;a<=abs(t-6)*3;a++) cout<<" ";
        if (m%3==0) cout<<"*"<<endl;
        else cout<<"* ";
    }
    }
    else if(t==6) cout<<"                     * ";
}
void main()
{
    int year,month,i,j,k;
    char c;
    int week (int,int,int);
    void print(int,int,int);
        int Day (int,int);
        N:cout<<" 请输入年份:";
    cin>>year;
    if(year<0) goto N;
    system("cls");
    cout<<"                                公元"<<year<<"年                          "<<endl;
    cout<<endl<<"** ** ** ** ** ** ** * ** ** ** ** ** ** ** * ** ** ** ** ** ** ** *"<<endl;
    for(month=1;month<=12;month=month+3)
    {
        j=0;
        k=0;
        if(month<10) cout<<"         "<<month<<"月         *          "<<month+1<<"月         *          "<<month+2<<"月         *         "<<endl;
        else cout<<"         "<<month<<"月        *          "<<month+1<<"月        *          "<<month+2<<"月        *         "<<endl;
        cout<<"                     *                      *                      *"<<endl;
        cout<<"一 二 三 四 五 六 七 * 一 二 三 四 五 六 七 * 一 二 三 四 五 六 七 *"<<endl;
        for (i=1;i<=35;i++)
        {
            print(year,month,i);
            if(week(year,month,i)==6||i==Day(year,month))
            {
                j++;
                for (;j<=35;j++)
                {
                    print(year,month+1,j);
                    if(week(year,month+1,j)==6||j==Day(year,month+1))
                    {
                        k++;
                        for(;k<=35;k++)
                        {
                            print(year,month+2,k);
                            if(week(year,month+2,k)==6||k==Day(year,month+2)) break;
                        }
                        break;
                    }
                }
            }
        }
        cout<<endl<<"** ** ** ** ** ** ** * ** ** ** ** ** ** ** * ** ** ** ** ** ** ** *"<<endl;
    }
    while(1)
    {
        cout<<endl<< "重新输入(1)|退出(2):";
        cin>>c;
        if(c=='1') goto N;
        if(c=='2') break;
    }
}
效果截图
搜索更多相关主题的帖子: 万年历 指教 
2008-11-08 00:56
tinx
Rank: 2
等 级:论坛游民
帖 子:24
专家分:29
注 册:2008-10-19
收藏
得分:0 
坐着沙发等…
2008-11-10 08:42
快速回复:全年版万年历,请高手指教
数据加载中...
 
   



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

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