Professional Documents
Culture Documents
Lab 09
Lab 09
Lab 09
Topic Covered: Conversion between Objects of Different Classes
Q1B. Create another class named Polar that represents a point in 3D Polar
coordinate system.
1. It has three attribute
2. R, Theta and Psi as three variables of double data type.
3. Make no argument constructor to set R, Theta and Psi equals to
0.
4. Make three argument constructor
5. The first argument changes the value of R.
6. The second argument changes the value of Theta.
7. The third argument changes the value of Psi.
8. Make one argument constructor for Cartesian to Polar
coordinates conversion.
9. So the data type of the argument would be a Cartesian
object.
10. Implement following mathematical equations for Cartesian
to Polar coordinates conversion.
−1 z
( ) , ψ=tan ( yx )
r =√ x 2 + y 2 + z 2 , θ=cos r
−1
1
11. Make Show() function to show the value of R, Theta and Psi on
screen.
12. Now make operator overloading of Cartesian data type for Polar
to Cartesian coordinates conversion.
13. Implement following mathematical equations for Polar to
Cartesian coordinates conversion.
x=r sin ( θ ) cos ( ψ ) , y=r sin ( θ ) sin ( ψ ) , z=r cos ( θ )
Z = r cos(θ)
P(x,y,z) in Cartesian
P(r,θ,ψ) in Polar