Advertisement
irmantas_radavicius

Untitled

Apr 23rd, 2024
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cctype>
  7.  
  8. using namespace std;
  9.  
  10. struct Point {
  11.  
  12.     double x;
  13.     double y;
  14.     string s;
  15.  
  16.     Point(string s){
  17.         this->s = s;
  18.         x = 0;
  19.         y = 0;
  20.     }
  21.  
  22.     Point(string s, int x, int y){
  23.         this->s = s;
  24.         this->x = x;
  25.         this->y = y;
  26.     }
  27.  
  28.     void print(){
  29.         cout << s << ": (" << x << "," << y << ")" << endl;
  30.     }
  31.  
  32.     void read(){
  33.         cout << s << " taskas, ivesk dvi koordinates: ";
  34.         cin >> x >> y;
  35.         this->s = s;
  36.     }
  37.  
  38.     double getDistance(Point q){
  39.         double dx = this->x-q.x;
  40.         double dy = this->y-q.y;
  41.         return sqrt(dx*dx + dy*dy);
  42.     }
  43.  
  44. };
  45.  
  46.  
  47.  
  48.  
  49.  
  50. int main(){
  51.  
  52.     Point p1("Pirmas", 1, 2), p2("Antras", 4, 5), p3("Trecias");
  53.     p3.read();
  54.  
  55.     cout << "Turime tris taskus: " << endl;
  56.     p1.print();
  57.     p2.print();
  58.     p3.print();
  59.  
  60.     cout << "Atstumas tarp p1 ir p2 yra " << p1.getDistance(p2) << endl;
  61.     cout << "Atstumas tarp p1 ir p3 yra " << p1.getDistance(p3) << endl;
  62.  
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement