/*★ 誕生日の曜日 前田 稔 ★*/
using namespace System;
ref class KOYOMI
{ static String^ WTBL = "日月火水木金土";
static array<int>^ MTBL = { 0,31,59,90,120,151,181,212,243,273,304,334 };
int yy,mm,dd;
int Today,cnt,wek;
public:
// Constructor
KOYOMI()
{ //西暦1年1月1日から今日までの日数を調べる
yy= DateTime::Today.Year;
mm= DateTime::Today.Month;
dd= DateTime::Today.Day;
Today= Days();
}
// 生年月日を入力して曜日と通算日数を計算
bool GetDate()
{ String^ str;
array<String^>^ ymd;
array<String^>^ sep= {"/", ","};
Console::WriteLine("生年月日= YYYY/MM/DD を入力(Enter のみで終了)");
str = Console::ReadLine();
if (str==String::Empty) return false;
ymd= str->Split(sep, StringSplitOptions::None);
yy= int::Parse(ymd[0]);
mm= int::Parse(ymd[1]);
dd= int::Parse(ymd[2]);
cnt= Days();
wek= cnt%7;
cnt= Today-cnt+1;
return true;
}
// 生年月日と曜日と通算日数を印字
void Print()
{ Console::WriteLine("{0}年 {1}月 {2}日 ({3}曜日) 通算日数={4}",
yy, mm, dd, WTBL[wek], cnt);
}
// 西暦1年1月1日からの通算日数を調べる関数
int Days()
{ int w;
w= (yy-1)*365; //年*365
w+= (yy/4 - yy/100 + yy/400 + MTBL[mm-1] + dd);
if (mm<3 && Uruu(yy)) w--;
return(w);
}
// 閏年を調べる関数
bool Uruu(int year)
{ if (year%400L==0L) return(true);
if (year%100L==0L) return(false);
if (year%4L==0L) return(true);
return(false);
}
};
static int main()
{ KOYOMI^ koyomi = gcnew KOYOMI();
while(true)
{ if (koyomi->GetDate()==false) break;
koyomi->Print();
}
return 0;
}
|