Hi I'm new to C++ and would really appreciate if someone could help me. How do you exactly put the friend function into this program? Not that I haven't tried. I really have no idea where to put and what to change. My program is grouped into three different parts. Thank you in advance =D
#ifndef DISTANCE_H
#define DISTANCE_H
class Distance {
public:
Distance(int = 0, int = 0, int = 0);
Distance distance ( const Distance &);
void print(void);
void printDistance();
private:
int x, y, z;
double d;
};
#endif
#include <iostream>
#include <cmath>
using namespace std;
#include "distance.h"
Distance::Distance(int a, int b, int c)
{
x = a;
y = b;
z = c;
}
Distance Distance::distance(const Distance &h)
{
Distance k;
int w;
k.x = x - h.x;
k.y = y - h.y;
k.z = z - h.z;
w = pow(k.x,2)+pow(k.y,2)+pow(k.z,2);
k.d = sqrt(w);
return k;
}
void Distance::print()
{
cout << "[ "<< x << ", "<< y << ", "<< z << " ]";
}
void Distance::printDistance()
{
cout << d;
}
#include "Distance.h"
#include "distance.cpp"
void main(){
int i,j,k,l,m,n;
cout << "Enter three points in XYZ plane: ";
cin >> i >> j >> k >> l >> m >> n;
Distance p0(i,j,k), p1(l,m,n), p2;
p2 = p1.distance(p0);
cout << " The distance between ";
p0.print();
cout << " and ";
p1.print();
cout << " is " ;
p2.printDistance();
cout <<endl;
}