Question: Vector Class Please supply the Vec.h code in C++ Design a 2D vector class called Vec. (Note, this is not meant to represent the data

Vector Class

Please supply the "Vec.h" code in C++

Design a 2D vector class called Vec. (Note, this is not meant to represent the data structure vector, but the mathematical concept of vector used for, among other things, Cartesian coordinates.)

Your class Vec must contain the following: - two float data members called x and y - a default constructor (initialize variables to 0) - a constructor from two floats - a "set" method which takes two floats - an "add" method, which takes another Vec and adds its x and y to the local instance's x and y - a "print" method which prints out the values of x and y

Your Vec class must allow the vectors.cpp file to run without generating any error messages.

THE OUTPUT YOU ARE LOOKING FOR: Test 1 passed! Test 2 passed! (10, 20) Test 3 passed! Finished!

-------------------------------

vectors.cpp

Vector Class Please supply the "Vec.h" code in C++ Design a 2D

#include

#include "Vec.h"

using namespace std;

Vec nullvec( 0.0f, 0.0f );

bool equal( const Vec & u, const Vec& v )

{

return u.x == v.x && u.y == v.y;

}

int main( int argc, const char* argv[] )

{

Vec u;

Vec v;

Vec w( 1.0f, 2.0f );

if( equal( u, nullvec ) == true ) cout

else cout

v.set( 1.0f, 2.0f );

if( equal( v, w ) == true ) cout

else cout

for( int i = 0; i

u.add( w );

u.print();

if( equal( u, Vec( 10.0f, 20.0f ) ) == true ) cout

else cout

cout

return 0;

}

Again, please provide the C++ code for "Vec.h" that will allow the following output EXACTLY

Test 1 passed! Test 2 passed! (10, 20) Test 3 passed! Finished!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!