Question: Write a program called rotate _ point that solicits an x and y coordinate representing a point and an angle in degrees and then displays

Write a program called rotate_point that solicits an x and y coordinate representing a point and an angle in degrees and then displays the point that would result from rotating the given one about the origin by the given angle.
Example runs:
..hing/cyb126%./rotate_point
Please enter an x coordinate: 30
Please enter an y coordinate: 1
Please enter the number of degrees to rotate by: 45
The result is (20.506097,21.920310)
Formulae:
Degrees to radians
180degrees
Rotation formulae
xnew=xcos()-ysin()
ynew=xsin()+ycos()
Notes, hints, and reminders:
Math
The library needs to be included to access the sin() and cos() functions as well as the M_PI constant
When you compile your program with gcc, don't forget to add the "-lm"(link math) flag to the command
If you get an error when compiling that says "undefined reference to sin()" move the "-lm" flag to a different position in the gcc command; if you had it near the beginning, put it at the end or vice versa
"double" not "int"
Since this program uses real numbers, your variables should be of type "double"
You can get the address of a double (or anything) the same way we did for integers in the videos, with the & operator
A variable which has the type "pointer to double" is likewise declared as a "double *"
The format string to provide to scanf() when reading in a double from the user is "%lf"(long float) as "%i" only works for integers
rotate() function
While it is not necessary programmatically speaking to have a separate rotate() function, it is a requirement of this assignment to get further practice with using pointers.
Your rotate() function should accept two "double *" parameters which point to the x & y coordinates entered by the user and a simple "double" parameter which is the number of radians to rotate by
The rotate() function should have a return type of void; its results (the coordinates of the new point) will simply be saved in the memory cells designated by the pointers it receives, that is, when the function is done running, it will have changed the values associated with the pointers that were passed to it
Don't forget a function prototype for rotate() like I always do; it's function prototype should be "void rotate(double *, double *, double)"
Using pointers
Don't forget star (*) operator when working with pointers! If you want to access the value the pointer points to, you need *some_ptr; if you actually want the pointer itself, then leave the star off.
..hing/cyb126%./rotate_point
Please enter an x coordinate: 30
Please enter an y coordinate: 1
Please enter the number of degrees to rotate by: 180
The result is (-30.000000,-1.000000)
Formulae:
Degrees to radians
180degrees
Rotation formulae
xnew=xcos()-ysin()
ynew=xsin()+ycos()
Notes, hints, and reminders:
Math
The library needs to be included to access the sin() and cos() functions as well as the M_PI constant
When you compile your program with gcc, don't forget to add the "-lm"(link math) flag to the command
If you get an error when compiling that says "undefined reference to sin()" move the "-lm" flag to a different position in the gcc command; if you had it near the beginning, put it at the end or vice versa
"double" not "int"
Since this program uses real numbers, your variables should be of type "double"
You can get the address of a double (or anything) the same way we did for integers in the videos, with the & operator
A variable which has the type "pointer to double" is likewise declared as a "double *"
The format string to provide to scanf() when reading in a double from the user is "%lf"(long float) as "%i" only works for integers
rotate() function
While it is not necessary programmatically speaking to have a separate rotate() function, it is a requirement of this assignment to get further practice with using pointers.
Your rotate() function should accept two "double *" parameters which point to the x & y coordinates entered by the user and a simple "double" parameter which is the number of radians to rotate by
The rotate() function should have a return type of void; its results (the coordinates of the new point) will simply be saved in the memory cells designated by the pointers it receives, that is, when the function is done running, it will have changed the values associated with the pointers that were passed to it
Don't forget a function prototype for rotate() like I always do; it's function prototype should be "void rotate(double *, double *, double)"
Using pointers
Don't forget star (*) operator when working with pointers! If you want to access the value the pointer points to, you need *some_ptr; if you actually want the pointer itself, then leave the star off.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!