fork download
  1. //week2(problem 4 part 1)
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. class points
  6. {
  7. public:
  8. float x,y;
  9.  
  10.  
  11. };
  12. class line
  13. { public:
  14. points A;
  15. float sum;
  16. float length(points p1,points p2)
  17. {
  18. sum=pow((p1.x-p2.x),2)+pow((p1.y-p2.y),2);
  19. return sqrt(sum);
  20.  
  21. }
  22. points midpoint(points p1,points p2)//float return dile hobe na
  23. {
  24. A.x=(p1.x+p2.x)/2;
  25. A.y=(p1.y+p2.y)/2;
  26. /*
  27.   // cout<<"Midpoint of the line :"<<"("<<A.x<<" "<<A.y<<")";
  28.   if we dont want to return points;
  29.  
  30.   */
  31. //CAN NOT RETURN 0 BECAUSE ITS POINT TUPE FUNCTION
  32. return A;
  33. }
  34.  
  35.  
  36.  
  37. };
  38. int main()
  39. { line x;
  40. points a,b,mid;
  41. cout<<"Enter coordinate of the first point(x1,y1):";
  42. cin>>a.x;
  43. cin>>a.y;
  44. cout<<"Enter coordinate of the second point(x2,y2):";
  45. cin>>b.x;
  46. cin>>b.y;
  47. cout<<"Length of the line :"<<fixed<<setprecision(2)<<x.length(a,b)<<endl;
  48. mid=x.midpoint(a,b);
  49. cout<<"Midpoint of the line :"<<"("<<mid.x<<","<<mid.y<<")"<<endl;
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter coordinate of the first point(x1,y1):Enter coordinate of the second point(x2,y2):Length of the line :inf
Midpoint of the line :(-3754303106267568144384.00,0.00)