daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef _MSC_VER
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #endif
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include <ctime>
  8. #include <conio.h>
  9.  
  10. using namespace std;
  11.  
  12. class Date
  13. {
  14. public:
  15.  
  16.     int year;
  17.     int month;
  18.     int day;
  19.     string komunikat;
  20.  
  21.     string zapiszWiadomosc(string text)
  22.     {
  23.         this->komunikat = text;
  24.         cout << "Podaj tresc przypomnienia" << endl;
  25.         getline(cin, komunikat);
  26.         return komunikat;
  27.     }
  28.  
  29.     void Wypisz()
  30.     {
  31.         cout << "Masz przypomnienie na dzien: " << day << "/" << month << "/" << year << endl;
  32.         cout << "Tresc przypomnienia: " << komunikat << endl;
  33.     }
  34.  
  35.     ///////////////////////////////////////////////// dodawanie dni ///////////////////////////////////////////////////////////
  36.     int dodajDzien(int added)
  37.     {
  38.         do
  39.         {
  40.             if (added < 1 || added > 31)
  41.             {
  42.                 cout << "Podano niewlasciwa liczbe. Podana liczba musi byc z zakresu od 1 do 31!" << endl;
  43.                 cin >> added;
  44.             }
  45.         } while (added < 1 || added>31);
  46.  
  47.  
  48.         time_t now = time(0);
  49.         tm *myTime = localtime(&now);
  50.         myTime->tm_year = year - 1900;
  51.         myTime->tm_mon = month - 1;
  52.         myTime->tm_mday = day + added;
  53.         mktime(myTime);
  54.  
  55.         year = (myTime->tm_year + 1900);
  56.         month = (myTime->tm_mon + 1);
  57.         day = myTime->tm_mday;
  58.  
  59.         return added;
  60.     }
  61.  
  62.     ////////////////////////////////////////////////////////konstruktory/////////////////////////////////////////////////////
  63.     Date()
  64.     {
  65.         time_t t = time(0);
  66.         tm* now = localtime(&t);
  67.         year = (now->tm_year + 1900);
  68.         month = (now->tm_mon + 1);
  69.         day = now->tm_mday;
  70.     }
  71.  
  72.     Date(int year, int month, int day)
  73.     {
  74.         this->year = year;
  75.         this->month = month;
  76.         this->day = day;
  77.     }
  78.  
  79.     Date(const Date &copy)      //konstruktor kopiujacy
  80.     {
  81.         year = copy.year;
  82.         month =  copy.month;     //kopiowanie zmiennych z podanego obiektu
  83.         day = copy.day;
  84.     }
  85.  
  86.     ~Date()
  87.     {
  88.         cout << "Reminder: " <<komunikat<< endl;
  89.         cout << "Object deleted" << endl;
  90.     }
  91.  
  92. };
  93.  
  94. int main()
  95. {
  96.  
  97.     Date *firstObject = new Date;
  98.     Date *secondObject = new Date(2019, 3, 11);
  99.    
  100.     firstObject->dodajDzien(15);
  101.     secondObject->dodajDzien(28);
  102.     firstObject->zapiszWiadomosc("");
  103.     secondObject->zapiszWiadomosc("");
  104.    
  105.     Date *thirdObject(secondObject);
  106.  
  107.     firstObject->Wypisz();
  108.     secondObject->Wypisz();
  109.     thirdObject->Wypisz();
  110.    
  111.     delete firstObject;
  112.     delete secondObject;
  113.  
  114.     return 0;
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top