Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C/C+ function called Rect_Polar that converts rectangular(x, y) co-ordin

ID: 3789302 • Letter: W

Question

Write a C/C+ function called Rect_Polar that converts rectangular(x, y) co-ordinates to polar co-ordinates (R, theta). Use references to return values of R and theta to the main program. Test your function in a program that uses inputs x=12, y=12: R = squareroot (x*x + y*y); theta = (180/pi)* atan2(y, x); Write a C/C+ function called Polar_Rect that converts polar to rectangular co-ordinates (X, Y) for a program with inputs R = 10, theta = 30 degree. Use references to return values of X and Y to the main program. X = R*cos(theta *pi/180); Y = R*sin(theta*pi/180); Write a C/C+ function called FACTORR that is used to calculate factorials for an input integer N Use a return statement to return value of Factorial to the main program. Test your function in a program that calculates the factorial for an input N = 9 and N = 12 Note you will need a for or while loop that re-multiplies the factored number by its previous product. Int FACTORR(int N) {

Explanation / Answer

//C++ program for 3 no. problem statement

#include <iostream>
#include <bits/stdc++.h>
#define pi 3.14
using namespace std;

//This function converts the rectangular (X,Y) coordinates to polar coordinates.

//This function uses reference variables.

void Rect_Polar(int &x,int &y,int &rect,int &theta)
{
   rect=sqrt(x*x+y*y);
   theta=(180/pi)*atan2(y,x);
}
int main()
{
   int x=12;
   int y=12;
   int r=0,theta=0;
   Rect_Polar(x,y,r,theta);
   cout<<"r="<<r<<" ";
   cout<<"theta="<<theta<<" ";
   return 0;
}

Output :

G580:~/codes/schegg$ g++ RectTheta.cpp
G580:~/codes/schegg$ ./a.out
r=16
theta=45

//4. C++ program for which converts polar to rectangular coordinates.

#include <iostream>
#include <bits/stdc++.h>
#define pi 3.14
using namespace std;
//This function coverts the polar to rectangular coordinates .

//This function make use of reference variables.
void Polar_Rect(int &x,int &y,int &rect,int &theta)
{
   x=rect*cos(theta*pi/180);
   y=rect*sin(theta*pi/180);
}
int main()
{
   int x=0,y=0;
   int r=10,theta=30;
   Polar_Rect(x,y,r,theta);
   cout<<"X="<<x<<" ";
   cout<<"Y="<<y<<" ";
   return 0;
}

//Output :

G580:~/codes/schegg$ g++ RectTheta.cpp
G580:~/codes/schegg$ ./a.out
X=8
Y=4
G580:~/codes/schegg$

//5. C++ program for calculating factorial of a given number


int FACTORR(int n) //Function which calculate factorial of given number and return answer
{
   int fact=1;
   for(int i=1;i<=n;i++)
   {
       fact=fact*i;
   }
   return fact;
}
int main()
{
   int n1=9;
   int n2=12;
   cout<<"Factorial of 9 is : "<<FACTORR(n1);
   cout<<" Factorial of 12 is : "<<FACTORR(n2);
   return 0;
}

//Output :

-G580:~/codes/schegg$ g++ fact.cpp
-G580:~/codes/schegg$ ./a.out
Factorial of 9 is : 362880
Factorial of 12 is : 479001600

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote