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 rotatepoint 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:
hingcybrotatepoint
Please enter an x coordinate:
Please enter an y coordinate:
Please enter the number of degrees to rotate by:
The result is
Formulae:
Degrees to radians
degrees
Rotation formulae
xnewxcosysin
ynewxsinycos
Notes, hints, and reminders:
Math
The library needs to be included to access the sin and cos functions as well as the MPI constant
When you compile your program with gcc don't forget to add the lmlink 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 lflong 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 rotatedouble 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 someptr; if you actually want the pointer itself, then leave the star off.
hingcybrotatepoint
Please enter an x coordinate:
Please enter an y coordinate:
Please enter the number of degrees to rotate by:
The result is
Formulae:
Degrees to radians
degrees
Rotation formulae
xnewxcosysin
ynewxsinycos
Notes, hints, and reminders:
Math
The library needs to be included to access the sin and cos functions as well as the MPI constant
When you compile your program with gcc don't forget to add the lmlink 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 lflong 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 rotatedouble 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 someptr; 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
