返回顶部

收藏

万年历查询系统C++

更多
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<iomanip>
#include<windows.h>
using namespace std;

char * week[]={"日","一","二","三","四","五","六"};
char *month[]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};

void Welcome()
{
    int i,j;
    cout<<"\\n\\n\\n\\n\\n";
    for(i=0;i<45;i++)
        cout<<" ";
    Sleep(300);
    for(i=0;i<25;i++)
    {
        cout<<"欢 迎 使 用 万 年 历 查 询 系 统 !";
        Sleep(40-i);
        for(j=0;j<34;j++)
            cout<<"\\b";
        for(j=0;j<34;j++)
            cout<<" ";
        for(j=0;j<35;j++)
            cout<<"\\b";   
    }
    Sleep(10);
    for(i=0;i<2;i++)
    {
        cout<<"欢 迎 使 用 万 年 历 查 询 系 统 !";
        Sleep(i*10);
        for(j=0;j<34;j++)
            cout<<"\\b";
        for(j=0;j<34;j++)
            cout<<" ";
        for(j=0;j<33;j++)
            cout<<"\\b";
    }
    cout<<"欢 迎 使 用 万 年 历 查 询 系 统 !"<<endl;
    Sleep(100);
}

void End()
{
    int i,j;
    Sleep(300);
    for(i=0;i<28;i++)
    {
        cout<<"谢  谢  使  用  !";
        Sleep(28-i);
        for(j=0;j<17;j++)
            cout<<"\\b";
        for(j=0;j<17;j++)
            cout<<" ";
        for(j=0;j<16;j++)
            cout<<"\\b";   
    }
    Sleep(5);
    for(i=0;i<2;i++)
    {
        cout<<"谢  谢  使  用  !";
        Sleep(i*10);
        for(j=0;j<17;j++)
            cout<<"\\b";
        for(j=0;j<17;j++)
            cout<<" ";
        for(j=0;j<18;j++)
            cout<<"\\b";
    }
    cout<<"谢  谢  使  用  !"<<endl;
    Sleep(100);
}

void Close()
{
    int i;
    cout<<"该窗口将在 5 秒后自动关闭";
    for(i=0;i<13;i++)
        cout<<"\\b";
    for(i=4;i>=0;i--)
    {
        cout<<"\\b";
        Sleep(1000);
        cout<<i;
    }
    cout<<endl;
}    

int judge(int year,int mon)
{
     if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)
         return (31);  
     else if(mon==2)
     {
          if(year%4!=0||year%100==0&&year%400!=0)
          return (28);
       else return (29);
     }
     else return(30);
}

int day_week(int year,int mon)
{
    int a,b,m;
    a=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
    for(b=1;b<mon;b++)
    {
         m=judge(year,b);
        a=(a+m)%7;
    }
    return (a);
}

void end_round()
{
    cout<<"******************查询完毕******************\\n";
    system("pause");
    cout<<"\\n继续查询请按1,返回主菜单请按0:";
}

void menu()
{
    system("cls");
    cout<<"\\n            *******************主菜单*******************\\n";
    cout<<"\\n                   1.输入年月,显示月日历\\n";
    cout<<"\\n                   2.输入年份,显示年日历\\n";
    cout<<"\\n                   3.输入年、月、日,显示此日的星期数\\n";
    cout<<"\\n                   0.退出\\n";
}

void month_cal(int year,int mon)
{
    char ** p;
    int a,i,j,k,n;
    n=judge(year,mon);
    a=day_week(year,mon);
    for(i=0;i<7;i++)
    {
        p=week+i;
        cout<<setw(6)<<*p;
    }
    cout<<"\\n";
    for(j=0;j<a;j++)
    cout<<"      ";
    for(k=1;k<=n;k++)
    {
        cout<<setw(6)<<k;
        if((a+k)%7==0)
        cout<<"\\n";
    }
    cout<<"\\n";
}

void year_cal(int year)
{
    int i,j,a,n,m,k; 
    char ** p;  
    a=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
        for(i=0;i<12;i++)
    {
        n=judge(year,i+1);
        p=month+i;
        cout<<"\\n";
        for(j=0;j<18;j++)
            cout<<" ";
        cout<<*p<<endl;
        cout<<"\\n";

        for(j=0;j<7;j++)
        {
            p=week+j;
            cout<<setw(6)<<*p;
        }
        cout<<"\\n";

        for(k=0;k<a;k++)
            cout<<"      ";

        for(m=1;m<=n;m++)
        {
            cout<<setw(6)<<m;
            if((a+m)%7==0)
                cout<<"\\n";
        }
        a=(a+m-1)%7;
        cout<<"\\n";

        cout<<"============================================";
        cout<<"\\n";
    }
}

void week_day(int year,int mon,int day)
{
    int a,i;
    a=day_week(year,mon);
    i=(a+day)%7;
    cout<<"星期";
    switch(i)
    {
       case 1:cout<<"日\\n";break;
       case 2:cout<<"一\\n";break;
       case 3:cout<<"二\\n";break;
       case 4:cout<<"三\\n";break;
       case 5:cout<<"四\\n";break;
       case 6:cout<<"五\\n";break;
       case 0:cout<<"六\\n";break;
    }
}

void main()
{
    int ye,mo,da,sel,choose,flag=1;
    Welcome();
    system("pause");
    while(flag)
    {
        menu();
        cout<<"\\n请选择:";
        cin>>choose;
        switch(choose)
        {
            case 1:inx:cout<<"\\n请输入要查询的年月(×××× ××):";
            cin>>ye>>mo;
            if(mo<0||mo>12)
            {
                cout<<"\\n输入的月份有误,请重新操作!\\a\\n";
                system("pause");
                goto inx;
             }
            cout<<"\\n                  "<<ye<<"年"<<mo<<"月\\n";
            month_cal(ye,mo);
            end_round();
            inm:cin>>sel;
            if(sel==1)
                  goto inx;
            else if(sel)
            {
                cout<<"\\n错误!\\a\\n";
                cout<<"\\n继续查询请按1,返回主菜单请按0:";           
                    goto inm;
            }
            system("pause");
            break;
            case 2:iny:cout<<"\\n请输入要查询的年份(××××):";
            cin>>ye;
            cout<<"\\n                  "<<ye<<"年\\n";
            year_cal(ye);
            end_round();
            inn:cin>>sel;
            if(sel==1)
                    goto iny;
            else if(sel)
            {
                cout<<"\\n错误!\\a\\n";
                cout<<"\\n继续查询请按1,返回主菜单请按0:";
                    goto inn;
            }
            system("pause");
            break;
            case 3:inz:cout<<"\\n请输入要查询的年月日(×××× ×× ××):";
            cin>>ye>>mo>>da;
            if(mo<0||mo>12)
            {
                 cout<<"\\n输入的月份有误,请重新操作!\\a\\n";
                system("pause");
                goto inz;
            }

            else if(da<0||da>judge(ye,mo))
            {
               cout<<"\\n输入的天数有误,请重新操作!\\a\\n";
               system("pause");
               goto inz;
            }
            cout<<"\\n"<<ye<<"年"<<mo<<"月"<<da<<"日是";
            week_day(ye,mo,da);
            end_round();
            ink:cin>>sel;
            if(sel==1)
                  goto inz;
            else if(sel)
            {
                cout<<"\\n错误!\\a\\n";
                cout<<"\\n继续查询请按1,返回主菜单请按0:";
                  goto ink;
            }
            system("pause");
            break;
            case 0:flag=0;
            End();
            Close();
            break;
        default:cout<<"\\n错误的选择!请重选!\\a\\n";
        system("pause");
        system("pause");
        }
    }
}
//该片段来自于http://outofmemory.cn

标签:c++,基础

收藏

0人收藏

支持

0

反对

0