Create C++ classes for three dimensional vectors and points. The Vector class should implement all of the functions used in the following code:
Vector v1(1.0f, 2.0f, 3.0f);
Vector v2(v1);
Vector v3 = v1;
v3 = v1 + v2;
v1 += v2;
v3 = v1 - v2;
v1 -= v2;
v3 = v2 * 2.0f;
v3 = 2.0f * v2;
v3 *= 2.0f;
v3 = v2 / 2.0f;
v3 /= 2.0f;
v3 = -v1;
v1 == v2;
cout << "v1.x: " << v1.x() << "\n";
cout << "v1.x: " << v1[0] << "\n";
v1.set_x(0.0f);
v1[0] = 0.0f;
cout << "dot product of v1 and v2: " << Vector::Dot(v1, v2) << "\n";
cout << "cross product of v1 and v2: " << Vector::Cross(v1, v2) << "\n";
cout << "length of v1: " << v1.Length() << "\n";
cout << "v1 normalized: " << v1.Normalize() << "\n";
The Point class should implement all of the functions used in the following code:
Point p1(1.0f, 2.0f, 3.0f);
Point p2(p1);
Point p3 = p1;
Vector v1(p1); // note: this should be in the vector class
cout << "p1: " << p1 << "\n";
p3 = p1 + v1;
p3 = v1 + p1; // note: this should be in the vector class
p3 += v1;
v1 = p1 - p2;
p3 = p1 - v1;
p3 -= v1;
p1 == p2;
cout << "p1.x: " << p1.x() << "\n";
cout << "p1.x: " << p1[0] << "\n";
p1.set_x(0.0f);
p1[0] = 0.0f;
cout << "distance from p1 to p2: " << Point::Distance(p1, p2) << "\n";
To improve the efficency of your code all member functions that do not
modify this
should be accessor functions, and non-primative
parameters should be constant references. The functions should
perform input verification (divide by zero in operator/
for example)
using the cassert
library.
Tar your code in a file that contains your name and submit it on the course Inquire site.