Lawlzes

Ch7_1.cpp

Oct 29th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include "date.h"
  5.  
  6. using namespace std;
  7. string Months[] = { "January", "February ", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  8.  
  9.  
  10. class Date // Default Class
  11.  
  12. {
  13.  
  14. private:
  15. int month;
  16. int day;
  17. int year;
  18. int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  19. public:
  20. Date(int m, int d, int y)
  21. {
  22. if (m < 1 || m > 12)
  23. month = 1;
  24. else
  25. month = m;
  26. if (d < 1 || d > DaysPerMonth[month - 1])
  27. day = 1;
  28. else
  29. day = d;
  30. if (y < 2001)
  31. year = 2001;
  32. else
  33. year = y;
  34. }
  35.  
  36. Date(){
  37. }
  38.  
  39. void printDate1() // Print the Date in 1st style
  40.  
  41. {
  42. cout << this->month << "/" << this->day << "/" << this->year << "\n"; // Display the date in m/d/y
  43. }
  44.  
  45. void printDate2() // Print the Date in 2nd style
  46.  
  47. {
  48. cout << Months[month - 1] << " " << day << ", " << year << endl; // Display the Date in m d, y
  49. }
  50.  
  51. void printDate3() // Print the Date in 3rd style
  52.  
  53. {
  54. cout << day << " " << Months[month - 1] << " " << year << endl; // Display the Date in d m y
  55. }
  56.  
  57. };
  58.  
  59. int main()
  60. {
  61. int tempMonth = 0;
  62. int tempDay = 0;
  63. int tempYear = 0;
  64. int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  65.  
  66. cout << "Hello! This Program will Give You a Certain Date in 3 Different Formats\n\n";
  67.  
  68. while (tempMonth < 1 || tempMonth > 12)
  69.  
  70. {
  71.  
  72. cout << "Month: \n\n";
  73. cin >> tempMonth;
  74. cout << endl;
  75.  
  76. }
  77.  
  78. while (tempDay > DaysPerMonth[tempMonth - 1] || tempDay < 1)
  79.  
  80. {
  81.  
  82. cout << "Day: \n\n";
  83. cin >> tempDay;
  84. cout << endl;
  85.  
  86. }
  87. while (tempYear < 1)
  88.  
  89. {
  90.  
  91. cout << "Year: \n\n";
  92. cin >> tempYear;
  93. cout << endl;
  94.  
  95. }
  96.  
  97. Date *d = new Date(tempMonth, tempDay, tempYear);
  98. d->printDate1();
  99. d->printDate2();
  100. d->printDate3();
  101.  
  102. system("Pause");
  103.  
  104.  
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment