Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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!

use vectors.cpp file to test the output

#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 << "Test 1 passed! ";

else cout << "error1 ";

v.set( 1.0f, 2.0f );

if( equal( v, w ) == true ) cout << "Test 2 passed! ";

else cout << "error2 ";

for( int i = 0; i < 10; i++ )

u.add( w );

u.print();

if( equal( u, Vec( 10.0f, 20.0f ) ) == true ) cout << "Test 3 passed! ";

else cout << "error3 ";

cout << "Finished! ";

return 0;

}

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

2+1+(g)+02(g)2H(H(g) Arswer

Answered: 1 week ago

Question

How might mobile HR affect the various HR functions?

Answered: 1 week ago