[Exercise 7] | [Content] | [Exercise 9] |
Design and implement a class to represent points in 2D space. Invent suitable methods. Verify the behaviour in simple application. Draw class diagram.
Help
Attributes
Methods
double x,y;
- set x,y coordinates according to polar ones
- set coordinates copying another object
- distance from the origin
- distance from the another point
- angle calculation (polar coordinates)
- move point - add dx, dy to the coordinates
- print coordinates in the form [x,y]
class Point { public: double x,y; void set_polar(double dist, double angle); // angle in rad void set(Point &point); // copy coordinates from the parameter double distance(Point &p); ... void move(double dx, double dy); void print(); }Inspire how to creat main application:int main(int argc, char **argv) { Point p1; cout << "Enter x coordinate: "; cin >> p1.x; cout << "Enter y coordinate: "; cin >> p1.y; cout << "Entered point: [" << p1.x << "," << p1.y << "]\n"; cout << "Distance from the origin: " << p1.distance() << endl; cout << "Angle: " << p1.get_angle() << " rad\n"; Point p2; p2.x = 10; p2.y = 5; cout << "Distance between "; p1.print(); cout << " and "; p2.print(); cout << ": "; ... return 0; }Solution:
Library: point.h, point.cpp Application: app_point.cbp, app_point.cpp
[Exercise 7] | [Content] | [Exercise 9] |