Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Program that find the distance between two points in 2D and 3D space using function overloading

Posted By: Easy Tutor     Category: C++ Programming     Views: 6702

A C++ Program that find the distance between two points in 2D and 3D space using function overloading.

Code for Program that find the distance between two points in 2D and 3D space using function overloading in C++ Programming

 #include<iostream.h>
 #include<math.h>
 #include<conio.h>

 float distance(float,float,float,float);
 float distance(float,float,float,float,float,float);

 main()
    {
       clrscr();

       float x1;
       float x2;
       float y1;
       float y2;
       float distance_1;

       cout<<"\n *********  2D Distance ********"<<endl;

       cout<<"\n Enter the value of the first point P1 :"<<endl;

       cout<<"\t\t x_1 = ";
       cin>>x1;

       cout<<"\t\t y_1 = ";
       cin>>y1;

       cout<<"\n Enter the value of the second point P2 :"<<endl;

       cout<<"\t\t x_2 = ";
       cin>>x2;

       cout<<"\t\t y_2 = ";
       cin>>y2;

       float x_1;
       float x_2;
       float y_1;
       float y_2;
       float z_1;
       float z_2;
       float distance_2;

       cout<<"\n\n *********  3D Distance ********"<<endl;

       cout<<"\n Enter the value of the first point P1 :"<<endl;

       cout<<"\t\t x_1 = ";
       cin>>x_1;

       cout<<"\t\t y_1 = ";
       cin>>y_1;

       cout<<"\t\t z_1 = ";
       cin>>z_1;

       cout<<"\n Enter the value of the second point P2 :"<<endl;

       cout<<"\t\t x_2 = ";
       cin>>x_2;

       cout<<"\t\t y_2 = ";
       cin>>y_2;

       cout<<"\t\t z_2 = ";
       cin>>z_2;

       getch();
       clrscr();

       cout<<"\n *********  2D Distance ********"<<endl;

       cout<<"\n The values of the points P1 & P2 are :"<<endl;
       cout<<"\t\tP1 (x1,y1) = P1 ("<<x1<<","<<y1<<")"<<endl;
       cout<<"\t\t P2 (x2,y2) = P2 ("<<x2<<","<<y2<<")"<<endl;

       cout<<"\n Distance b/w P1 & P2 is :"<<endl;

       distance_1=distance(x1,y1,x2,y2);

       cout<<"\t\t ³P1P2³ = "<<distance_1<<endl;

       cout<<"\n\n *********  3D Distance ********"<<endl;

       cout<<"\n The values of the points P1 & P2 are :"<<endl;
       cout<<"\t\t P1 (x1,y1,z1) = P1 ("<<x_1<<","<<y_1<<","<<z_1<<")"<<endl;
       cout<<"\t\t P2 (x2,y2,z2) = P2 ("<<x_2<<","<<y_2<<","<<z_2<<")"<<endl;

       cout<<"\n Distance b/w P1 & P2 is :"<<endl;

       distance_2=distance(x_1,y_1,z_1,x_2,y_2,z_2);

       cout<<"\t\t ³P1P2³ = "<<distance_2<<endl;


       getch();
       return 0;
    }


 /*************************************************************************///-------------------  distance(float,float,float,float)  ---------------///*************************************************************************/float distance(float x_1,float y_1,float x_2,float y_2)
    {
       float distance=0;

       distance=sqrt(pow((x_2-x_1),2)+pow((y_2-y_1),2));
       return distance;
    }

 /*************************************************************************///-------------  distance(float,float,float,float,float,float)  ---------///*************************************************************************/float distance(float x_1,float y_1,float z_1,float x_2,float y_2,float z_2)
    {
       float distance=0;

       distance=sqrt(pow((x_2-x_1),2)+pow((y_2-y_1),2)+pow((z_2-z_1),2));
       return distance;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program that find the distance between two points in 2D and 3D space using function overloading is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!