fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class point{
  4. private:
  5. double x,y;
  6.  
  7. public:
  8. void set_point(double x1,double y1){
  9. x=x1;
  10. y=y1;
  11. }
  12. double get_x(){
  13. return x;
  14. }
  15. double get_y(){
  16. return y;
  17. }
  18. };
  19.  
  20. class line{
  21. //private:
  22. // point start,ends;
  23. public:
  24. // void set_ends(point a,point b){
  25. // start=a;
  26. // ends=b;
  27. // }
  28. // double length(){
  29. // double dx,dy;
  30. // dx=start.get_x()-ends.get_x();
  31. // dy=start.get_y()-ends.get_y();
  32. // return sqrt(dx*dx+dy*dy);
  33. // }
  34. // point midpoint(){
  35. // double mid_x,mid_y;
  36. // mid_x=(start.get_x()+ends.get_x())/2;
  37. // mid_y=(start.get_y()+ends.get_y())/2;
  38. // point mid;
  39. // mid.set_point(mid_x,mid_y);
  40. // return mid;
  41. // }
  42.  
  43.  
  44. double length(point a, point b) {
  45. double dx = a.get_x() - b.get_x();
  46. double dy = a.get_y() - b.get_y();
  47. return sqrt(dx*dx + dy*dy);
  48. }
  49.  
  50. point midpoint(point a, point b) {
  51. double mid_x = (a.get_x() + b.get_x()) / 2;
  52. double mid_y = (a.get_y() + b.get_y()) / 2;
  53. point mid;
  54. mid.set_point(mid_x, mid_y);
  55. return mid;
  56. }
  57.  
  58.  
  59. };
  60. int main(){
  61. point A,B,C;
  62. line line_and_mid;
  63. cout<<"Enter first two point :";
  64. double x1,y1;
  65. cin>>x1>>y1;
  66. A.set_point(x1,y1);
  67. cout<<"Enter second two point :";
  68.  
  69. cin>>x1>>y1;
  70. B.set_point(x1,y1);
  71.  
  72. cout<<endl;
  73. //line_and_mid.set_ends(A,B);
  74. cout<<"Length of the line :"<<fixed<<setprecision(2)<<line_and_mid.length(A,B)<<endl;
  75. C=line_and_mid.midpoint(A,B);
  76. cout<<"Midpoints are :"<<"("<<C.get_x()<<","<<C.get_y()<<")"<<endl;
  77. return 0;
  78. }
  79.  
  80.  
  81.  
  82.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Enter first two point :Enter second two point :
Length of the line :0.00
Midpoints are :(0.00,0.00)