Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started