Help with overloading

My task is to implement the output shown in the first attached code file. I, unfortunately, am attempting to learn a lot of this as I go, so I'm really lost. My code is extremely mangled right now so really anything helps. I'm not sure what to do with my constructor. I think I only need one if I use getters and setters (not defined yet), but I don't know. My main issue is in overloading. I don't understand it. I know...RTFM. I would love to, but I won't have access to a computer for at least a day, so I'm leaving this here hoping for some direction.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "ThreeDVec.h"

int main()
{
  ThreeDVec A;
  cout << "A is " << A << endl << endl;
  ThreeDVec X(1,0,0), Y(0,1,0), Z(0,0,1);
  cout << "X+Y+Z is " << X+Y+Z << endl << endl;

  ThreeDVec B(3,4,5);
  cout << "B is " << B << endl;
  cout << "||B|| is " << B.magnitude() << endl;
  cout << "B dot Y is " << B*Y << endl << endl;;
  
  ThreeDVec C(X+Y+Z);
  cout << "C is " << C << endl;
  cout << "B cross C is " << (B^C) << endl;
  cout << "B dot (B cross C) is " << B*(B^C) << endl << endl;

  ThreeDVec D;
  cout << "Enter your vector coefficients as x y z:  ";
  cin >> D;
  cout << "D is " << D << " with magnitude " << D.magnitude() << endl;
  ThreeDVec E=D*(1/D.magnitude());  // This is a scalar multiplying a vector
  cout << "Normalized D is |" << E << "| = " << E.magnitude() << endl << endl;

  return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef THREEDVEC_H
#define THREEDVEC_H

#include <iostream>
using std::ostream;

class ThreeDVec
{
public:
  ThreeDVec(int,int,int);
  ThreeDVec operator* (const ThreeDVec& vector);
  ThreeDVec operator^ (const ThreeDVec& vec1);
  //ThreeDVec operator^ (const ThreeDVec& vec1, const ThreeDVec& vec2);
  ThreeDVec operator* (const double k);
  double magnitude();
  ThreeDVec operator+ (const ThreeDVec& vec1);
  ostream& operator<< (ostream& , const ThreeDVec&);

private:
  double a, b, c;


};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "ThreeDVec.h"
#include<cmath>

using namespace std;

ThreeDVec::ThreeDVec (int a, int b, int c)
{
}

ostream& operator<< (ostream& , const ThreeDVec&)
{
}
/*ThreeDVec operator* (const ThreeDVec& vector)
{
  ThreeDVec vec;

  vec.setX(this.getX() * vector.getX()); 
  vec.setY(this.getY() * vector.getY());
  vec.setZ(this.getZ() * vector.getZ());

  return vec;
}*/

ThreeDVec operator^ (const ThreeDVec& vec1)
{

}

ThreeDVec operator* (const ThreeDVec& vec1, const double k)
{
  //vec1.getX() * k;
}

ThreeDVec operator+ (const ThreeDVec& vec1)
{

}
Topic archived. No new replies allowed.