The class Date { Public: Date (int y, int m, int d) {year=y; The month=m; Day=d; All=0; Days=0; } int myday (); Private: int year, month, day, all the days; };
Int the Date: : myday () { Int all days; The switch (month) {case 1: all=0; break; Case 2: all=31; break; Case 3: all=59; break; Case 4: all=90; break; Case 5: all=120; break; Case 6: all=151; break; Case 7: all=181; break; Case 8: all=212; break; Case 9: all=243; break; Case 10: all=273; break; Case 11: all=304; break; Case 12: all=334; break; If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; }} The return days; } Int main () {int y, m, d; Cin> Y> M> d; The Date my (y, m, d); My myday (); cout}
CodePudding user response:
You switch of curly braces is wrong, in case12 break, namely the if leap year judgment to remove the switch of curly braces, The 12: all=334; break; If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; } } Change 12: all=334; break; } the if (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; }
In addition to write code as indentation, best or out of the problem is not good looking for you this is not trouble yourself