万年历

/*
*Corpyright (c)2013,烟台大学计算机学院
*All right reseved.
*作者:高古尊
*完成日期:2013年11月4日
*版本号:v1.0
*输入描述:
*问题描述:万年历
*程序输出:
*问题分析:
*算法设计:
*/
#include <iostream>
using namespace std;
int main()
{
    char cha1,cha2,cha3,cha4,cha5,cha6;
    int num1;
    cout<<"欢迎使用玩年历查询系统\n";
    cout<<"请输入用户名:";
    cin>>cha1>>cha2>>cha3>>cha4>>cha5;
    cout<<endl;
    cout<<"请输入密码:";
    cin>>num1;
    cout<<endl;
    do
    {
        if(cha1=='a'&&cha2=='d'&&cha3=='m'&&cha4=='i'&&cha5=='n'&&num1==123)
        {

            int  year, month, days,days1,c,num5;
            cout << "请输入年、月: ";
            cin >> year >> month;
            switch(month)
            {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days1 = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days1 = 30;
                break;
            case 2:
                if((year%4==0 && year%100!=0 )||year%400==0)
                    days1 = 29;
                else
                    days1 =28;
            }
            if((year%4==0 && year%100!=0 )||year%400==0)
                days = 29;
            else
                days=28;
            switch(month)
            {

            case 1:
                num5=31;
                break;
            case 3:
                num5=31*2+days;
                break;
            case 5:
                num5=31*3+days+30;
                break;
            case 7:
                num5=31*4+days+30*2;
                break;
            case 8:
                num5=31*5+days+30*2;
                break;
            case 10:
                num5=31*6+days+30*3;
                break;
            case 12:
                num5=31*7+days+30*4;
                break;
            case 4:
                num5=30+days+31*2;
                break;
            case 6:
                num5=30*2+days+31*3;
                break;
            case 9:
                num5=31*5+days+30*3;
                break;
            case 11:
                num5=31*6+days+30*4;
                break;
            case 2:
                num5=31+days;
                break;
            }
            int n,m=0;
            for(n=1900;n<year;)
            {
               n++;

            if((n%4==0 && n%100!=0 )||n%400==0)
            {
                m++;
            }

            }

            int num2=m;
            //num3为天数
            int num3=num2*366+(year-1900-num2)*365+num5;
                 //**********
            cout<<"星期一    星期二    星期三    星期四    星期五    星期六    星期天\n";
            int num4=num3%7;
            int a=7-(days1-num4)%7;
            int b;
            if(a==7)
                for(b=0; b<days1;)
                {
                    b++;
                    if(b<10)
                    {           //********
                        cout<<b<<"         ";
                    }
                    else
                    {         //********
                      cout<<b<<"        ";
                    }

                    if(b%7==0)
                        cout<<endl;
                }
            else

            {
                for(c=0; c<a; c++)
                {        //**********
                    cout<<"          ";
                }
                for(b=0; b<days1;)
                {
                    b++;
                    if(b<10)
                    {           //********
                        cout<<b<<"         ";
                    }
                    else
                    {        //********
                     cout<<b<<"        ";
                    }

                    if((b+a)%7==0)
                        cout<<endl;
                }
            }
            cout<<endl;
        }
        else
        {
            cout<<"输入有误是/否(y/n)继续?\n";
            cin>>cha6;
        }
    }
    while(cha6!='y');
    return 0;

}

万年历_第1张图片

你可能感兴趣的:(万年历)