Advertisement
Guest User

jptypie

a guest
Nov 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <exception>
  3. using namespace std;
  4.  
  5. int def_day = 1;
  6. int def_month = 1;
  7. int def_year = 2018;
  8.  
  9. class simpleDate{
  10. private:
  11.     int day;
  12.     int month;
  13.     int year;
  14.  
  15. public:
  16.     //constructors
  17.     simpleDate();
  18.     explicit simpleDate(int);
  19.     simpleDate(int, int);
  20.     simpleDate(int, int, int);
  21.     simpleDate(const simpleDate& x); // copy constructor
  22.  
  23.     simpleDate& operator = (const simpleDate&);
  24.  
  25.     void addDays(int days);
  26.     void print();
  27. };
  28.  
  29.  
  30. simpleDate::simpleDate() : day(def_day), month(def_month), year(def_year){};
  31. simpleDate::simpleDate(int user_day) : month(def_month), year(def_year) {
  32.     if(user_day<1 || user_day >31){
  33.         cout<<"zly dzien lol"<<endl;
  34.     }
  35.     day=user_day;
  36.  
  37. }
  38. simpleDate::simpleDate(int user_day, int user_month) : year(def_year) {
  39.     if(user_day<1 || user_day >31){
  40.         cout<<"zly dzien lol"<<endl;
  41.     }
  42.     if(user_month<1 || user_month>12){
  43.         cout<<"zly miesiac lol"<<endl;
  44.     }
  45.     day=user_day;
  46.     month = user_month;
  47.  
  48. }
  49. simpleDate::simpleDate(int user_day, int user_month, int user_year){
  50.     if(user_day<1 || user_day >31){
  51.         cout<<"zly dzien lol"<<endl;
  52.     }
  53.     if(user_month<1 || user_month>12){
  54.         cout<<"zly miesiac lol"<<endl;
  55.     }
  56.     if(user_year <2018 || user_year>2020){
  57.         cout<<"zly rok lol"<<endl;
  58.     }
  59.  
  60.     day=user_day;
  61.     month=user_month;
  62.     year= user_year;
  63. };
  64.  
  65. simpleDate::simpleDate(const simpleDate& x){
  66.     day=x.day;
  67.     month=x.month;
  68.     year=x.year;
  69. };
  70.  
  71. simpleDate& simpleDate::operator=(const simpleDate& x) = default;
  72.  
  73. void simpleDate::addDays(int days) {
  74.     while(!days){
  75.         if(days > 365) {
  76.             year++;
  77.             days -= 365;
  78.         }
  79.         if(days < -365)
  80.         {
  81.             year++;
  82.             days +=365;
  83.         }
  84.     }
  85.     //tu sb sami napiszcie bo nudy xd
  86.  
  87. }
  88.  
  89. void simpleDate::print(){
  90.     cout<< year << '-' << month << '-'  << day << endl;
  91. }
  92.  
  93. int main(){
  94.  
  95.     simpleDate test(13,3);
  96.     simpleDate copy(test);
  97.     simpleDate kurrr = copy;
  98.     test.print();
  99.     copy.print();
  100.     kurrr.print();
  101.  
  102.  
  103.     return  0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement