Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

Students also viewed these Programming questions