Homework #9
- Goal:
Learn to use the square root and cosine functions in the mathematical
library.
- Please UPLOAD your homework (ZIP or RAR file) to TA at
http://ms11.voip.edu.tw/cs102/
- Deadline: 2008/4/19 11:00 AM
- Background:
-
In Visual C++, sqrt()
is a function in Math class which
returns the square root of a specified number, while
the cos()
function takes an angle and returns the ratio of two sides of a right
triangle. The ratio is the length of the side adjacent to the angle
divided by the length of the hypotenuse.
-
M_PI is a constant with the value pi, while
M_PI_2 is a constant with the value pi/2.
- Be sure to include <math.h> in your C++ program to access these
functions and constants.
- Also see the file VisualStudio8\VC\include\math.h for other popular constants.
- To use these math constants, you have to define _USE_MATH_DEFINES before
the #including math.h.
-
Let w = cos(2*pi/n) + i sin(2*pi/n).
Write a program to take the input n, and
print out the complex number w, and the result of
1 + w + w^2 + w^3 + ... + w^(n-1).
- Note: Overload the operator^ to be the integer power over a complex number,
i.e., w^3 = w * w * w. In this exercise, you may assume the integer power to be
non-negative.