// console_operator.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; struct CAS { unsigned char hod; // hodiny unsigned char min; // minuty unsigned char sec; // sekundy unsigned int msec; // milisekundy }; int operator == (CAS a, CAS b) { return (a.msec == b.msec) && (a.sec == b.sec) && (a.min == b.min) && (a.hod == b.hod); }; int operator != (CAS a, CAS b) { return !(a==b); // pouzijeme vyse definovany operator == } int operator < (CAS a, CAS b) { if(a.hod != b.hod) return a.hod < b.hod; if(a.min != b.min) return a.min < b.min; if(a.sec != b.sec) return a.sec < b.sec; return a.msec < b.msec; }; int operator <= (CAS a, CAS b) { return a == b || a < b; // pouzijeme vyse definovane operatory }; int operator > (CAS a, CAS b) { return !(b <= a); }; int operator >= (CAS a, CAS b) { return !(a < b); } int _tmain(int argc, _TCHAR* argv[]) { CAS t1, t2, t3; t1.hod = 10; t1.min = 5; t1.sec = 26; t1.msec = 25; t2.hod = 10; t2.min = 5; t2.sec = 26; t2.msec = 25; t3.hod = 10; t3.min = 5; t3.sec = 26; t3.msec = 30; cout << "rovnost == " << endl<< (t1 == t2) << endl << (t1 == t3) << endl; cout << "nerovnost != " << endl<< (t1 != t2) << endl << (t1 != t3) << endl; cout << "mensi < " << endl<< (t1 < t2) << endl << (t1 < t3) << endl; cout << "mensi rovno <= " << endl<< (t1 <= t2) << endl << (t1 <= t3) << endl; cout << "vetsi > " << endl<< (t1 > t2) << endl << (t1 > t3) << endl; cout << "vetsi rovno >= " << endl<< (t1 >= t2) << endl << (t1 >= t3) << endl; return 0; }