I can't speak english very well, sorry. I am having a problem with a practice question given to me. I am asked to write a code that finds the distance between 2 points in 3D space according to their x, y and z coordinates. But while doing this, it wants me to use the class structure, use the get-set functions, use the concepts of public and private, and overload the "*" operator to find the distance. I wrote a code and it gives correct result but it does not meet the desired conditions. I would really appreciate if you could help. thank you so much.
#include<iostream>
#include<math.h>
using namespace std;
class coordinat
{
private:
int x1, y1, z1, x2, y2, z2;
public:
void get()
{
cout << "1. point X value: ";
cin >> x1;
cout << "1. point Y value: ";
cin >> y1;
cout << "1. point Z value: ";
cin >> z1;
cout << "2. point X value: ";
cin >> x2;
cout << "2. point Y value: ";
cin >> y2;
cout << "2. point Y value: ";
cin >> z2;
}
void calculate()
{
float distance;
distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2));
cout << "Distance between 2 points: " << distance << endl;
}
};
int main()
{
coordinat c;
c.get();
c.calculate();
return 0;
}