Question

In: Computer Science

Define two C structures, one to represent rectangular coordinates and one to represent polar coordinates. Rewrite...

Define two C structures, one to represent rectangular coordinates and one to represent polar coordinates. Rewrite the rec_to_polar function to use variables declared using the new structures.

Solutions

Expert Solution

thanks for the question, here is the code in C language, I have created the two structures, however the function rec_to_polar was not shared, I have assumed the function will take in a rectangular struct object and return a polar struct object.

Hope this helps, let me know for any help with any other question.

here is the code.

===============================================================

#include<stdio.h>

#include<math.h>

struct RectangularCordinate{

               

                float x;

                float y;

};

struct PolarCordinate{

               

                float radius;

                float theta;

};

struct PolarCordinate rect_to_polar(struct RectangularCordinate rect){

               

                float radius = pow(rect.x*rect.x + rect.y*rect.y,0.5);

                float angle = atan(rect.y/rect.x);

               

                struct PolarCordinate pol = {radius,angle};

               

                return pol;

}

int main(){

               

                struct RectangularCordinate rect {3,4};

               

                struct PolarCordinate pol = rect_to_polar(rect);

               

                printf("Radius: %.2f\n", pol.radius)          ;

                printf("Angle: %.2f\n", pol.theta)              ;

}

===============================================================


Related Solutions

Determine the following for a point with the rectangular coordinates (1.380, 2.690) m. (a) the polar...
Determine the following for a point with the rectangular coordinates (1.380, 2.690) m. (a) the polar coordinates r and θ (Enter your answers to at least three significant figures.) r = m θ = ° (b) the rectangular coordinates of the point with the polar coordinates (2r, θ) x = m y = m (c) the rectangular coordinates of the point with the polar coordinates (r, 2θ) x = m y = m
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your...
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your program. Define each structure with exactly three members (each member has to be a different datatype). You may set them up whichever way you want. Don’t forget your semicolons. - Inside main, declare two structures. One for each of the two structures you defined. - Then, initialize each one of the members manually (the three members of your first structure and the three elements...
Separate the wave equation in two-dimensional rectangular coordinates x, y. Consider a rectangular membrane, rigidly attache...
Separate the wave equation in two-dimensional rectangular coordinates x, y. Consider a rectangular membrane, rigidly attache to supports along its sides, such that a ≤ x ≤ 0 and b ≤ y ≤ 0. Find the solution, including the specification of the characteristic frequencies of the membrane oscillations. In the case of a = b, show that two or more modes of vibration correspond to a single frequency
Two vectors in polar coordinates (R, θ) are given byV1 = (5.0, 125°) and V2 =...
Two vectors in polar coordinates (R, θ) are given byV1 = (5.0, 125°) and V2 = (4.0, 260°). Find the sum V1 + V2 in polar coordinates. Give the answer to 2 significant figures for the magnitude and to the nearest degree in angle. Hint: first convert the vectors to Cartesian form and add them to get the resultant vector. Then convert this resultant vector to polar form
Solve the two-dimensional wave equation in polar coordinates and discuss the eigen values of the problem.
Solve the two-dimensional wave equation in polar coordinates and discuss the eigen values of the problem.
Consider a particle that is free (U=0) to move in a two-dimensional space. Using polar coordinates...
Consider a particle that is free (U=0) to move in a two-dimensional space. Using polar coordinates as generalized coordinates, solve the differential equation for rho and demonstrate that the trajectory is a straight line.
C Language Let us define a Point type to store two-dimensional coordinates (x, y)! Write the...
C Language Let us define a Point type to store two-dimensional coordinates (x, y)! Write the following functions operating on this data type: dist(): calculates the distance between the two points received (using the Pythagorean theorem) equal(): checks if to points are equal or not read(): reads a point from the keyboard and returns it In the main, define two points, and test all these functions. When all tests are passed, solve the following task by utilizing the structure and...
Convert from rectangular to polar form and vice versa: a. ?6 b. 2√5∠135∘ c. −2 −...
Convert from rectangular to polar form and vice versa: a. ?6 b. 2√5∠135∘ c. −2 − ?2√3 d. √2∠45∘ Please show your steps because I need to understand how we reached the solution Thank you
2) Give examples of “Cartesian” and “polar” coordinates. Explain how we translate between the two coordinate systems.
2) Give examples of “Cartesian” and “polar” coordinates. Explain how we translate between the two coordinate systems.     Answer: Cartesian is ( x, y) and polar is (r, theta)3) The force table generates a force at its center by means of a hanging mass attached to a string. What formula do we use to calculate the force generated given a certain amount of hanging mass?   Answer: From newtons second law. f=ma, a=g hence f=mg4) What formula do we use to calculate...
1) Define a C struct that can be used to represent an ingredient in a recipe....
1) Define a C struct that can be used to represent an ingredient in a recipe. You must include the ingredient, the amount to use, and the unit of measurement. When allocated, the struct must be self-contained; do not rely on information being stored anywhere else in memory. 2) Define a C function that will print an array of ingredients to the standard output stream, one per line. You must use the struct definition from the first part. 3) Define...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT