Advertisement
Leeen

class Data

Jun 11th, 2019
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. string exp1 = "";
  7. enum Months { Jan, Feb, March, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
  8. class Ddata {
  9. public:
  10.     Ddata *ptr;
  11.    
  12.     Ddata() {
  13.         day = 0;
  14.         month = 0;
  15.         year = 0;
  16.     }
  17.     Ddata(int Pday, Months Pmonth, int Pyear) {
  18.         /*checkData(Pday, Pmonth, Pyear);*/
  19.         day = Pday;
  20.         month = Pmonth;
  21.         year = Pyear;
  22.     }
  23.     ~Ddata() {
  24.        
  25.     } //деструктор
  26.     Ddata(const Ddata &dat) :day(dat.day), month(dat.month), year(dat.year) {} //конструктор копирования
  27.  
  28.     Ddata operator=(Ddata *d1) {
  29.         day = d1->day;
  30.         month = d1->month;
  31.         year = d1->year;
  32.         return *this;
  33.     }
  34.     bool operator>(Ddata d1) {
  35.         if (d1.day + d1.month + d1.year > day + month + year)
  36.             return true;
  37.         else return false;
  38.     }
  39.     Ddata operator*(int r) {
  40.         day = r*day;
  41.         return *this;
  42.     }
  43.     Ddata operator+(Ddata &d1) {
  44.         day = d1.day + day;
  45.         month = d1.month + month;
  46.         year = d1.year + year;
  47.         return *this;
  48.     }
  49.     Ddata &operator++() {
  50.         this->day++;
  51.         return *this;
  52.     }
  53.     Ddata operator++(int val) {
  54.         Ddata p(*this);
  55.         this->day++;
  56.         return p;
  57.     }
  58.    
  59.     friend std::ostream& operator<<(std::ostream& out, const Ddata &d1)
  60.     {
  61.         out << d1.day << "." << d1.month + 1 << "."<< d1.year;
  62.         return out;
  63.     }
  64.    
  65. private:
  66.     int day, month, year;
  67. };
  68. int main() {
  69.     int d = 11;
  70.     Months m = Jun;
  71.     int y = 2019;
  72.     Ddata mydata(d,m,y);
  73.     Ddata sss = mydata++;
  74.     cout << mydata << ' ' << sss;
  75.     if (sss > mydata) cout <<"ya";
  76.     system("pause");
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement