Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef DATE_H
- #define DATE_H
- #include <ctime>
- class Date : public tm
- {
- public:
- Date();
- int getYear();
- int getMonth();
- int getDay();
- int getHour();
- int getMin();
- int getSec();
- }; //Date
- #endif // DATE_H
- #include "Date.h"
- using namespace std;
- Date::Date()
- {
- time_t t;
- time(&t);
- tm local = *localtime(& t);
- tm_year = local.tm_year;
- tm_mday = local.tm_mday;
- tm_min = local.tm_min;
- tm_sec = local.tm_sec;
- tm_mon = local.tm_mon;
- tm_hour = local.tm_hour;
- }
- int Date::getYear() {
- return tm_year + 1900;
- }
- int Date::getMonth() {
- return tm_mon +1;
- }
- int Date::getDay() {
- return tm_mday;
- }
- int Date::getHour() {
- return tm_hour;
- }
- int Date::getSec() {
- return tm_sec;
- }
- int Date::getMin() {
- return tm_min;
- }
- #include <iostream>
- #include "Date.h"
- using namespace std;
- namespace {
- class Message {
- protected:
- string myContent;
- Date myDate;
- public:
- Message(const string & s){
- myContent = s;
- myDate = Date();
- }
- void displayContent(void){
- cout << "Message recu il y a " << myDate.getMin() << " et " << myDate.getSec() << " et le Message est : " << this->myContent;
- }
- Date getDate() {
- return myDate;
- }
- };
- void displayDate ( Date date)
- {
- cout << date.getDay () << ' ' << date.getMonth () << ' ' << date.getYear ();
- } // displayDate()
- void displayHour ( Date date)
- {
- cout << date.getHour () << "h " << date.getMin ()
- << "mn et " << endl;
- }
- void testMessage (void)
- {
- Message message ("salut");
- message.displayContent ();
- cout << " posté le : ";
- displayDate (message.getDate ());
- cout << " à ";
- displayHour (message.getDate ());
- cout << endl;
- } // testMessage()}
- }
- int main()
- {
- testMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement