Question: In C++, esign and write a Point class, simulating a 2-dimensional point. The Point class needs to implement the following as member functions. Construct a

In C++, esign and write aPointclass, simulating a 2-dimensional point. ThePointclass needs to implement the following as member functions.

  1. Construct aPointobject
  2. adistance()member function, which returns the distance from the point to the origin
  3. Anangle()member function, which returns the angle the point makes with the positive x-axis
  4. Atranslate()member function, which translates the point in 2D space: to move a Point with coordinates (x,y) by an amount ( dx, dy ), so that the new coordinates are (x+dx, y+dy)
  5. Aprint_xy()function, which prints the point's x and y coordinates nicely on screen.
  6. Aprint_rtheta()function, which prints the point's polar coordinates (r and theta) nicely on screen. [ hint: use the distance() and angle() functions you already developed. ]

Test harness

Use the test harness below to test your class:

#include

#define MY_PI (acos(-1)) // This will come in useful later!

//

int main()

{

Point p1(3.0,5.0) ;

p1.print_xy(); cout

p1.translate (-1, 1) ;

p1.print_xy(); cout

return 0;

}

Steps to follow

  1. For the requirements spec: find expected value for p1, in (x,y) and (r, theta), before and after the translation above
  2. Copy the smallmain()into your project, and write a skeleton version of the class.
  3. One by one, fill out the functions in the class definition with real code. Write a little, build a little...

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 Programming Questions!