Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _MSC_VER
- #define _CRT_SECURE_NO_WARNINGS
- #endif
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- class Date
- {
- public:
- int year;
- int month;
- int day;
- string komunikat;
- string zapiszWiadomosc(string text)
- {
- this->komunikat = text;
- cout << "Podaj tresc przypomnienia" << endl;
- getline(cin, komunikat);
- return komunikat;
- }
- void Wypisz()
- {
- cout << "Masz przypomnienie na dzien: " << day << "/" << month << "/" << year << endl;
- cout << "Tresc przypomnienia: " << komunikat << endl;
- }
- ///////////////////////////////////////////////// dodawanie dni ///////////////////////////////////////////////////////////
- int dodajDzien(int added)
- {
- do
- {
- if (added < 1 || added > 31)
- {
- cout << "Podano niewlasciwa liczbe. Podana liczba musi byc z zakresu od 1 do 31!" << endl;
- cin >> added;
- }
- } while (added < 1 || added>31);
- time_t now = time(0);
- tm *myTime = localtime(&now);
- myTime->tm_year = year - 1900;
- myTime->tm_mon = month - 1;
- myTime->tm_mday = day + added;
- mktime(myTime);
- year = (myTime->tm_year + 1900);
- month = (myTime->tm_mon + 1);
- day = myTime->tm_mday;
- return added;
- }
- ////////////////////////////////////////////////////////konstruktory/////////////////////////////////////////////////////
- Date()
- {
- time_t t = time(0);
- tm* now = localtime(&t);
- year = (now->tm_year + 1900);
- month = (now->tm_mon + 1);
- day = now->tm_mday;
- }
- Date(int year, int month, int day)
- {
- this->year = year;
- this->month = month;
- this->day = day;
- }
- Date(const Date ©) //konstruktor kopiujacy
- {
- year = copy.year;
- month = copy.month; //kopiowanie zmiennych z podanego obiektu
- day = copy.day;
- }
- ~Date()
- {
- cout << "Reminder: " <<komunikat<< endl;
- cout << "Object deleted" << endl;
- }
- };
- int main()
- {
- Date *firstObject = new Date;
- Date *secondObject = new Date(2019, 3, 11);
- firstObject->dodajDzien(15);
- secondObject->dodajDzien(28);
- firstObject->zapiszWiadomosc("");
- secondObject->zapiszWiadomosc("");
- Date *thirdObject(secondObject);
- firstObject->Wypisz();
- secondObject->Wypisz();
- thirdObject->Wypisz();
- delete firstObject;
- delete secondObject;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement