Question: Write a class ThreeDPoint that inherits from TwoDPoint and adds a z coordinate. You should not use composition or create your own x and y

Write a class ThreeDPoint that inherits from TwoDPoint and adds a z coordinate. You should not use composition or create your own x and y variables. ThreeDPoint should only need to worry about its z value. You will need to implement a constructor that takes three ints (x, y, z).

#include using namespace std;

class TwoDPoint { private: double x; double y; public: TwoDPoint(int xLocation, int yLocation) { x = xLocation; y = yLocation; } void print() const { cout << x << ", " << y; } };

//Do not modify anything on or above the line below this //YOUR_CODE_BELOW

//YOUR_CODE

//YOUR_CODE_ABOVE //Do not modify anything on or below the line above this

int main() { cout << "(Only checking x, y)" << endl; ThreeDPoint p1(1, 2, 3); TwoDPoint p2 = p1; //should copy the twoD part of p1 p2.print(); cout << endl; ThreeDPoint p3(0, 0, 0); TwoDPoint p4 = p3; //should copy the twoD part of p3 p4.print(); }

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!