// lisaapvm.cpp // P„iv„m„„r„n lis„„minen yhdell„ // Vesa Lappalainen 23.1.2000 #include int k_pituudet[2][12] = { // 1 2 3 4 5 6 7 8 9 10 11 12 { 31,28,31,30,31,30,31,31,30,31,30,31 }, { 31,29,31,30,31,30,31,31,30,31,30,31 } }; int karkausvuosi(int vv) { if ( vv % 400 == 0 ) return 1; if ( vv % 100 == 0 ) return 0; return ( vv % 4 == 0 ); } void lisaa_pvm(int &pp, int &kk, int &vv) { ++pp; int kv = karkausvuosi(vv); //palauttaa 0 jos ei, 1 jos on int pv_lkm = k_pituudet[kv][kk-1]; if ( pp > pv_lkm ) { pp = 1; ++kk; } if ( kk > 12 ) { kk = 1; ++vv; } } void testaa(int &pp, int &kk, int &vv, int kpl) { cout << "Aluksi: " << pp << "." << kk << "." << vv << endl; for (int i=0; i " << pp << "." << kk << "." << vv << endl; } } int main(void) { int pp=27, kk = 2, vv = 1999; testaa(pp,kk,vv,3); pp=27; kk = 2; vv = 2000; testaa(pp,kk,vv,3); pp=31; kk=12; testaa(pp,kk,vv,2); return 0; }