Created
May 15, 2017 20:06
-
-
Save marcin119a/8c396bc4d3fbf5f4685fa9d438ecf7f0 to your computer and use it in GitHub Desktop.
Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <assert.h> | |
| /** | |
| * struct Data | |
| */ | |
| struct Data { | |
| int rok_; | |
| int miesiac_; | |
| int dzien_; | |
| bool poprawna_data(int rok, int miesiac ,int dzien) | |
| { | |
| if(miesiac_ > 12 && miesiac < 1) { | |
| return false; | |
| } | |
| if(rok_ < 0) | |
| { | |
| return false; | |
| } | |
| if(dzien_ < 0 && dzien > 31) | |
| { | |
| return false; | |
| } | |
| } | |
| Data(int rok, int miesiac, int dzien): rok_(rok), miesiac_(miesiac), dzien_(dzien) { | |
| assert(poprawna_data(rok, miesiac, dzien)); | |
| } | |
| }; | |
| /** | |
| * | |
| * @param a | |
| * @param b | |
| * @return | |
| */ | |
| auto operator !=(Data a, Data b) -> bool { | |
| if(!(a.dzien_ == b.dzien_)) { | |
| return true; | |
| } | |
| if(!(a.miesiac_ == b.miesiac_)) { | |
| return true; | |
| } | |
| if(!(a.rok_== b.rok_)) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * | |
| * @param a | |
| * @param b | |
| * @return bool | |
| */ | |
| auto operator ==(Data a, Data b) -> bool { | |
| if((a.dzien_ == b.dzien_) && (a.miesiac_ == b.miesiac_) && (a.rok_ == b.rok_)) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| auto main(void) -> int { | |
| assert((Data(2014, 06, 9) == Data(2014, 6, 9))); | |
| assert(!(Data(2014, 06, 9) != Data(2014, 6, 9))); | |
| assert(!(Data(2000, 3, 2) == Data(2001, 3, 2))); | |
| assert((Data(2000, 3, 2) != Data(2001, 3, 2))); | |
| assert(!(Data(2001, 3, 2) == Data(2001, 2, 2))); | |
| assert((Data(2001, 3, 2) != Data(2001, 2, 2))); | |
| assert(!(Data(2001, 3, 2) == Data(2001, 3, 3))); | |
| assert((Data(2001, 3, 2) != Data(2001, 3, 3))); | |
| assert(!(Data(2345, 8, 30) == Data(2001, 3, 3))); | |
| assert((Data(2345, 8, 30) != Data(2001, 3, 3))); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment