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

The equations x = r cos (), y = rsin(),r 2 = x 2 + y 2 ,and tan() = y/x define t

ID: 3613063 • Letter: T

Question

The equations x = r cos (), y = rsin(),r2 = x2 + y2 ,and tan() = y/x  define the relationship betweenCartesian coordinates (x,y) and polar coordinates (r,)

In order to do this assignment, you will need the mathematicsfunctions sin, cos, andtan. These functions are in the mathematicslibrary. You need to include this library in your program(i.e. the statement: #include <math.h> must beadded to your program). The sin,cos, and tan functions expects adouble value angle as anargument, and returns the double value as aresult. The value for angle must be inradians. For example, sin(/2) =1. Note /2 = 90°.

Suggested help for completing the assignment: Firstwrite a program that prompts the user to select the type ofconversion, prompts the user for each coordinate, and then displaysthe converted coordinate on the monitor screen. When you aresatisfied with the behavior of this program, modify the program toread in coordinates from an input file and put the result in theoutput file convert.out.

Explanation / Answer

please rate - thanks run # 1 what do you want to do 1. convert cartesian coordinates to polar 2. convert polar coordinates to cartesian 1 what is the name of the input file? input.txt    x      y     rho    theta 13.00   23.00   26.42   60.55 10.00   50.00   50.99   78.73 program has completed run # 2 what do you want to do 1. convert cartesian coordinates to polar 2. convert polar coordinates to cartesian 2 what is the name of the input file? input1.txt    x      y     rho    theta 13.01   22.51   26.00   60.00 9.77    50.06   51.00  79.00 program has completed contents of input.txt 13 23 10 50 contents of input1.txt 26 60 51 79 code- corrected #include #include #include struct coordinates { double x; double y; double rho; double theta; } point; int main() {FILE *outfile; FILE *infile; char filename[30]; int choice; double x,y,rho,theta; outfile = fopen("convert.out","w"); printf("what do you want to do "); printf("1. convert cartesian coordinates to polar "); printf("2. convert polar coordinates to cartesian "); scanf("%d",&choice); printf("what is the name of the input file? "); scanf("%s",&filename); infile=fopen(filename,"r"); if(infile==NULL) {printf("error opening file "); return 1; } fprintf(outfile,"   x    y rho theta "); printf("   x    y rho theta ");   if(choice==1) {while(fscanf(infile,"%lf",&point.x)!=EOF)       {fscanf(infile,"%lf",&point.y);       point.rho=sqrt(pow(point.x,2)+pow(point.y,2));       point.theta=atan(point.y/point.x)*(180/3.14);       fprintf(outfile,"%.2lf %.2lf %.2lf %.2lf ",point.x,point.y,point.rho,point.theta);       printf("%.2lf %.2lf %.2lf %.2lf ",point.x,point.y,point.rho,point.theta);        } } else   {while(fscanf(infile,"%lf%lf",&point.rho,&point.theta)!=EOF)       {point.x=point.rho*cos(point.theta*(3.14/180));       point.y=point.rho*sin(point.theta*(3.14/180));       fprintf(outfile,"%.2lf %.2lf %.2lf %.2lf ",x,y,rho,theta);       printf("%.2lf %.2lf %.2lf %.2lf ",point.x,point.y,point.rho,point.theta);        }    }   fclose(infile); fclose(outfile); printf("program has completed "); getch(); return 0; }
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