Advertisement
acrogenesis

Fecha.h

Apr 17th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Fecha{
  6.     protected:
  7.         int dd;
  8.         int mm;
  9.         int aa;
  10.     public:
  11.         Fecha();
  12.         Fecha(int d, int m, int a);
  13.         int getdd();
  14.         int getmm();
  15.         int getaa();
  16.         void setdd(int d);
  17.         void setmm(int m);
  18.         void setaa(int a);
  19.         Fecha operator+(int d);
  20.         bool operator>=(Fecha f);
  21.         bool operator<=(Fecha f);
  22.         bool operator>(Fecha f);
  23.         bool operator<(Fecha f);
  24.         bool operator==(Fecha f);
  25. };
  26. Fecha::Fecha(){
  27.     dd = 1;
  28.     mm = 1;
  29.     aa = 2012;
  30. }
  31. Fecha::Fecha(int d, int m, int a){
  32.     dd = d;
  33.     mm = m;
  34.     aa = a;
  35. }
  36. int Fecha::getdd(){
  37.     return dd;
  38. }
  39. int Fecha::getmm(){
  40.     return mm;
  41. }
  42. int Fecha::getaa(){
  43.     return aa;
  44. }
  45. void Fecha::setdd(int d){
  46.     dd = d;
  47. }
  48. void Fecha::setmm(int m){
  49.     mm = m;
  50. }
  51. void Fecha::setaa(int a){
  52.     aa = a;
  53. }
  54. Fecha Fecha::operator +(int d){
  55.     Fecha temp;
  56.     temp.dd = dd + d;
  57.     temp.mm = mm;
  58.     temp.aa = aa;
  59.     if(temp.mm == 2){
  60.         if(temp.dd > 28){
  61.             temp.dd -= 28;
  62.             temp.mm++;
  63.         }
  64.     }else if(temp.mm == 12){
  65.         if(temp.dd > 31){
  66.             temp.dd -= 31;
  67.             temp.mm = 1;
  68.             temp.aa++;
  69.         }
  70.     }else if((temp.mm == 1) or (temp.mm == 3) or (temp.mm == 5) or (temp.mm == 7) or (temp.mm == 8) or (temp.mm == 10)){
  71.         if(temp.dd > 31){
  72.             temp.dd -= 31;
  73.             temp.mm++;
  74.         }
  75.     }else if((temp.mm == 4) or (temp.mm == 6) or (temp.mm == 9) or (temp.mm == 8) or (temp.mm == 11)){
  76.         if(temp.dd > 30){
  77.             temp.dd -= 30;
  78.             temp.mm++;
  79.         }
  80.     }
  81.    
  82.     return temp;
  83. }
  84. bool Fecha::operator>=(Fecha f){
  85.     Fecha temp;
  86.     temp.dd = dd;
  87.     temp.mm = mm;
  88.     temp.aa = aa;
  89.     if(temp.aa == f.aa){
  90.         if(temp.mm == f.mm){
  91.             if(temp.dd == f.dd){
  92.                 return (temp.dd == f.dd);
  93.             }else return (temp.dd > f.dd);
  94.         }else return (temp.mm > f.mm);
  95.     }else return (temp.aa > f.aa);
  96. }
  97. bool Fecha::operator<=(Fecha f){
  98.     Fecha temp;
  99.     temp.dd = dd;
  100.     temp.mm = mm;
  101.     temp.aa = aa;
  102.     if(temp.aa == f.aa){
  103.         if(temp.mm == f.mm){
  104.             if(temp.dd == f.dd){
  105.                 return (temp.dd == f.dd);
  106.             }else return (temp.dd < f.dd);
  107.         }else return (temp.mm < f.mm);
  108.     }else return (temp.aa < f.aa);
  109. }
  110. bool Fecha::operator<(Fecha f){
  111.     Fecha temp;
  112.     temp.dd = dd;
  113.     temp.mm = mm;
  114.     temp.aa = aa;
  115.     if(temp.aa == f.aa){
  116.         if(temp.mm == f.mm){
  117.             return (temp.dd < f.dd);
  118.         }else return (temp.mm < f.mm);
  119.     }else return (temp.aa < f.aa);
  120. }
  121. bool Fecha::operator>(Fecha f){
  122.     Fecha temp;
  123.     temp.dd = dd;
  124.     temp.mm = mm;
  125.     temp.aa = aa;
  126.     if(temp.aa == f.aa){
  127.         if(temp.mm == f.mm){
  128.             return (temp.dd > f.dd);
  129.         }else return (temp.mm > f.mm);
  130.     }else return (temp.aa > f.aa);
  131. }
  132. bool Fecha::operator ==(Fecha f){
  133.     Fecha temp;
  134.     temp.dd = dd;
  135.     temp.mm = mm;
  136.     temp.aa = aa;
  137.     return ((temp.dd == f.dd) & (temp.mm == f.mm) && (temp.aa == f.aa));
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement