Advertisement
Guest User

Untitled

a guest
May 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #ifndef DATE_H
  2. #define DATE_H
  3. #include <ctime>
  4.  
  5.  
  6. class Date : public tm
  7. {
  8.  
  9. public:
  10. Date();
  11. int getYear();
  12. int getMonth();
  13. int getDay();
  14. int getHour();
  15. int getMin();
  16. int getSec();
  17. }; //Date
  18.  
  19. #endif // DATE_H
  20.  
  21. #include "Date.h"
  22.  
  23. using namespace std;
  24.  
  25. Date::Date()
  26. {
  27. time_t t;
  28. time(&t);
  29. tm local = *localtime(& t);
  30. tm_year = local.tm_year;
  31. tm_mday = local.tm_mday;
  32. tm_min = local.tm_min;
  33. tm_sec = local.tm_sec;
  34. tm_mon = local.tm_mon;
  35. tm_hour = local.tm_hour;
  36. }
  37.  
  38. int Date::getYear() {
  39.  
  40. return tm_year + 1900;
  41. }
  42.  
  43. int Date::getMonth() {
  44.  
  45. return tm_mon +1;
  46. }
  47.  
  48. int Date::getDay() {
  49.  
  50. return tm_mday;
  51. }
  52.  
  53. int Date::getHour() {
  54. return tm_hour;
  55. }
  56.  
  57. int Date::getSec() {
  58.  
  59. return tm_sec;
  60. }
  61.  
  62.  
  63. int Date::getMin() {
  64.  
  65. return tm_min;
  66. }
  67. #include <iostream>
  68. #include "Date.h"
  69. using namespace std;
  70.  
  71. namespace {
  72.  
  73.  
  74. class Message {
  75. protected:
  76. string myContent;
  77. Date myDate;
  78. public:
  79. Message(const string & s){
  80.  
  81. myContent = s;
  82. myDate = Date();
  83. }
  84. void displayContent(void){
  85. cout << "Message recu il y a " << myDate.getMin() << " et " << myDate.getSec() << " et le Message est : " << this->myContent;
  86. }
  87. Date getDate() {
  88. return myDate;
  89. }
  90.  
  91.  
  92. };
  93.  
  94.  
  95.  
  96. void displayDate ( Date date)
  97. {
  98. cout << date.getDay () << ' ' << date.getMonth () << ' ' << date.getYear ();
  99.  
  100. } // displayDate()
  101.  
  102. void displayHour ( Date date)
  103. {
  104. cout << date.getHour () << "h " << date.getMin ()
  105. << "mn et " << endl;
  106. }
  107. void testMessage (void)
  108. {
  109. Message message ("salut");
  110. message.displayContent ();
  111. cout << " posté le : ";
  112. displayDate (message.getDate ());
  113. cout << " à ";
  114. displayHour (message.getDate ());
  115. cout << endl;
  116.  
  117. } // testMessage()}
  118.  
  119. }
  120.  
  121. int main()
  122. {
  123. testMessage();
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement