class Point3d { public: Point3d(double x, double y, double z); Point3d(const point3d& p); void setX(double x); void setY(double y); void...

70.2K

Verified Solution

Question

Programming

class Point3d { public: Point3d(double x, double y, doublez);

Point3d(const point3d& p);

void setX(double x);

void setY(double y);

void setZ(double z);

double getX() const;

double getY() const;

double getZ() const;

point3d& operator=(const point3d& rhs); private: doublex; double y; double z;

};

Given the Point class above, complete the following:

1. Write just the signature for the overloaded addition operatorthat would add the respective x,y, and z from two point3dobjects.

2. What is the output of the code (assuming copy constructor andcopy assignment operators are properly implemented).

point3d p1{3,4,5};

point3d p2{p1};

p2.setY(2*p2.getX());

point3d* p3 = new point3d{p1.getX(), p2.getY(), p2.getZ()};

p3 = &p1; cout << *p3.getZ() << endl;

p1.setY(2*p1.getZ());

p3.setX(p2.getZ());

p1 = p2; cout << p1.getX() + “, ” p1.getY() + “, ”p1.getZ() << endl;

cout << p2.getX() + “, ” p2.getY() + “, ” p2.getZ()<< endl;

cout << p3.getX() + “, ” p3.getY() + “, ” p3.getZ()<< endl;

delete p3;

Answer & Explanation Solved by verified expert
3.5 Ratings (312 Votes)
Given codeclass Point3dpublicPoint3ddouble x double y double zPoint3dconst Point3d pvoid setXdouble xvoid setYdouble yvoid setZdouble zdouble getX    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students