1 using System;
2 public class MyDate{
3 private int month,day,year;
4 public MyDate(int _month=1,int _day= 1,int _year=1900 ){
5 bool ok=true;
6 if(_month>12 || _month<1 || _year<0 || _day<0) ok=false;
7 if(_month<=7 &&( (_month%2==1 && _day>31) || (_month%2==< span style="color: #800080;">0 && _day>30))) ok=false;
8 if(_month>=8 &&( (_month%2==1 && _day>30) || (_month%2==< span style="color: #800080;">0 && _day>31))) ok=false;
9 if(_year%4==0 && _month==2 span> && _day>29) ok=false;
10 if(_year%4!=0 && _month==2 span> && _day>28) ok=false;
11 if(!ok){
12 Console.WriteLine("invalid date");
13 this.month=1;
14 this.day=1;
15 this.year=1900;
16 return;
17 }
18 this.month=_month;
19 this.day=_day;
20 this.year=_year;
21 }
22 public void SetDate(int _month,int _day,< span style="color: #0000ff;">int _year){
23 bool ok=true;
24 if(_month>12 || _month<1 || _year<0 || _day<0) ok=false;
25 if(_month<=7 &&( (_month%2==1 && _day>31) || (_month%2==< span style="color: #800080;">0 && _day>30))) ok=false;
26 if(_month>=8 &&( (_month%2==1 && _day>30) || (_month%2==< span style="color: #800080;">0 && _day>31))) ok=false;
27 if(_year%4==0 && _month==2 span> && _day>29) ok=false;
28 if(_year%4!=0 && _month==2 span> && _day>28) ok=false;
29 if(!ok){
30 Console.WriteLine("invalid date");
31 return;
32 }
33 this.month=_month;
34 this.day=_day;
35 this.year=_year;
36 }
37 public void Display(){
38 Console.WriteLine("{0}/{1}/{2}",month,day,year);
39 }
40 }
41 public class DateTest{
42 public static void Main(){
43 MyDate oneDate = new MyDate(2,29,1222 );
44 oneDate.Display();
45 oneDate.SetDate(2,29,2015);
46 oneDate.Display();
47 Console.WriteLine(oneDate);
48 }
49 }
1 using System;
2 public class MyDate{
3 private int month,day,year;
4 public MyDate(int _month=1,int _day= 1,int _year=1900 ){
5 bool ok=true;
6 if(_month>12 || _month<1 || _year<0 || _day<0) ok=false;
7 if(_month<=7 &&( (_month%2==1 && _day>31) || (_month%2==< span style="color: #800080;">0 && _day>30))) ok=false;
8 if(_month>=8 &&( (_month%2==1 && _day>30) || (_month%2==< span style="color: #800080;">0 && _day>31))) ok=false;
9 if(_year%4==0 && _month==2 span> && _day>29) ok=false;
10 if(_year%4!=0 && _month==2 span> && _day>28) ok=false;
11 if(!ok){
12 Console.WriteLine("invalid date");
13 this.month=1;
14 this.day=1;
15 this.year=1900;
16 return;
17 }
18 this.month=_month;
19 this.day=_day;
20 this.year=_year;
21 }
22 public void SetDate(int _month,int _day,< span style="color: #0000ff;">int _year){
23 bool ok=true;
24 if(_month>12 || _month<1 || _year<0 || _day<0) ok=false;
25 if(_month<=7 &&( (_month%2==1 && _day>31) || (_month%2==< span style="color: #800080;">0 && _day>30))) ok=false;
26 if(_month>=8 &&( (_month%2==1 && _day>30) || (_month%2==< span style="color: #800080;">0 && _day>31))) ok=false;
27 if(_year%4==0 && _month==2 span> && _day>29) ok=false;
28 if(_year%4!=0 && _month==2 span> && _day>28) ok=false;
29 if(!ok){
30 Console.WriteLine("invalid date");
31 return;
32 }
33 this.month=_month;
34 this.day=_day;
35 this.year=_year;
36 }
37 public void Display(){
38 Console.WriteLine("{0}/{1}/{2}",month,day,year);
39 }
40 }
41 public class DateTest{
42 public static void Main(){
43 MyDate oneDate = new MyDate(2,29,1222 );
44 oneDate.Display();
45 oneDate.SetDate(2,29,2015);
46 oneDate.Display();
47 Console.WriteLine(oneDate);
48 }
49 }