Specify design and implement a class that can be used to kee
Solution
// Please see comments given with code .
// angle to be passed in PI terms +ve for anticlock and -ve for clock
// axis value to be passed for axis of rotation : x = 1 , y = 2 , z = 3
#include <iostream>
#include <cmath>
using namespace std;
#include <iostream>
using namespace std;
class TDPR
{
private :
// coordinates
double x,y,z;
// default constructor
public : TDPR()
{
}
// constructor to initialize coordinates passing x,y,z in sequence
public : TDPR
(double xc,double yc,double zc)
{
x = xc ;
y = yc ;
z = zc
;
}
// to set coordinates passing x,y,z in sequence
public : void setPoint(double xc,double yc,double zc)
{
x = xc ;
y = yc ;
z = zc ;
}
// to rotate angle in PI value ,+ve for counterclockwise and -ve for clockwise and axis as 1 for x , 2 for y and 3 for z
public : void rotate(double angle , int axis )
{
if(axis==1)
{
y = y*cos(angle) -
z*sin(angle);
z = y*sin(angle) + z*cos(angle);
}
else
if(axis==2)
{
x = x*cos(angle) + z*sin(angle);
z = z*cos(angle) - x*sin(angle);
}
else if
(axis==3)
{
x = x*cos(angle) - y*sin(angle);
y =
x*sin(angle) + y*cos(angle);
}
}
public : void showPoint
()
{
cout << \" x = \" << x <<\" y = \" << y <<\" z = \" <<
z << endl;
}
} ;
// Main Function
int main()
{
TDPR T1 ; // T1 object created without coordinates
TDPR T2(1.5,2.0,3.0); // T2 object created with coordinates
T1.setPoint(3.0,0.0,1.0); // setting coordinates for T1
T1.showPoint(); // show coordinates for T1
T2.showPoint(); // show coordinates for T2
T1.rotate(1,2); // rotate T1
T2.rotate(-1,1); // rotate T2
T1.showPoint(); // show coordinates for T1
T2.showPoint(); // show coordinates for T2
return 0;
}


