#include using namespace std; class Pkt { int *xy; public: Pkt(int x, int y) { xy = new int[2]; xy[0] = x; xy[1] = y; } int zwrocX(); int zwrocY(); void wypisz(); Pkt() { xy = new int[2]; xy[0] = 10; xy[1] = 15; }; Pkt suma(Pkt &punkt); //Pkt roznica(Pkt &punkt, Pkt &punkt2); }; /* class Prosta { Pkt &punkt1; Pkt &punkt2; public: Prosta(); Prosta(pkt &, pkt &); ~Prosta(); void wypisz(); }; */ void Pkt::wypisz() { cout << "x: " << xy[0] << endl; cout << "y: " << xy[1] << endl;; } Pkt roznica(Pkt &a, Pkt &b) { int x, y; x = a.zwrocX() - b.zwrocX(); y = a.zwrocY() - b.zwrocY(); Pkt rozn(x, y); return rozn; } Pkt Pkt::suma(Pkt &punkt) { Pkt sum; sum.xy[0] = xy[0] + punkt.xy[0]; sum.xy[1] = xy[1] + punkt.xy[1]; return sum; } int Pkt::zwrocX() { return xy[0]; } int Pkt::zwrocY() { return xy[1]; } int main() { Pkt p1, p2(2, 5), p3(10, 7), p4(p3); p1.wypisz(); cout << "wspolrzedne punktu (2,5):" << endl; p2.wypisz(); cout << endl; p3.wypisz(); cout << endl; p4.wypisz(); p1 = p2.suma(p3); p2 = roznica(p1, p3); cout << endl; cout << "Suma: " << endl; p1.wypisz(); cout << endl; cout << "Roznica: " << endl; p2.wypisz(); cout << endl; cout << endl; system("PAUSE"); return 0; } /* #include #include using namespace std; class punkt2d { string nazwa; float x; float y; public: void ustaw(string nazwa, float a, float b) { this->nazwa = nazwa; x = a; y = b; } void wypisz(int q) { if (q == 1) { cout << this->nazwa << "( " << this->x << ", " << this->y << ")" << endl; } else if (q == 2) { cout << this->nazwa << "[" << this->x << ", " << this->y << "]" << endl; } else if (q == 3) { cout << this->nazwa << "{" << this->x << ", " << this->y << "}" << endl; } } string pobierzNazwa(); float pobierzX(); float pobierzY(); float miedzyPunktami(punkt2d punkt1) { return sqrt(((x - punkt1.x)*(x - punkt1.x)) + ((y - punkt1.y)*(y - punkt1.y))); } }; float odlOdZera(punkt2d punkt2) { return sqrt(((punkt2.pobierzX())*(punkt2.pobierzX())) + (punkt2.pobierzY())*punkt2.pobierzY()); } string punkt2d::pobierzNazwa() { return this->nazwa; } float punkt2d::pobierzX() { return this->x; } float punkt2d::pobierzY() { return this->y; } int main() { cout << "Ustawianie i wypisywanie punktu:" << endl; punkt2d punkt1; punkt1.ustaw("Pierwszy ", 5, 6); punkt1.wypisz(1); punkt1.wypisz(2); punkt1.wypisz(3); cout << endl; cout << endl; punkt2d punkt2; punkt2.ustaw("Drugi", 40, 50); cout << "Pobieranie:" << endl; float x1 = punkt2.pobierzX(); cout << x1 << endl; float y1 = punkt2.pobierzY(); cout << y1 << endl;; string nazwa = punkt2.pobierzNazwa(); cout << nazwa << endl; cout << endl; cout << "Odleglosc miedzy punktami:" << endl; float x3 = punkt2.miedzyPunktami(punkt1); cout << x3 << endl; cout << endl; cout << "Odleglosc od zera:" << endl; float x4 = odlOdZera(punkt1); cout << x4 << endl; cout << endl; cout << endl; cout << endl; cout << "Punkt dynamiczny: " << endl; punkt2d *punktDyn = new punkt2d; punktDyn->ustaw("Trzeci ", 8, 15); punktDyn->wypisz(1); cout << endl; cout << endl; system("PAUSE"); return 0; } */