标题:全年版万年历,请高手指教
只看楼主
tinx
Rank: 2
等 级:论坛游民
帖 子:24
专家分:29
注 册:2008-10-19
结帖率:0
 问题点数:0 回复次数:6 
全年版万年历,请高手指教
//全年版万年历源代码
#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
lionmusicyj
Rank: 1
等 级:新手上路
帖 子:98
专家分:0
注 册:2008-9-20
得分:0 
LZ干吗写这个程序啊?
2008-11-10 08:56
lionmusicyj
Rank: 1
等 级:新手上路
帖 子:98
专家分:0
注 册:2008-9-20
得分:0 
LZ说等着,是想干什么呢?
小弟看半天了,觉得没什么问题呀~!
2008-11-10 09:19
zxf12604
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-11-3
得分:0 
好东西。。。学习中
2008-11-10 09:27
zxf12604
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-11-3
得分:0 
好东西。。。学习中
2008-11-10 10:08
gyfabc
Rank: 1
等 级:新手上路
帖 子:16
专家分:5
注 册:2012-4-20
得分:0 
#include<iostream>
 using namespace std;
 #include<iomanip>
 int firstday(int year)   //计算当年第一天是星期几
 {
 double s;
 

int k=((year-1)+(year-1)/4-(year/100)+(year/400)+1);
 return (int)(k%7);
 
}
 





int monthday(int n,int year)     //计算一个月有多少天
 {
     if((n==1)||(n==3)||(n==5)||(n==7)||(n==8)||(n==10)||(n==12))
         return 31;
     if(n==2)
         {
         if((year%4==0&&year%100!=0)||(year%400==0))
             return 29;
 
           else
               return 28;
         }
 
    else
         return 30;
 


}
 
void main()
 {
 int i,year,f,m;
 cout<<"year:";
 cin>>year;
 cout<<endl;
 f=firstday(year);
 for(i=1;i<=12;i++)      //控制输出12个月
     {
       cout<<"         "<<i<<"月"<<endl;
 
cout<<" 日 "<<"一 "<<"二 "<<"三 "<<"四 "<<"五 "<<"六 "<<endl;
 for(int j=f;j>0;j--)
 cout<<"   ";
     m=monthday(i,year);
 for(int i=1;i<=m;i++)
 {
 cout<<" "<<setw(2)<<i;
 f=(f+1)%7;
 if(f==0)
    cout<<endl;
 }
 cout<<endl;
 }
 }
 
2012-04-22 19:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-243015-1-1.html




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

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