Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Punkt.cpp"
- using namespace std;
- // .................................... OPERATOR + .................................... //
- // .................................... dla innego typu z prawej strony
- Punkt operator +(int x, Punkt &thisP) {
- int nowyX = thisP.x + x;
- int nowyY = thisP.y + x;
- Punkt nowyPunkt = Punkt(nowyX, nowyY);
- return nowyPunkt;
- }
- int main() {
- Punkt p1 = Punkt(1, 5);
- Punkt p2 = Punkt(2, 10);
- Punkt innyObiektPunktuTakiSamJakP1 = Punkt(1, 5);
- // .................................... OPERATOR += .................................... //
- cout << "p1 += p2" << endl;
- cout << "Przed: " << endl;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << endl;
- p1+=p2;
- cout << "Po: " << endl;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << endl;
- // .................................... OPERATOR = ..................................... //
- cout << "p1 = p2" << endl;
- // Reset danych
- p1 = Punkt(1, 5);
- p2 = Punkt(2, 10);
- cout << "Przed: " << endl;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << endl;
- p1 = p2;
- cout << "Po: " << endl;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << endl;
- // .................................... OPERATOR == .................................... //
- cout << "p1 == p2 i p1 == innyObiektPunktuTakiSamJakP1" << endl;
- // Reset danych
- p1 = Punkt(1, 5);
- p2 = Punkt(2, 10);
- innyObiektPunktuTakiSamJakP1 = Punkt(1, 5);
- cout << "Przed: " << endl;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << "innyObiektPunktuTakiSamJakP1: " << innyObiektPunktuTakiSamJakP1.x << "," << innyObiektPunktuTakiSamJakP1.y << endl;
- cout << endl;
- bool wynik = p1 == p2;
- cout << "p1 == p2: " << wynik << endl;
- bool wynikTrue = p1 == innyObiektPunktuTakiSamJakP1;
- cout << "p1 == innyObiektPunktuTakiSamJakP1: " << wynikTrue << endl;
- cout << endl;
- cout << "Po: " << endl;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << "innyObiektPunktuTakiSamJakP1: " << innyObiektPunktuTakiSamJakP1.x << "," << innyObiektPunktuTakiSamJakP1.y << endl;
- cout << endl;
- // .................................... OPERATOR + .................................... //
- cout << "p1 + p2" << endl;
- // Reset danych
- p1 = Punkt(1, 5);
- p2 = Punkt(2, 10);
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "P2: " << p2.x << "," << p2.y << endl;
- cout << endl;
- Punkt nowyPunkt = p1 + p2;
- cout << "Punkt nowyPunkt = p1 + p2: " << endl;
- cout << "nowyPunkt: " << nowyPunkt.x << "," << nowyPunkt.y << endl;
- cout << endl;
- // .................................... OPERATOR + .................................... //
- // .................................... dla innego typu z prawej strony
- cout << "5 + p1" << endl;
- // Reset danych
- p1 = Punkt(1, 5);
- p2 = Punkt(2, 10);
- int doDodania = 100;
- cout << "P1: " << p1.x << "," << p1.y << endl;
- cout << "doDodania: " << doDodania << endl;
- cout << endl;
- Punkt nowyPunkt2 = 5 + p1;
- cout << "Punkt nowyPunkt = p1 + doDodania: " << endl;
- cout << "nowyPunkt: " << nowyPunkt2.x << "," << nowyPunkt2.y << endl;
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement