1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include "C:\Users\CS\Desktop\Documents\std_lib_facilities.h"
#include <conio.h>
//**************************************************************
class Year {
static const int min = 1800;
static const int max = 2200;
public:
Year(int x): y(x) { if(x < min || x > max) error("bad year");}
int year() {return y;}
private:
int y;
};
//*************************************************
class Date {
public:
enum Month {
jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
};
Date(Year yy, Month mm, int dd) {
if((mm < 1 || mm > 12 || dd < 1 || dd > 31)
|| (yy.year() % 4 != 0 && mm == 2 && dd > 28)
|| ( (mm == 4 || mm == 6 || mm == 9 || mm == 11) &&
( dd > 30)))
error("invalid date!");
else m = mm; d = dd; y = yy;
}
int month() { return m; }
int day() { return d; }
int year() { return y.year();}
private:
int d;
Month m;
Year y;
};
//**************************************************************
ostream& operator<<(ostream& os, Date& dd)
{
return os << '(' << dd.year() << ',' << dd.month() << ',' << dd.day() << ')';
}
//**********************************************
int main()
try {
Date d1 (Year(1983), Date:: mar, 25);
Date d2 = d1;
cout << d1 << ' ' << d2 << endl;
getch();
return 0;
}
catch(exception& e)
{
cerr << e.what() << endl;
getch();
return 0;
}
| |