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.

 ``123456789101112131415161718192021222324252627282930313233`` ``````#include 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; }``````

 ``12345678910111213141516171819202122232425`` ``````#ifndef THREEDVEC_H #define THREEDVEC_H #include 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 ``````

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include "ThreeDVec.h" #include 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.