Write a CC function Called DIST that calculates the distance
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

