Using template convert rectangular coordinate to polar using single argument constructor in polar

0 votes
asked Sep 6 by (140 points)
//Help to debug the program it shows error with single arument constructor in class polar

template <class T>
class rectangular

{

public:

T xco,yco;

rectangular():xco(0),yco(0){}

rectangular(T x,T y):xco(x),yco(y){}

void display_rect()

{
cout<<"rectangular coordintaes:"<<xco<<","<<yco<<endl;

}

};

template <class S>

class polar

{

S radius,angle;

public:

polar();radius(0),angle(0){}

polar(rectangular r)

{

radius=sqrt(r.xco*r.xco+r.yco*r.yco);

angle=atan(r.yco/r.xco);

}

void display_polar()

{

cout<<"polar coordinates is"<<radius<<","<<angle<<endl;

}

};

void main()

{

polar<double> p;

rectangular <double> r(4.71,30.56);

p=r;

p.display_rect();

cout<<"After conversion"<<endl;

p.display_polar()

}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...