• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# main

a guest Dec 7th, 2019 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include "Punkt.cpp"
3.
4.
5. using namespace std;
6.
7.   // .................................... OPERATOR + .................................... //
8.   // .................................... dla innego typu z prawej strony
9.   Punkt operator +(int x, Punkt &thisP) {
10.     int nowyX = thisP.x + x;
11.     int nowyY = thisP.y + x;
12.     Punkt nowyPunkt = Punkt(nowyX, nowyY);
13.
14.     return nowyPunkt;
15.   }
16.
17.
18. int main() {
19.
20.   Punkt p1 = Punkt(1, 5);
21.   Punkt p2 = Punkt(2, 10);
22.   Punkt innyObiektPunktuTakiSamJakP1 = Punkt(1, 5);
23.
24.
25.   // .................................... OPERATOR += .................................... //
26.   cout << "p1 += p2" << endl;
27.   cout << "Przed: " << endl;
28.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
29.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
30.   cout << endl;
31.
32.   p1+=p2;
33.
34.   cout << "Po: " << endl;
35.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
36.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
37.   cout << endl;
38.
39.
40.   // .................................... OPERATOR = ..................................... //
41.   cout << "p1 = p2" << endl;
42.
43.   // Reset danych
44.   p1 = Punkt(1, 5);
45.   p2 = Punkt(2, 10);
46.
47.   cout << "Przed: " << endl;
48.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
49.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
50.   cout << endl;
51.
52.   p1 = p2;
53.
54.   cout << "Po: " << endl;
55.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
56.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
57.   cout << endl;
58.
59.
60.   // .................................... OPERATOR == .................................... //
61.   cout << "p1 == p2 i p1 == innyObiektPunktuTakiSamJakP1" << endl;
62.
63.   // Reset danych
64.   p1 = Punkt(1, 5);
65.   p2 = Punkt(2, 10);
66.   innyObiektPunktuTakiSamJakP1 = Punkt(1, 5);
67.
68.   cout << "Przed: " << endl;
69.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
70.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
71.   cout << "innyObiektPunktuTakiSamJakP1: " << innyObiektPunktuTakiSamJakP1.x << "," <<  innyObiektPunktuTakiSamJakP1.y << endl;
72.   cout << endl;
73.
74.   bool wynik = p1 == p2;
75.   cout << "p1 == p2: " << wynik << endl;
76.   bool wynikTrue = p1 == innyObiektPunktuTakiSamJakP1;
77.   cout << "p1 == innyObiektPunktuTakiSamJakP1: " << wynikTrue << endl;
78.   cout << endl;
79.
80.   cout << "Po: " << endl;
81.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
82.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
83.   cout << "innyObiektPunktuTakiSamJakP1: " << innyObiektPunktuTakiSamJakP1.x << "," <<  innyObiektPunktuTakiSamJakP1.y << endl;
84.   cout << endl;
85.
86.
87.   // .................................... OPERATOR + .................................... //
88.   cout << "p1 + p2" << endl;
89.
90.   // Reset danych
91.   p1 = Punkt(1, 5);
92.   p2 = Punkt(2, 10);
93.
94.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
95.   cout << "P2: " << p2.x << "," <<  p2.y << endl;
96.   cout << endl;
97.
98.   Punkt nowyPunkt = p1 + p2;
99.
100.   cout << "Punkt nowyPunkt = p1 + p2: " << endl;
101.   cout << "nowyPunkt: " << nowyPunkt.x << "," <<  nowyPunkt.y << endl;
102.   cout << endl;
103.
104.
105.   // .................................... OPERATOR + .................................... //
106.   // .................................... dla innego typu z prawej strony
107.   cout << "5 + p1" << endl;
108.
109.   // Reset danych
110.   p1 = Punkt(1, 5);
111.   p2 = Punkt(2, 10);
112.   int doDodania = 100;
113.
114.   cout << "P1: " << p1.x << "," <<  p1.y << endl;
115.   cout << "doDodania: " << doDodania << endl;
116.   cout << endl;
117.
118.   Punkt nowyPunkt2 = 5 + p1;
119.
120.   cout << "Punkt nowyPunkt = p1 + doDodania: " << endl;
121.   cout << "nowyPunkt: " << nowyPunkt2.x << "," <<  nowyPunkt2.y << endl;
122.   cout << endl;
123. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top