Question: class Vec3d { public: static double dot(const Vec3d& a, const Vec3d& b); }; int main() { // Main() Section 1 const Vec3d a(1.0,2.5,3.5); // double

class Vec3d {
public:
static double dot(const Vec3d& a, const Vec3d& b);
};
int main() {
// Main() Section 1
const Vec3d a(1.0,2.5,3.5); // double precision!
const Vec3d b(2.0); //(2,0,0)
const Vec3d c(2.0,3.5); //(2,3.5,0)
const Vec3d d; //(0,0,0)
// Main() Section 2
const Vec3d e = a + d; // use friend
const Vec3d f = c - b; // use friend
const Vec3d g = -e; // use friend
// Main() Section 3
double r = dot(e, f); // regular function e.x*f.x + e.y*f.y + e.z*f.z (friend)
double s = e.dot(f); // method
double t = Vec3d::dot(e,f); // static function
// Main() Section 4
double x = e.mag(); // square root of sum of square
double y = e.magSq(); // sum of square
double z = e.dist(f); // sqrt or sum of square of diff
// Main() Section 5
cout << "a: " << a << ' ';
cout << "b: " << b << ' ';
cout << "c: " << c << ' ';
cout << "d: " << d << ' ';
cout << "e: " << e << ' ';
cout << "f: " << f << ' ';
cout << "g: " << g << ' ';
cout << "r: " << r << ' ';
cout << "s: " << s << ' ';
cout << "x: " << x << ' ';
cout << "y: " << y << ' ';
cout << "z: " << z << ' ';
}

1, Please use C++ and write the code

2.

 The main() function has been separated into several sections: Section 1: Create constructor/s to create the Vec3d objects. Section 2: Overload the three operators for vector math. Section 3: Compute the dot product as a function and as a method. Section 4: Create three methods to compute various vector properties. Section 5: Overload the << operator to output formatted Vec3d objects. Example format: (1.0,2.5,3.5)

3.

Things to remember: You should always think for each method, "Can I make this method readonly(const)?" For each line in main, think "What method would I have to write in the class to make this work?"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!