Answer to Question #174665 in C++ for zain ul abdeen

Question #174665

Make two 3D-points in a 3-Dimensional space. Calculate the distance between these two points. Instead of integer data type, use any other datatype for x,y,z values. Create an object pt, and call distance function as pt.Distance(pt2), which will calculate the distance between two 3-D points.


1
Expert's answer
2021-03-23T08:09:43-0400
#include <bits/stdc++.h> 
#include <iomanip> 
#include <iostream> 
#include <math.h> 

using namespace std; 

  
// function to print distance 

void distance(float x1, float y1,  

            float z1, float x2,  

            float y2, float z2) 
{ 

    float d = sqrt(pow(x2 - x1, 2) +  

                pow(y2 - y1, 2) +  

                pow(z2 - z1, 2) * 1.0); 

    std::cout << std::fixed; 

    std::cout << std::setprecision(2); 

    cout << " Distance is " << d; 

    return; 
} 

  
// Driver Code 

int main() 
{ 

    float x1 = 2; 

    float y1 = -5; 

    float z1 = 7; 

    float x2 = 3; 

    float y2 = 4; 

    float z2 = 5; 

      

    // function call for distance 

    distance(x1, y1, z1,  

            x2, y2, z2); 

    return 0; 
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS