Lawlzes

Date.cpp

Oct 29th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // Date.cpp is the Date class function implemetation file.
  2.  
  3. #include "Date.h"
  4.  
  5.  
  6. class Date // Default Class
  7.  
  8. {
  9.  
  10. private:
  11. int month;
  12. int day;
  13. int year;
  14. int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  15. public:
  16. Date(int m, int d, int y)
  17. {
  18. if (m < 1 || m > 12)
  19. month = 1;
  20. else
  21. month = m;
  22. if (d < 1 || d > DaysPerMonth[month - 1])
  23. day = 1;
  24. else
  25. day = d;
  26. if (y < 0)
  27. year = 2001;
  28. else
  29. year = y;
  30. }
  31.  
  32. Date(){
  33. }
  34.  
  35. void printDate1() // Print the Date in 1st style
  36.  
  37. {
  38. cout << this->month << "/" << this->day << "/" << this->year << "\n"; // Display the date in m/d/y
  39. }
  40.  
  41. void printDate2() // Print the Date in 2nd style
  42.  
  43. {
  44. cout << Months[month - 1] << " " << day << ", " << year << endl; // Display the Date in m d, y
  45. }
  46.  
  47. void printDate3() // Print the Date in 3rd style
  48.  
  49. {
  50. cout << day << " " << Months[month - 1] << " " << year << endl; // Display the Date in d m y
  51. }
  52.  
  53. };
Advertisement
Add Comment
Please, Sign In to add comment