#include <iostream>
#include<cmath>
enum class Boja {Crna, Crvena, Zelena, Plava, Zuta, Smedja, Ljubicasta, Bijela};
class Tacka{
double x, y;
Boja b;
public:
Tacka(double x, double y, Boja b = Boja::Crna) : x(x), y(y), b(b) {}
double DajX() const { return x; }
double Dajy() const { return y; }
Boja DajBoju() const { return b; }
Tacka &PostaviX(double x){ Tacka::x = x; return *this;}
Tacka &PostaviY(double y) { Tacka::y = y; return *this;}
Tacka &PostaviBoju(Boja b) {Tacka::b = b; return *this;}
bool operator ==(const Tacka &t) const {return (x==t.x && y==t.y);}
bool operator !=(const Tacka &t) const { return !(*this == t);}
bool operator <(const Tacka &t) const { return x < t.x || (x == t.x && y < t.y);}
bool operator <=(const Tacka &t) const { return !(t < *this);}
bool operator >(const Tacka &t) const { return t < *this;}
bool operator >=(const Tacka &t) const { return !(*this < t);}
friend bool operator *(const Tacka &t){ return std::sqrt(t.x * t.x + t.y * t.y);}
bool operator !(const Tacka &t){ return t.x == 0 && t.y == 0;}
friend Tacka &operator ++(const Tacka &t){ t.b = Boja((int(t.b) + 1) % 8); return t;}
friend Tacka operator ++(Tacka &t, int){Tacka stara = t; ++t; return stara;}
friend std::ostream &operator <<(std::ostream &tok, Tacka t){
return tok<<"("<<t.x<<,<<t.y<<")";
}
};
class Duz{
Tacka t1, t2;
bool usmjerena;
static void TestBoje(const Tacka &t1, const Tacka &t2){
if(t1.DajBoju() != t2.DajBoju()) throw std::domain_error("Nesaglasne boje krajeva");
}
void TestUsmjerenosti(){ if(!usmjerena) throw std::logic_error("Nemoguca postavka za neusmjerene duzi");}
public:
Duz(Tacka t1, Tacka t2, bool usmjerena = false) : t1(t1), t2(t2), usmjerena(usmjerena){TestBoje(t1,t2);}
Duz(double x1, double y1, double x2, double y2, Boja boja, bool usmjerena = false) :
t1(x1,y1,boja), t2(x2,y2,boja), usmjerena(usmjerena){}
Duz &Postavi(double x1, double y1, double x2, double y2, Boja boja, bool usmjerena = false){
t1.PostaviX(x1).PostaviY(y1).PostaviBoju(boja);
t2.PostaviX(x2).PostaviY(y2).PostaviBoju(boja);
Duz::usmjerena = usmjerena; return *this;
}
const Tacka &DajPocetak() const{return (usmjerena || t1 < t2) ? t1 : t2;}
const Tacka &DajZavrsetak() const{return(usmjerena || t1 < t2) ? t2 : t1;}
Boja DajBoju() const{return t1.DajBoju();}
Duz &PostaviPocetak (const Tacka &t){TestUsmjerenosti(); TestBoje(t, t2); Duz::t1 = t; return *this;}
Duz &PostaviPocetak(double x, double y){TestUsmjerenosti() t1.PostaviX(x).PostaviY(y); return *this;}
Duz &PostaviZavrsetak(const Tacka &t){TestUsmjerenosti(); TestBoje(t1, t); t2 = t; return *this;}
Duz &PostaviPocetak(double x, double y){TestUsmjerenosti() t2.PostaviX(x).PostaviY(y); return *this;}
Duz &PostaviBoju(Boja b) {t1.PostaviBoju(b); t2.PostaviBoju(b); return *this;}
bool operator ==(const Duz &d) const{
return usmjerena == d.usmjerena && DajPocetak() == d.DajPocetak() &&
DajZavrsetak() == d.DajZavrsetak();
}
bool operator !=(const Duz &d) const {return !(*this == d);}
friend bool operator !(const Duz &d) {return d.t1==d.t2;}
double operator *() const {
return std::sqrt((t2.DajX() - t1.DajX()) * (t2.DajX() - t1.DajX())
+ (t2.DajY() - t1.DajY()) * (t2.DajY() - t1.DajY()));
}
friend std::ostream &operator <<(std::ostream &tok, const Duz &d) {
return tok << d.DajPocetak() << "-" << d.DajZavrsetak();
}
};
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: