入力した日付によって、曜日を返す、分かりやすいタイプ

1848 ワード

class Datetime{
public:
Datetime(int a,int b,int c):year(a),month(b),day(c){}
Datetime(int a):year(int(a/10000)),month(int(a%10000/100)),day(int(a%100)){}
void print(){cout<int year_yun();
int day_num();
int week_day();
public:
int year;
int month;
int day;
};
int Datetime::year_yun()
{
int sum=0;
for(int i=1900;isum+=(i%4==0&&i%100!=0||i%400==0)?1:0;
return sum;
}
int Datetime::day_num()
{
int temp;
int day_num=0;
int day_num_yun=year_yun()*366;
int day_num_fyun=(year-1900-year_yun())*365;
temp=(year%4==0&&year%100!=0||year%400==0)?1:0;
switch(month){
case 1:day_num=day;break;
case 2:day_num=31+day;break;
case 3:day_num=59+temp+day;break;
case 4:day_num=90+temp+day;break;
case 5:day_num=120+temp+day;break;
case 6:day_num=151+temp+day;break;
case 7:day_num=181+temp+day;break;
case 8:day_num=212+temp+day;break;
case 9:day_num=243+temp+day;break;
case 10:day_num=273+temp+day;break;
case 11:day_num=304+temp+day;break;
case 12:day_num=334+temp+day;break;
}
return day_num_fyun+day_num_yun+day_num;
}
int Datetime::week_day()
{
return day_num()%7?day_num()%7:7;
}
int main()
{
int a,b,c;
while(1){
cin>>a;
if(cin.get()=='')
{
Datetime t(a);
cout<<「今日の日曜日:」<}
else
{
cin>>b>>c;
Datetime t1(a,b,c);
cout<<「今日の日曜日:」<}
}
return 0;
}
*/
//日付によって曜日に戻る