00001 // Copyright (C) 2008 ETF Mighty Coders 00002 00003 #include "Tacka.h" 00004 00005 #include <cmath> // Zbog funkcija sqrt i fabs 00006 #include <iomanip> // Zbog manipulatora setprecision 00007 00008 Tacka::Tacka(double pv_apscisa, double pv_ordinata) 00009 : apscisa(pv_apscisa), ordinata(pv_ordinata) 00010 { 00011 } 00012 00013 double Tacka::poteg() const 00014 { 00015 return sqrt(apscisa * apscisa + ordinata * ordinata); 00016 } 00017 00018 std::ostream& operator<<(std::ostream& o, const Tacka& rhs) 00019 { 00020 return o << std::fixed << std::setprecision(3) << rhs.poteg() << " - (" << rhs.apscisa << ',' << rhs.ordinata << ')' << std::endl; 00021 } 00022 00023 bool Tacka::operator<(const Tacka& rhs) const 00024 { 00025 return poteg() < rhs.poteg(); 00026 } 00027 00028 bool Tacka::operator==(const Tacka& rhs) const 00029 { 00030 return fabs(poteg() - rhs.poteg()) < 0.000001; 00031 }
1.5.3