Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago