Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- #include<math.h>
- class polar;
- class rect
- {
- double x,y;
- public:
- rect(double a=0,double b=0)
- {
- x=a;
- y=b;
- }
- rect(polar &k)
- {
- x=k.r*cos(k.a);
- y=k.r*sin(k.a);
- }
- void display()
- {
- cout<<"the rectangular co-ordinates:\n x = "<<x<<" and y = "<<y<<endl;
- }
- };
- class polar
- {
- double r,a;
- public:
- polar(double c=0,double b=0)
- {
- r=c;
- a=(3.14/180)*b;
- }
- polar(rect &k)
- {
- r=sqrt(k.x*k.x+k.y*k.y);
- a=atan(k.y/k.x);
- }
- polar operator+(polar &t)
- {
- polar fin;
- double x,y,z,s;
- x=r*cos(a);
- y=r*sin(a);
- z=t.r*cos(t.a);
- s=t.r*sin(t.a);
- x=x+z;
- y=y+s;
- fin.a=atan(y/x);
- fin.r=sqrt(x*x+y*y);
- return fin;
- }
- void display()
- {
- cout<<"the polar co-ordinates:\n radius is = "<<r<<" and the angle = "<<a<<endl;
- }
- };
- int main()
- {
- polar p1,p2,p3;
- rect r1;
- double x,y;
- int a,t=1,i;
- do
- {
- cout<<"enter a choice:\n";
- cout<<"1.add two polar co-ordinates\n";
- cout<<"2.convert from polar to rectangular co-ordinates\n";
- cout<<"3.convert from rectangular to polar co-ordinates\n";
- cout<<"4.exit\n";
- cin>>a;
- switch(a)
- {
- case 1:
- cout<<"enter the values of the radius and angle of the two co-ordinates:\n";
- for(i=1;i<=2;i++)
- {
- cout<<"radius and angle in degrees of "<<i<<" No.:\n";
- cin>>x>>y;
- if(i==1)
- p1=polar(x,y);
- else
- p2=polar(x,y);
- }
- p3=p1+p2;
- cout<<"the result is:\n";
- p3.display();
- break;
- case 2:
- cout<<"enter the values of the radius and angle of the co-ordinates:\n";
- cout<<"radius and angle in degrees:\n";
- cin>>x>>y;
- p1=polar(x,y);
- r1=p1;
- r1.display();
- break;
- case 3:
- cout<<"enter the values of x and y:\n";
- cin>>x>>y;
- r1=rect(x,y);
- p1=r1;
- p1.display();
- break;
- case 4:
- t=0;
- break;
- default:
- cout<<"invalid\n";
- break;
- }
- }while(t!=0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment