Date: Mon, 11 Nov 1996 17:23:53 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Wed, 06 Nov 1996 04:29:43 GMT
Content-length: 4494
CS110, Program 1
Program 1 -- Polygons on the March
Due Date: Wednesday, November 13
Some Background
A polygon is a flat shape with 3 or more sides, all of which
are straight (e.g. a triangle is a 3-sided polygon). When all the
sides of a polygon have the same length, the polygon is called
regular. Equilateral triangles and squares are regular
polygons with 3 and 4 sides respectively.
All regular polygons can be fit perfectly within a circle (such that the
circle touches all the corners of the polygon). This circle is called
the circumscribed circle.
The Problem
You are to write a program that will perform a few calculations on
regular polygons. Your program will ask the user (1) how many sides
the polygon has, and (2) what the length of each side is. Remember,
all sides have the same length so part (2) is just one question! The
number of sides should be stored in an integer variable, and all other
variables should be of type double.
As output, your program will display (1) the area of the polygon,
and (2) the radius of the circumscribed circle. Just use the formulas
given below; you don't need to understand them at all!
In addition to the requirements above, print a welcoming message when the
program starts and an exiting message when the program ends (see
sample printout; use any messages you like!).
Finally, put a comment at the beginning of your program briefly
describing the purpose of the program (use 1 or 2 sentences). Of
course, put your name and login name in comments at the beginning of
the program just like in assignment 0.
The Formulas
In the following equations, sides is the number of sides,
edge is the length of each side, radius is the
radius of the circumscribed circle, and area is the area of
the polygon. Note that sides and edge are what the
user enters, and radius and area are what the
program outputs. Also note that edge is squared in the formula for area.
A Sample Run
Step inside the amazing polygonator...
Number of sides? 4
Length of each side? 7.82
Area of polygon: 61.1524
Radius of circumscribed circle: 5.529575
That's all, folks!
Hints
Don't write the whole program at once! For example, start by
writing a program which only displays some messages. When that is
working, create some variables and add the input commands. Test your
input statements by redisplaying what the user has typed in. Finally,
add the math commands to finish the program.
Use pow(x,y) for calculating the square root.
For example, pow(7, 0.5) calculates the square root of 7.
Remember to use #include<math.h>, since
you will need cos(), sin(), and pow(). Of course, you also need
#include<iostream.h> in order to use
cout and cin.
Use meaningful variable names. Avoid one-letter names unless
they make your program more understandable.
Create some variables to store intermediate calculations.
Test your program on several cases for which you already know the correct
answers. For instance, see the sample run given above for a square.
Here's another case: when the number of sides is 3 and the length of each side is
2.1, the area is 1.909586 and the radius is 1.2124356.
What to turn in
Turn in the following two pages, stapled together:
(page 1) Printed listing of the source file. This is to
be done just like in program 0.
(page 2) Printed copy of your program's output when run on a
sample test case. This can be done easily as follows: After
running your program, pull down the little tab button on the upper
left hand corner of the output window (the window with INACTIVE at the
top), and select the Print option . This will send all output
generated by your program in this window to the printer.
In addition, as with all assignments, you must electronically turn in a
copy of your program's source code. Use the filename "program1.cpp".