0% found this document useful (0 votes)
30 views

Lab 09

This document discusses an object-oriented programming lab assignment on converting between objects of different classes. Specifically, it involves creating Cartesian and Polar classes to represent points in 3D Cartesian and polar coordinate systems respectively. The Cartesian class contains X, Y, Z attributes and related methods, while the Polar class contains R, Theta, Psi attributes and methods. Constructors are created to initialize the attributes and convert between the coordinate systems. Operator overloading is used to implement polar to Cartesian conversion. The main function tests conversions between the classes and displays the results.

Uploaded by

Lovely Jutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Lab 09

This document discusses an object-oriented programming lab assignment on converting between objects of different classes. Specifically, it involves creating Cartesian and Polar classes to represent points in 3D Cartesian and polar coordinate systems respectively. The Cartesian class contains X, Y, Z attributes and related methods, while the Polar class contains R, Theta, Psi attributes and methods. Constructors are created to initialize the attributes and convert between the coordinate systems. Operator overloading is used to implement polar to Cartesian conversion. The main function tests conversions between the classes and displays the results.

Uploaded by

Lovely Jutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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