fork(1) 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. int main(){
  45. point A,B,C;
  46. line line_and_mid;
  47. cout<<"Enter first two point :";
  48. double x1,y1;
  49. cin>>x1>>y1;
  50. A.set_point(x1,y1);
  51. cout<<"Enter second two point :";
  52.  
  53. cin>>x1>>y1;
  54. B.set_point(x1,y1);
  55.  
  56. cout<<endl;
  57. line_and_mid.set_ends(A,B);
  58. cout<<"Length of the line :"<<fixed<<setprecision(2)<<line_and_mid.length()<<endl;
  59. C=line_and_mid.midpoint();
  60. cout<<"Midpoints are :"<<"("<<C.get_x()<<","<<C.get_y()<<")"<<endl;
  61. return 0;
  62. }
  63.  
  64.  
  65.  
  66.  
Success #stdin #stdout 0.01s 5288KB
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)