Program Requirements Part 1 Polar Rectangular Conversation A
Solution
#include <math.h>   //library for trignometric functions used
 #include <stdio.h>
 int main()
 {
 double a,b,x,y,m,ang;
 char c;
 cout<<\"Enter The coordinates Followed By R/r or P/p :\";
 cin>>a>>b>>c;     //reading the coordinates and character following them
 if(c=\'r\'||c=\'R\') //check whether to see the character indicate rectangular coordinates
 {
 x=a;
 y=b;
//calculate polar coordinates
 m=sqrt((x*x)+(y*y));
 ang=atan(y/x);
//print the cooordinates
 cout<<\"Rectangular (\"<<x<<\",\"<<y<<\")\";
 cout<<\"polar coordinates (\"<<m<<\" & \"<<ang<< \")\";
}
 else if(c=\'p\' ||c=\'P\') //check if the character represent polar coordinates
 {
 m=a;
 ang=b;
//calculate the rectangular coordinates
 x=m*cos(ang);
 y=m*sin(ang);
//print the coordinates
 cout<<\"Rectangular (\"<<x<<\",\"<<y<<\")\";
 cout<<\"polar coordinates (\"<<m<<\" & \"<<ang<< \")\";
 }
 else   //if the inpuut format mismatch print the message to user
 cout<<\"Illegal input format\";
 cout<<\"\ \ Press any key to continue . . .\";
//to read input character from user to continue
 cin>>c;
 return (0);
 }

