Question: C++ , please help. Design a 2D vector class called Vec. Class Vec will contain two float data members x and y, a default constructor,
C++ , please help.
Design a 2D vector class called Vec. Class Vec will contain two float data members x and y, a default constructor, a constructor from two coordinates, an add method, and a static member Vec object called "null" to represent the (0,0) null vector. Your Vec class should allow the following vectors.cpp file to run without generating any error messages.
sample result: (10, 20)
test with it with this cpp. do not modify just for testing the result...
#include#include "Vec.h" using namespace std; inline 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 n, u(1.0f,2.0f); if ( !equal(n,Vec::null) ) std::cout<<"error "; for ( int i=0; i<10; i++ ) n.add ( u ); n.print(); if ( !equal(n,Vec(10.0f,20.0f)) ) std::cout<<"error "; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
