Facebook
From Soft Bat, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 287
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Pkt {
  6.         int *xy;
  7. public:
  8.         Pkt(int x, int y) {
  9.                 xy = new int[2];
  10.                 xy[0] = x;
  11.                 xy[1] = y;
  12.         }
  13.         int zwrocX();
  14.         int zwrocY();
  15.  
  16.         void wypisz();
  17.         Pkt() {
  18.                 xy = new int[2];
  19.                 xy[0] = 10;
  20.                 xy[1] = 15;
  21.         };
  22.  
  23.         Pkt suma(Pkt &punkt);
  24.  
  25.         //Pkt roznica(Pkt &punkt, Pkt &punkt2);
  26.        
  27.        
  28. };
  29. /*
  30. class Prosta {
  31.         Pkt &punkt1;
  32.         Pkt &punkt2;
  33.        
  34. public:
  35.         Prosta();
  36.         Prosta(pkt &, pkt &);
  37.         ~Prosta();
  38.         void wypisz();
  39. };
  40. */
  41.  
  42. void Pkt::wypisz() {
  43.         cout << "x: " << xy[0] << endl;
  44.         cout << "y: " << xy[1] << endl;;
  45. }
  46.  
  47. Pkt roznica(Pkt &a, Pkt &b) {
  48.         int x, y;
  49.         x = a.zwrocX() - b.zwrocX();
  50.         y = a.zwrocY() - b.zwrocY();
  51.         Pkt rozn(x, y);
  52.         return rozn;
  53. }
  54.  
  55.  
  56. Pkt Pkt::suma(Pkt &punkt) {
  57.         Pkt sum;
  58.         sum.xy[0] = xy[0] + punkt.xy[0];
  59.         sum.xy[1] = xy[1] + punkt.xy[1];
  60.  
  61.         return sum;
  62.  
  63. }
  64.  
  65. int Pkt::zwrocX() {
  66.         return xy[0];
  67. }
  68.  
  69. int Pkt::zwrocY() {
  70.         return xy[1];
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. int main() {
  79.        
  80.         Pkt p1, p2(2, 5), p3(10, 7), p4(p3);
  81.         p1.wypisz();
  82.  
  83.  
  84.         cout << "wspolrzedne punktu (2,5):" << endl;
  85.        
  86.         p2.wypisz();
  87.         cout << endl;
  88.         p3.wypisz();
  89.         cout << endl;
  90.         p4.wypisz();
  91.         p1 = p2.suma(p3);
  92.         p2 = roznica(p1, p3);
  93.        
  94.         cout << endl;
  95.        
  96.         cout << "Suma: " << endl;
  97.         p1.wypisz();
  98.  
  99.         cout << endl;
  100.        
  101.         cout << "Roznica: " << endl;
  102.         p2.wypisz();
  103.  
  104.         cout << endl;
  105.         cout << endl;
  106.  
  107.        
  108.         system("PAUSE");
  109.         return 0;
  110. }
  111.  
  112.  
  113.  
  114. /*
  115. #include <iostream>
  116. #include <string>
  117. using namespace std;
  118.  
  119.  
  120. class punkt2d {
  121.         string nazwa;
  122.         float x;
  123.         float y;
  124. public:
  125.         void ustaw(string nazwa, float a, float b) {
  126.                 this->nazwa = nazwa;
  127.                 x = a;
  128.                 y = b;
  129.         }
  130.  
  131.         void wypisz(int q) {
  132.                 if (q == 1)
  133.                 {
  134.                         cout << this->nazwa << "( " << this->x << ", " << this->y << ")" << endl;
  135.                 }
  136.                 else if (q == 2)
  137.                 {
  138.                         cout << this->nazwa << "[" << this->x << ", " << this->y << "]" << endl;
  139.                 }
  140.                 else if (q == 3)
  141.                 {
  142.                         cout << this->nazwa << "{" << this->x << ", " << this->y << "}" << endl;
  143.                 }
  144.         }
  145.  
  146.         string pobierzNazwa();
  147.         float pobierzX();
  148.         float pobierzY();
  149.  
  150.         float miedzyPunktami(punkt2d punkt1) {
  151.                 return sqrt(((x - punkt1.x)*(x - punkt1.x)) + ((y - punkt1.y)*(y - punkt1.y)));
  152.         }
  153. };
  154.  
  155.  
  156. float odlOdZera(punkt2d punkt2) {
  157.         return sqrt(((punkt2.pobierzX())*(punkt2.pobierzX())) + (punkt2.pobierzY())*punkt2.pobierzY());
  158. }
  159.  
  160. string punkt2d::pobierzNazwa() {
  161.         return this->nazwa;
  162. }
  163.  
  164. float punkt2d::pobierzX() {
  165.         return this->x;
  166. }
  167.  
  168. float punkt2d::pobierzY() {
  169.         return this->y;
  170. }
  171.  
  172. int main() {
  173.         cout << "Ustawianie i wypisywanie punktu:" << endl;
  174.         punkt2d punkt1;
  175.         punkt1.ustaw("Pierwszy ", 5, 6);
  176.  
  177.         punkt1.wypisz(1);
  178.         punkt1.wypisz(2);
  179.         punkt1.wypisz(3);
  180.  
  181.         cout << endl;
  182.         cout << endl;
  183.  
  184.         punkt2d punkt2;
  185.         punkt2.ustaw("Drugi", 40, 50);
  186.         cout << "Pobieranie:" << endl;
  187.  
  188.         float x1 = punkt2.pobierzX();
  189.         cout << x1 << endl;
  190.  
  191.         float y1 = punkt2.pobierzY();
  192.         cout << y1 << endl;;
  193.  
  194.         string nazwa = punkt2.pobierzNazwa();
  195.         cout << nazwa << endl;
  196.         cout << endl;
  197.         cout << "Odleglosc miedzy punktami:" << endl;
  198.         float x3 = punkt2.miedzyPunktami(punkt1);
  199.         cout << x3 << endl;
  200.         cout << endl;
  201.         cout << "Odleglosc od zera:" << endl;
  202.         float x4 = odlOdZera(punkt1);
  203.         cout << x4 << endl;
  204.  
  205.         cout << endl;
  206.         cout << endl;
  207.         cout << endl;
  208.  
  209.  
  210.         cout << "Punkt dynamiczny: " << endl;
  211.         punkt2d *punktDyn = new punkt2d;
  212.         punktDyn->ustaw("Trzeci ", 8, 15);
  213.         punktDyn->wypisz(1);
  214.  
  215.         cout << endl;
  216.         cout << endl;
  217.  
  218.  
  219.         system("PAUSE");
  220.         return 0;
  221. }
  222.  
  223. */