Answered step by step
Verified Expert Solution
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.
- Construct aPointobject
- adistance()member function, which returns the distance from the point to the origin
- Anangle()member function, which returns the angle the point makes with the positive x-axis
- 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)
- Aprint_xy()function, which prints the point's x and y coordinates nicely on screen.
- 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
- For the requirements spec: find expected value for p1, in (x,y) and (r, theta), before and after the translation above
- Copy the smallmain()into your project, and write a skeleton version of the class.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started