Lawlzes

Final Product

Oct 29th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #ifndef DATE_H // Date.h is the Date class specification file
  2. #define DATE_H
  3. #include <iostream>
  4. #include <string.h>
  5. #include <iomanip>
  6. #include <string>
  7. #include <cstdlib>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. //string Months[] = { "January", "February ", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  13.  
  14. // Class Date Declaration
  15.  
  16.  
  17. class Date
  18. {
  19.  
  20. public:
  21. Date(int m, int d, int y);
  22. void printDate1();
  23. void printDate2();
  24. void printDate3();
  25. int month;
  26. int day;
  27. int year;
  28. static int DaysPerMonth[12];
  29. static string Months[12];
  30.  
  31. };
  32.  
  33.  
  34. #endif
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. // Date.cpp is the Date class function implemetation file.
  52. #include "Date.h"
  53.  
  54. using namespace std;
  55.  
  56. int Date::DaysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  57. string Date::Months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  58.  
  59. Date::Date(int m, int d, int y)
  60. {
  61.  
  62.  
  63. if (m < 1 || m > 12)
  64. month = 1;
  65. else
  66. month = m;
  67. if (d < 1 || d > DaysPerMonth[month - 1])
  68. day = 1;
  69. else
  70. day = d;
  71. if (y < 0)
  72. year = 2001;
  73. else
  74. year = y;
  75. }
  76.  
  77.  
  78. void Date::printDate1()
  79. {
  80. cout << this->month << "/" << this->day << "/" << this->year << "\n";
  81. }
  82.  
  83. void Date::printDate2()
  84.  
  85. {
  86. cout << Months[month - 1] << " " << day << ", " << year << endl;
  87. }
  88.  
  89. void Date::printDate3() //
  90. {
  91. cout << day << " " << Months[month - 1] << " " << year << endl;
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. #include "Date.h"
  117. #include <stdio.h>
  118. using namespace std;
  119.  
  120.  
  121. int main()
  122. {
  123. int tempMonth = 0;
  124. int tempDay = 0;
  125. int tempYear = 0;
  126. int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  127.  
  128.  
  129. cout << "Hello! This Program will Give You a Certain Date in 3 Different Formats!\n\n";
  130.  
  131. while (tempMonth < 1 || tempMonth > 12)
  132.  
  133. {
  134.  
  135. cout << "Month: \n\n";
  136. cin >> tempMonth;
  137. cout << endl;
  138.  
  139. }
  140.  
  141. while (tempDay > DaysPerMonth[tempMonth - 1] || tempDay < 1)
  142.  
  143. {
  144.  
  145. cout << "Day: \n\n";
  146. cin >> tempDay;
  147. cout << endl;
  148.  
  149. }
  150. while (tempYear < 1)
  151.  
  152. {
  153.  
  154. cout << "Year: \n\n";
  155. cin >> tempYear;
  156. cout << endl;
  157.  
  158. }
  159. Date* d = new Date(tempMonth, tempDay, tempYear);
  160. d->printDate1();
  161. d->printDate2();
  162. d->printDate3();
  163.  
  164. system("Pause");
  165.  
  166.  
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment