Advertisement
irmantas_radavicius

Untitled

Apr 9th, 2024
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 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.     double x;
  12.     double y;
  13.     string s;
  14. };
  15.  
  16. void print(Point p){
  17.     cout << p.s << ": (" << p.x << "," << p.y << ")" << endl;
  18. }
  19.  
  20. Point read(string s){
  21.     Point p;
  22.     cout << s << " taskas, ivesk dvi koordinates: ";
  23.     cin >> p.x >> p.y;
  24.     p.s = s;
  25.     return p;
  26. }
  27.  
  28. double getDistance(Point p, Point q){
  29.     double dx = p.x-q.x;
  30.     double dy = p.y-q.y;
  31.     return sqrt(dx*dx + dy*dy);
  32. }
  33.  
  34. int main(){
  35.  
  36.     Point p1 = read("Pirmas"); // { 0, 0 };
  37.     Point p2 = { 3, 4 }; // read("Antras");
  38.     Point p3 = { 4, 3, "Trecias" }; // read("Antras");
  39.  
  40.  
  41.     cout << "Turime tris taskus: " << endl;
  42.     print(p1);
  43.     print(p2);
  44.     print(p3);
  45.  
  46.     cout << "Atstumas tarp p1 ir p2 yra " << getDistance(p1, p2) << endl;
  47.     cout << "Atstumas tarp p1 ir p3 yra " << getDistance(p1, p3) << endl;
  48.  
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement