COMP 141 Project 4: Geometry

You will write a program that allows the user to compute measurements of various geometric shapes using a menu-driven interface.

About functions

Now that we are beginning to write longer programs, we will practice dividing our programs into functions. This is a critical habit to develop, because building a program out of functions that work together enables faster software development, because functions can be tested individually, then combined together into larger functions.

When first thinking about a program, try to envision it as a set of components that all fit together like a puzzle, where each component handles a separate, distinct task. Consider making separate tasks into separate functions. Now this idea can be taken to the extreme, which is not helpful, as using too many functions, especially if these functions all need access to the same variables, ends up being very messy because you have to write functions that take, for instance, ten arguments. Try to find a balance between too many functions and too few.

About the pledge

As we being to write more complicated programs, it is not uncommon to get stuck. However, as the syllabus states, all homework assignments you complete outside of class must be entirely your own work. You should not discuss the programs with other students, look at anyone else's code, nor share your code with anyone else. The only exceptions, of course, are the official course tutors and the instructor.

I'm asking everyone to please include the honor pledge in the comments at the top of your programs indicating you have conformed to the request to work individually. (See the instructions about comments for the text to include.)

Note that I'm not saying you can't talk to any other students about anything, just don't discuss the homework. Feel free to talk to each other with notes, examples from class, and general concepts.

OK, enough administration stuff. On to the actual program!

What you need to do

First, write five functions that compute and return the following: If you write these functions correctly, none of them should contain input statements or print statements. Each one interacts with outside functions only through parameters and return values.

Second, write your main() function to do this:

You may assume the user will type in the name of the shape either in all lowercase, or with a capital first letter (i.e., your program should work correctly for both "ring" and "Ring"). You do not have to handle any other type of capitalization. If the user types in an invalid shape name (like "RiNg" or "trapezoid"), your program should print an appropriate error message.

Testing your program

You should test your program thoroughly to make sure all of your shape functions work. You may assume the user will never give "bad" input --- the user will always type in integers for the numbers, and never negative numbers or zero.

Sample interaction

Note that this is only a sample. Your program should work with any order of shapes the user wants.
What shape do you want? square
What is the side length? 7
The area of the square is 49
Do you want to calculate another area? yes

What shape do you want? rectangle
What is the length? 8
What is the width? 5
The area of the rectangle is 40
Do you want to calculate another area? yes

What shape do you want? prism
What is the length? 6
What is the width? 5
What is the height? 4
The surface area of the prism is 148
Do you want to calculate another area? yes

What shape do you want? Hexagon
I don't know that shape.
Do you want to calculate another area? yes

What shape do you want? square
What is the side length? 5
The area of the square is 25
Do you want to calculate another area? yes

What shape do you want? ring
What is the outer radius? 6
What is the inner radius? 4
The area of the ring is 62.83185307179586

What shape do you want? Circle
What is the radius? 6
The area of the circle is 113.03999999999999
Do you want to calculate another area? no

What to turn in

Through Moodle, turn in your code as a file called geometry_yourLastName_yourFirstName.py.

Hints

Challenge Problems

Do not work on these until you have completely solved the basic assignment.