CPSC120A
Fundamentals of Computer Science I

Lab 7

Fruitful Functions

Use the command line to create a new directory called lab7 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Temperature

Create Python functions called convert_fahrenheit_to_celcius and convert_celcius_to_fahrenheit in a file called temperature.py. The convert_fahrenheit_to_celcius function should take a temperature in fahrenheit and return the equivalent temperature in celcius. The convert_celcius_to_fahrenheit function should take a temperature in celcius and return the equivalent temperature in fahrenheit. A temperature in fahrenheit can be converted to celcius by using the following equation:

C = (F − 32) ⋅ (5 / 9)

Where C is degrees celcius and F is degrees fahrenheit. To help test your code, water boils at 212 ∘ F and freezes at 32 ∘ F.

Pentagon

Create a Python function called draw_pentagon in a file called pentagon.py. The function should use Pygame to draw a regular pentagon, the length of each side is equivalent. The function should have three parameters, the x and y coordinates of the center of the pentagon and the size of the pentagon specified as the distance from the center to any of its vertices. Note, because the pentagon is regular all of the vertices lie on a circle with a radius equivalent to the size of the pentagon.

Use the following equations to compute the x and y coordinates of the pentagon's vertices:

px = r ⋅ cosθ + cx
py = r ⋅ sinθ + cy

where (px, py) is a point on the circle with radius r and center (cx, cy). Also note that because the pentagon is regular the difference in angle between neighboring vertices is always 360 / 5 = 72 degrees.

Design Document

Create a design document for your assignment 2 program, on paper. The functionality of the program is limited by the assignment requirements, and determining the structure of the program is part of the assignment. So the design document should only include an illustration of the program's appearance.

Once you have completed your design document, please show it to me for approval.

Submission

Make sure all of your .py files have your name in a comment at the top of the file. Create a tar file of your lab7 directory by navigating to your labs directory, using the cd command. Then, issue the following command.

    tar czf tarfilename.tgz lab7/

To verify that the tgz file contains your code run the following command. It should list all of your .py files.

    tar tzf tarfilename.tgz

To submit your activity, go to cseval.roanoke.edu. You should see an available assignment called Lab Activity 7. Click the submit button and choose the tgz file you created to upload. Only one person per group needs to submit.

Be sure to also copy or email the tgz file to your partner. To extract the files in a tgz file from the terminal use the following command:

    tar xzf tarfilename.tgz

Submission

Please show your source code and run your test cases for the instructor or lab assistant. Only a program that has perfect style, thorough test cases, and flawless functionality will be accepted as complete.