Homework 5

Due Sunday, Feb. 13, before 11:30pm

For some of these problems this week, you may want to use functions in the math library.

#include < math.h >Some prototypes for math library functions that you may find useful:

double sin(double x); // returns the sine of x, where x is given in radians double cos(double x); // returns the cosine of x, where x is given in radians double sqrt(double x); // return the sqrt of x, don't pass a negative valueThere is also a constant defined for the value of pi, named

`M_PI`

,
that you can use, and in case you forgot how to convert degrees to radians,
use the relation:
radians pi ------- = --- degrees 180Also, if you'd like, you can look at the man page for the sqrt, sin, cos, etc. functions. Here is how to veiw the man page for the sin function:

% man sin # hit the space bar to scroll down the displayed man pageHere is more information about man pages (I'll talk about man later in the semester too).

You can look at the header file for the math library, but unlike the Roberts' library header files, it is pretty difficult to read, so I wouldn't suggest doing so. However, if you are curious, it is here:

/usr/include/math.h

**7.1, Crossed Box Program****Draw a 3D box**. Write a program that prompts that user to enter values for x, y, width and height, and draws a 3-D box with its lower left hand front corner of the box at (x,y). You can decide the perspective of your 3D view (it doesn't have to be exaclty like the example below), but it cannot be a head-on veiw. For example, the call to your function, Draw3DBox(2.0, 1.0, 3.0, 2.0), may result the following being drawn:

**7.3, Draw a Heart****Pyramid of boxes program (like 7.2 but with a modification).**For this program, write a**function, DrawPyramid**, that takes the number of levels of boxes in the pyramid as input and prints out a pyramid of boxes, that just fit inside the graphics window (each box in a pyramid with three levels is larger then each box in a pyramid with 20 levels). Your program should prompt the user to enter a number of levels between 2 and 20, and then call your DrawAPyramid function to draw the pyramid. For example:This program draws a pyramid of boxes in the graphics window enter values for the number of levels between 20 and 2: 1 hey, 1 isn't between 2 and 20 enter values for the number of levels between 20 and 2: 21 hey, 21 isn't between 2 and 20 enter values for the number of levels between 20 and 2: 20 Press return to exit.

Draws:

If the user enters 5 instead:

This program draws a pyramid of boxes in the graphics window enter values for the number of levels between 20 and 2: 5

Your program will draw: