tungggg

triangle

May 17th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. struct Point {
  6.   int x, y ;
  7.   Point (){
  8.       x=0;
  9.       y=0;
  10.   }
  11.   Point (int _x , int _y){
  12.       x=_x;
  13.       y=_y;
  14.   }
  15.   double dis (Point another ){
  16.       double res= sqrt( (x-another.x)* (x-another.x)  + (y-another.y)*(y-another.y) );
  17.       return res;
  18.   }
  19.    
  20. };
  21.  
  22.  
  23. struct Triangle{
  24.   Point p1;
  25.   Point p2;
  26.   Point p3 ;
  27.     Triangle (Point _p1, Point _p2, Point _p3 ){
  28.         p1=_p1;
  29.         p2=_p2;
  30.         p3=_p3;
  31.     }
  32.     double sumDistance ( Point another ){
  33.         double total = p1.dis(another) + p2.dis ( another ) + p3.dis(another);
  34.         return total;
  35.     }    
  36. };
  37.  
  38.  
  39.  
  40.  
  41. //Sinh viên viết code vào đây
  42.  
  43. int main(){
  44.     // CHÚ Ý: Sinh viên không được thay đổi nội dung hàm main
  45.     // Chương trình thay đổi hàm main sẽ không được tính điểm dù đúng tất cả các test
  46.     int x1, y1, x2, y2, x3, y3, x, y;
  47.     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x >> y;
  48.  
  49.     Point p1(x1, y1);
  50.     Point p2(x2, y2);
  51.     Point p3(x3, y3);
  52.     Triangle t(p1, p2, p3);
  53.  
  54.     Point p(x,y);
  55.  
  56.     cout << t.sumDistance(p) << endl;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment