You are on page 1of 2

Object Oriented Programming

Lab 09
Topic Covered: Conversion between Objects of Different Classes

Q1A. Create a class named Cartesian that represents a point in 3D


Cartesian coordinate system.
1. It has three attribute
2. X, Y and Z as three variables of double data type.
3. Make no argument constructor to set X, Y and Z equals to 0.
4. Make three argument constructor
5. The first argument changes the value of X.
6. The second argument changes the value of Y.
7. The third argument changes the value of Z.
8. Make Get_X() function to return value of X.
9. Make Get_Y() function to return value of Y.
10. Make Get_Z() function to return value of Z.
11. Make Show() function to show the value of X, Y and Z on screen.

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 ( θ )

Q1C. Make main() function


Write code for Polar to Cartesian Coordinates conversion and vice
versa.
Show the results on screen.

Here is the output of program

Z = r cos(θ)

P(x,y,z) in Cartesian
P(r,θ,ψ) in Polar

X = r sin(θ) cos(ψ) r sin(θ)


Y = r sin(θ) sin(ψ)

You might also like