Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- #include <math.h>
- using namespace std;
- class CLinia
- {
- int x1, y1, x2, y2;
- public:
- CLinia(const int X1=0, const int Y1=0, const int X2=0, const int Y2=0);
- CLinia(const CLinia & l);
- CLinia & operator += (const int d);
- CLinia & operator -= (const int d);
- operator double();
- operator string();
- friend ostream & operator << (ostream &o, CLinia &l);
- bool operator == (const CLinia &l);
- bool operator != (const CLinia &l);
- bool operator < (const CLinia &l);
- bool operator > (const CLinia &l);
- bool operator <= (const CLinia &l);
- bool operator >= (const CLinia &l);
- };
- CLinia::CLinia(const int X1, const int Y1, const int X2, const int Y2):
- x1(X1), y1(Y1), x2(X2), y2(Y2) {}
- CLinia::CLinia(const CLinia & l):
- x1(l.x1), y1(l.y1), x2(l.x2), y2(l.y2) {}
- CLinia & CLinia::operator += (const int d)
- {
- x2+=d;
- y2+=d;
- return *this;
- }
- CLinia & CLinia::operator -= (const int d)
- {
- x2-=d;
- y2-=d;
- return *this;
- }
- CLinia::operator double()
- {
- double kw = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
- return sqrt(kw);
- }
- CLinia::operator string()
- {
- char buf[32];
- sprintf(buf, "Operator string: (%d,%d) - (%d,%d)",x1, y1, x2, y2);
- return buf;
- }
- ostream & operator << (ostream &o, CLinia &l)
- {
- return o << "Operator <<: (" << l.x1 << "," << l.y1 << ") - (" << l.x2 << "," << l.y2 << ")";
- }
- bool CLinia::operator == (const CLinia &l)
- {
- if( x1==l.x1 && x2==l.x2 && y1==l.y1 && y2==l.y2 ) return 1;
- return 0;
- }
- bool CLinia::operator != (const CLinia &l)
- {
- if( x1!=l.x1 || x2!=l.x2 || y1!=l.y1 || y2!=l.y2 ) return 1;
- return 0;
- }
- bool CLinia::operator < (const CLinia &l)
- {
- double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
- double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
- double d1 = sqrt(kw1);
- double d2 = sqrt(kw2);
- return d1<d2;
- }
- bool CLinia::operator > (const CLinia &l)
- {
- double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
- double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
- double d1 = sqrt(kw1);
- double d2 = sqrt(kw2);
- return d1>d2;
- }
- bool CLinia::operator <= (const CLinia &l)
- {
- double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
- double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
- double d1 = sqrt(kw1);
- double d2 = sqrt(kw2);
- return d1<=d2;
- }
- bool CLinia::operator >= (const CLinia &l)
- {
- double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
- double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
- double d1 = sqrt(kw1);
- double d2 = sqrt(kw2);
- return d1>=d2;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- CLinia a(1,2,3,4);
- cout << a << "\n";
- cout << (string)a << "\n";
- CLinia b(a);
- if(a==b) cout << "a rowne b\n";
- else cout << "a rozne od b\n\n";
- b+=3;
- if(a==b) cout << "a rowne b\n";
- else cout << "a rozne od b\n\n";
- b-=3;
- if(a==b) cout << "a rowne b\n";
- else cout << "a rozne od b\n\n";
- //a+=1;
- if(a>b) cout << "a wieksze od b\n";
- else cout << "a mniejsze od b";
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement