Ok my assignment has me doing vector math with some canned code provided for me by the instructor This is the header file to the class I'm working with and the .cpp file as far as I've gotten it.
#pragma once
#include "Scalar.h"
class Vector2D
{
public:
Vector2D();
Vector2D( const Vector2D& ) ; // copy constructor
Vector2D( Scalar element[2] ) ; // initialize with an array
Vector2D( double x, double y ) ;
Scalar& operator [] ( int index ) ; // use to both read and write elements, just like a normal array
Scalar operator [] ( int index ) const ; // use to read elements from const vectors
Scalar Length() ;
void Normalize() ;
// Scalar-Vector product
voidoperator - ( void ) ; // negate a vector
voidoperator *= ( Scalar ) ;
voidoperator /= ( Scalar ) ;
Vector2D operator * ( Scalar ) const ; // for the case when the operand order is Vector * Scalar
friend Vector2D operator * ( Scalar, Vector2D& ) ; // for the case when the operand order is Scalar * Vector
// vector addition
Vector2D operator + ( Vector2D& ) const ;
Vector2D operator - ( Vector2D& ) const ;
voidoperator += ( Vector2D& ) ;
voidoperator -= ( Vector2D& ) ;
// the Dot-Product
Scalar operator * ( Vector2D& ) const ;
// Construct a vector that is orthogonal (perpendicular) to the given vector
Vector2D Orthogonal() const ;
booloperator == ( const Vector2D& ) const ;
booloperator != ( const Vector2D& ) const ;
// use this to test whethere or not a vector == zero vector
// it returns a reference to a constant static vector full of 0's
staticconst Vector2D& Zero_Vector() ;
protected:
staticconstint dimension = 2 ;
Scalar v[dimension] ;
};
#include "Vector2D.h"
Vector2D::Vector2D()
{
for(int i=0;i<dimension;i++) v[i]=0.0f;
}
Vector2D::Vector2D(const Vector2D& other)
{
*this=other;
}
Vector2D::Vector2D(double x, double y)
{
v[X] = Scalar( x );
v[Y] = Scalar( y );
}
Vector2D:: Vector2D(Scalar element[2])
{
for(int i=0;i<dimension;i++)
v[i]=element[i];
}
Scalar& Vector2D::operator[](int index)
{
return v[index];
}
Scalar Vector2D::operator[](int index) const
{
return v[index];
}
Scalar Vector2D::Length()
{
Scalar lengthSquared=0.0;
write a for loop that computes length squared
return Math:: <--then fill-in the blank here that returns the length using sqrt
}
I'm having trouble seeing which data members I'm multiplying together and what the initial state, continuing state, and after loop action I'm supposed to be using in the for loop.