Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- using namespace std;
- //stabilire daca year este an bisect
- #define isleapyear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
- struct date {
- int year;
- int month;
- int day;
- int wday;
- };
- char *wdays[11]={"Luni","Marti","Miercuri","Joi","Vineri","Sambata","Duminica"};
- int isdatevalid ( struct date);
- void weekday( struct date &);
- int main()
- {
- int month, day, year;
- struct date d;
- cout << "Introdu data in format: zz ll aaaa : ";
- cin >> d.day >> d.month >> d.year;
- if (isdatevalid(d)) {
- weekday(d);
- cout << "Ziua spatamanii de la aceasta data este: " << wdays[d.wday] << "\n";
- }
- else
- cout << d.day << "/" << d.month << "/" << d.year << " is not a valid date!";
- getchar();
- getchar();
- return 0;
- }
- //functie de verificare a validatatii datei introduse
- int isdatevalid(struct date d)
- {
- if (d.day <= 0) return 0 ;
- switch( d.month )
- {
- case 1 :
- case 3 :
- case 5 :
- case 7 :
- case 8 :
- case 10 :
- case 12 : if (d.day > 31) return 0 ; else return 1 ;
- case 4 :
- case 6 :
- case 9 :
- case 11 : if (d.day > 30) return 0 ; else return 1 ;
- case 2 :
- if ( d.day > 29 ) return 0 ;
- if ( d.day < 29 ) return 1 ;
- if (isleapyear(d.year)) return 1 ; // an bisect
- else return 0 ;
- }
- return 0 ;
- }
- void weekday(struct date &d)
- {
- int ix, tx, vx;
- switch (d.month) {
- case 2 :
- case 6 : vx = 0; break;
- case 8 : vx = 4; break;
- case 10 : vx = 8; break;
- case 9 :
- case 12 : vx = 12; break;
- case 3 :
- case 11 : vx = 16; break;
- case 1 :
- case 5 : vx = 20; break;
- case 4 :
- case 7 : vx = 24; break;
- }
- if (d.year > 1900) // 1900 nu a fost an bisect
- d.year -= 1900;
- ix = ((d.year - 21) % 28) + vx + (d.month > 2);
- tx = (ix + (ix / 4)) % 7 + d.day;
- d.wday = tx % 7;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement