Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code below defines a class Point that represents a point on the coordinate plane. A Segment should connect two points (its end points). When

The code below defines a class Point that represents a point on the coordinate plane. A Segment should connect two points (its end points). When we make a segment, we will give the constructor the addresses of two points - we want the segment to use those points as its endpoints. The segment should link to those points, not make copies of them. (Aggregation) Finish the Segment class by making a constructor that accepts the addresses of two points and adding member variables. Code:

#include #include

using namespace std;

class Point { private: int x = 0; int y = 0; public: Point(int xVal, int yVal) { moveBy(xVal, yVal); } string toString() { return to_string(x) + ", " + to_string(y); } void moveBy(int xVal, int yVal) { x += xVal; y += yVal; } };

class Segment { public: string toString() { return p1->toString() + " to " + p2->toString(); }

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

//YOUR_CODE - constructor and member variables

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

};

int main() { Point A(0, 0); Point B(4, 4);

Segment s1(&A, &B);

cout << s1.toString() << endl; B.moveBy(1, 1); cout << s1.toString() << endl; }

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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

What is sociology and its nature ?

Answered: 1 week ago

Question

What is liquidation ?

Answered: 1 week ago

Question

Explain the different types of Mergers.

Answered: 1 week ago

Question

Project management skills and/or experience desirable

Answered: 1 week ago