cls date

2
 1 #include <iostream>  2 #include<string.h>  3 #include "clsDate.h"  4 #include <ostream>  5 using namespace std ;  6 7 clsDate::clsDate(int a, int l, int z, char *nume)  8 {  9 _an=a; 10 _luna=l; 11 _zi=z; 12 numeZi[30]=*nume; 13 } 14 15 16 17 ostream& operator<<(ostream &c, clsDate &d) 18 { 19 c<<"\nData este: "<<d.  _zi<<"/"<<d.  _luna<<"/"<<d.  _an<<";"; 20 21 } 22 23 istream & operator>>(istream &c, clsDate &d) 24 { 25 cout<<"\nIntrodu ziua: " ;c>>d.  _zi; 26 cout<<"Introdu luna: " ;c>>d.  _luna; 27 cout<<"Introdu anul: " ;c>>d.  _an; 28 29 return c; 30 } 31 32 33 clsDate& clsDate::operator+(int nrzile) 34 { 35 if((  _zi+=nrzile)>31){ 36 _luna+=1; 37 _zi=31-  _luna; 38 } 39 40 return *this; 41 } 42 43 44 int clsDate::operator-(clsDate &d) 45 { 46 clsDate a; 47 a.  _an = _an-d.  _an; a.  _an *= 365; 48 a.  _luna=  _luna-d.  _luna; a.  _luna*= 30; 49 a.  _zi=  _zi-d.  _zi; a.  _zi+=a.  _luna+a.  _an; 50 51 return a.  _zi; 52 } 53 54 int clsDate::operator==(clsDate &d) 55 { 56 if(  _zi==d.  _zi && _luna==d.  _luna && _an==d.  _an) 57 return 1; 58 return 0; 59 } 60 61 clsDate& clsDate::operator()(int nr, const char *element) 62 { 63 if(strcmp(element, "years")==0) 64 _an=nr; 65 if(strcmp(element, "months")==0) 66 _luna=nr;

Upload: viorel-curic

Post on 23-Feb-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

7/24/2019 Cls Date

http://slidepdf.com/reader/full/cls-date 1/2

 1 #include <iostream>

 2 #include<string.h>

 3 #include "clsDate.h"

 4 #include <ostream>

 5 using namespace std ;

 6

7 clsDate::clsDate(int a, int l, int z, char *nume)

 8 {

 9 _an=a;

10 _luna=l;

11 _zi=z;12 numeZi[30]=*nume;

13 }

14

15

16

17 ostream& operator<<(ostream &c, clsDate &d)

18 {

19 c<<"\nData este: "<<d. _zi<<"/"<<d. _luna<<"/"<<d. _an<<";";

20

21 }

22

23 istream & operator>>(istream &c, clsDate &d)

24 {25 cout<<"\nIntrodu ziua: ";c>>d. _zi;

26 cout<<"Introdu luna: ";c>>d. _luna;

27 cout<<"Introdu anul: ";c>>d. _an;

28

29 return c;

30 }

31

32

33 clsDate& clsDate::operator+(int nrzile)

34 {

35 if(( _zi+=nrzile)>31){

36 _luna+=1;

37 _zi=31- _luna;38 }

39

40 return *this;

41 }

42

43

44 int clsDate::operator-(clsDate &d)

45 {

46 clsDate a;

47 a. _an = _an-d. _an; a. _an *= 365;

48 a. _luna= _luna-d. _luna; a. _luna*= 30;

49 a. _zi= _zi-d. _zi; a. _zi+=a. _luna+a. _an;

50

51 return a. _zi;

52 }

53

54 int clsDate::operator==(clsDate &d)

55 {

56 if( _zi==d. _zi && _luna==d. _luna && _an==d. _an)

57 return 1;

58 return 0;

59 }

60

61 clsDate& clsDate::operator()(int nr, const char *element)

62 {

63 if(strcmp(element, "years")==0)

64 _an=nr;

65 if(strcmp(element, "months")==0)

66 _luna=nr;

7/24/2019 Cls Date

http://slidepdf.com/reader/full/cls-date 2/2

67 else

68 _zi=nr;

69 return *this;

70 }

71

72 int clsDate::operator()(const char *element)

73 {

74 if(strcmp(element, "years")==0)

75 return _an;

76 if(strcmp(element, "months")==0)

77 return _luna;78 if(strcmp(element, "days")==0)

79 return _zi;

80

81 }