Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

How is the economic production quantity different from EOQ?

Answered: 1 week ago

Question

Q: How do you recruit employees?

Answered: 1 week ago

Question

6. Vanguard

Answered: 1 week ago