Write a CC function Called DIST that calculates the distance

Write a C/C+ function Called DIST that calculates the distance between two three dimensional points and prints out the result. Also have this function calculate the amplitudes for the two point vectors, the vector dot product and the angle between the vectors. Use references to get all of the function results (distance, amplitudes, dot product and angle) returned to the main program. Test your function by using in a main program with the two inputs points P1 = (-3, 14, 7) and point P_2 = (5, -11, 13) Note there are 6 inputs for this function: x1, y1, z1 and x2, y2, z2 DIS = squareroot ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1)); Amp = squareroot (x1*x1 + y1*y2 + z1*z2); Dott = x1*x2 + y1*y2 + z1*z2; Angle = acos(Dott/(Amp1*Amp2)); After writing and testing the above function, re-write the code so that the function uses cout statements to print out the calculated results in the main program (instead of using the references) Using same format as above, write following function called CUBED that does following calculations and uses references to return the values of C1, C2 and C3 to the main program. C1 = x*x*x + y*y*y + *z*z*z; C2 = (x + y + z)/ squareroot (x*y*z); C3 = pow(x + y + z, x/y/z)/log((x + y)*(y + z)*(x + z)); After writing, test your function in a program with inputs x = 3, y = 7, z = 11

Solution

#include<bits/stdc++.h>
using namespace std;
void Dis(int x1,int y1,int z1,int x2,int y2,int z2)
{
   float dis=sqrt( (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1) );
   cout<<\"Distance is \"<<dis<<endl;
}

void Amp(int x1,int y1,int z1)
{
   float amp=sqrt(x1*x1+y1*y1+z1*z1);
   cout<<\"Amplitude of (\"<<x1<<\", \"<<y1<<\" ,\"<<z1<<\")is \"<<amp<<endl;

}

void Dott(int x1,int y1,int z1,int x2,int y2,int z2)
{
   float dot=(x1*x2+y1*y2+z1*z2);
   cout<<\"Dot product is \"<<dot<<endl;

}

void Angle(int x1,int y1,int z1,int x2,int y2,int z2)
{
   float amp1=sqrt(x1*x1+y1*y1+z1*z1);
   float amp2=sqrt(x2*x2+y2*y2+z2*z2);
   float dot=(x1*x2+y1*y2+z1*z2);
   float Angle=acos(dot/(amp1*amp2));
   cout<<\"Angle is \"<<Angle<<endl;
  

}


int main(int argc, char const *argv[])
{
   int x1=-3,y1=14,z1=7,x2=5,y2=-11,z2=13;
   Dis(x1,y1,z1,x2,y2,z2);
   Amp(x1,y1,z1);
   Amp(x2,y2,z2);
   Dott(x1,y1,z1,x2,y2,z2);
   Angle(x1,y1,z1,x2,y2,z2);
   return 0;
}

==============================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ amp.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Distance is 26.9258
Amplitude of (-3, 14 ,7)is 15.9374
Amplitude of (5, -11 ,13)is 17.7482
Dot product is -78
Angle is 1.85017

 Write a C/C+ function Called DIST that calculates the distance between two three dimensional points and prints out the result. Also have this function calculat
 Write a C/C+ function Called DIST that calculates the distance between two three dimensional points and prints out the result. Also have this function calculat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site