当前位置 - 股票行情交易網 - 文娛動態 - 求助c++題目,拜托大神

求助c++題目,拜托大神

#include<stdio.h>

#include<stdlib.h>

char* month_str[]={"壹月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十壹月","十二月"};

char* week[]={"星期日","星期壹","星期二","星期三","星期四","星期五","星期六"};

int runnian(int year) /*看看這是不是閏年*/

{

if((year%4==0&&year%100!=0)||(year%400==0)) //判斷是否是閏年的

return 1; //

else

return 0;//

}

int month_day(int year,int month) //這個函數用來判斷這年的月分有多少天的

{

int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};

if(runnian(year)&&month==2) /*判斷是判斷是否是閏年,是閏年而且這個月是2月那這個月有29天*/

return 29;

else

return(mon_day[month-1]);

}

int DS(int year,int month,int day) /*計算輸入的日期對應的星期,DS=DaySearch*/

{

int c=0;

float s;

int m;

for(m=1;m<month;m++)

c=c+month_day(year,m); //計算輸入的月分的累計天數

c=c+day; //計算日期在這壹年中是第幾天

s=year-1+(int)(year-1)/4+(int )(year-1)/100+(int)(year-1)/400-40+c;

return ((int)s%7);

}

int PAY(int year)/*這個函數是用來輸出全年的日歷,PAM=print all year*/

{

int temp;

int i,j;

for(i=1;i<=12;i++)

{

printf("\t\t\t%s的日歷\n",month_str[i-1],i); //輸出月分名稱

printf(" Sun\t Mon\t Tus\t Thr\t Wed\t Fri\t Sat\t\n\n");

temp=DS(year,i,1);

for(j=1;j<=month_day(year,i)+temp;j++)

{

if(j-temp<=0)

printf(" \t");

else if(j-temp<10)

printf("%2d\t",j-temp);

else

printf("%2d\t",j-temp);

if(j%7==0)

printf("\n");

}

printf("\n");

}

return 0;

}

int PM(int year,int month)//PM=print month//

{

int temp;

int i,j;

i=month;

printf("\n****************************************************\n");

printf("\t\t %d 年 %2d 月",year,month); //打印年月

printf("\n****************************************************\n");

printf(" 星期日 星期壹 星期二 星期三 星期四 星期五 星期六\n");

temp=DS(year,i,1);

for(j=1;j<=month_day(year,i)+temp;j++)

{

if(j-temp<=0)

printf(" \t");

else if(j-temp<10)

printf("%2d\t",j-temp);

else

printf("%2d\t",j-temp);

if(j%7==0)

printf("\n");

}

printf("\n");

return 0;

}

#define NY 2017

#define NM 6

#define ND 4 //把今天的日期定義為壹個常量

int DJT(int year,int month,int day) //計算某年某天是這年的第幾天

{

int i;

for(i=1;i<month;i++)

{

if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)

day+=31;

else if(i==2)

{

if(runnian(year)==1)

day+=29;

else

day+=28;

}

else

day+=30;

}

return(day);

}

void JL(int year,int month,int day) //分情況計算輸入的年月日與今天的天數

{

int x,y,z,i;

z=DJT(NY,NM,ND);

y=DJT(year,month,day);

if(year<NY)

{

for(i=year;i<NY;i++)//不同年用循環判斷中間年份的天數並加上

{

if(runnian(year)==1)

z+=366;

else

z+=365;

}

x=z-y;

}

else if(year>NY)

{

for(i=NY;i<year;i++)

{

if(runnian(year)==1)

y+=366;

else

y+=365;

}

x=y-z;

}

else

{

if(month<NM)//同年不同月將兩個日期在今年的天數相減

{

x=z-y;

}

else if(month>NM)

{

x=y-z;

}

else

{

if(day<ND)//同年同月直接將天數相減

x=ND-day;

else if(day>ND)

x=day-ND;

else

x=0;

}

}

printf("%d年%d月%d日距離今天還有%d天。\n",year,month,day,x);

}

void WEEK(int year,int month,int day) //判斷輸入日期是第幾周

{

int k;

k=DS(year,month,day);

switch(k)

{

case 0:printf("%d年%d月%d日是星期日。\n",year,month,day);break;

case 1:printf("%d年%d月%d日是星期壹。\n",year,month,day);break;

case 2:printf("%d年%d月%d日是星期二。\n",year,month,day);break;

case 3:printf("%d年%d月%d日是星期三。\n",year,month,day);break;

case 4:printf("%d年%d月%d日是星期四。\n",year,month,day);break;

case 5:printf("%d年%d月%d日是星期五。\n",year,month,day);break;

case 6:printf("%d年%d月%d日是星期六。\n",year,month,day);break;

}

}

int main()

{

int option,da;

char ch;

int year,month,day;

while(1)

{

printf("----------------- 請選擇功能: -------------------\n");

printf(" 1.顯示某年日歷 \n");

printf("-------------------------------------------------------------------------\n");

printf(" 2.顯示某年某月月歷 \n");

printf("-------------------------------------------------------------------------\n");

printf(" 3.計算距離今日天數,顯示今日為周幾 \n");

printf("-------------------------------------------------------------------------\n");

printf(" 4.退出 \n");

printf("請輸入您的選擇: ");

scanf("%d",&option);

switch(option) //用來選擇執行

{

case 1:

while(1)

{

printf("\n請輸入1930~2030任意年份:");

scanf("%d",&year);

PAY(year);

printf("\nContinue(Y/N)?");

fflush(stdin);

scanf("%c",&ch);

if(ch=='N'||ch=='n')

break;

}break;

case 2:

while(1)

{

printf("\n請輸入年份和月份(XXXX,XX):");

scanf("%d,%d",&year,&month);

PM(year,month);

printf("\nContinue(Y/N)?");

fflush(stdin);

scanf("%c",&ch);

if(ch=='N'||ch=='n')

break;

}break;

case 3:

while(1)

{

printf("\請輸入年,月,日(XXXX,XX,XX):");

scanf("%d,%d,%d",&year,&month,&day);

JL(year,month,day);

WEEK(year,month,day);

printf("\nContinue(Y/N)?");

fflush(stdin);

scanf("%c",&ch);

if(ch=='N'||ch=='n')

break;

}break;

case 4:

fflush(stdin);

printf("Exit?(Y/N)");

scanf("%c",&ch);

if(ch=='Y'||ch=='y')

exit(1);

break;

default:

printf("\n輸入錯誤,請輸入1到4之間的阿拉伯數字:\n");break;

}

}

return 0;

}