Guest User

Untitled

a guest
Apr 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. class Date {
  2. private:
  3. uint year, month, day;
  4. invariant() {
  5. assert(1 <= month && month <= 12);
  6. switch (day) {
  7. case 29:
  8. assert(month ! = 2 | | leapYear(year) );
  9. break;
  10. case 30:
  11. assert(month ! = 2);
  12. break;
  13. case 31:
  14. assert(longMonth(month) );
  15. break;
  16. default:
  17. assert(1 <= day && day <= 28);
  18. break;
  19. }
  20. // no restriction on year
  21. }
  22. // Helper functions
  23. static pure bool leapYear(uint y) {
  24. return (y % 4) == 0 && (y % 100 | | (y % 400) == 0);
  25. }
  26. static pure bool longMonth(uint m) {
  27. return ! (m & 1) == (m > 7);
  28. }
  29. public:
  30. . . .
  31. }
Add Comment
Please, Sign In to add comment