CS 110 Fall 2013 Lab 1 - Calculations

Laboratory Assignment 1: Calculations

Assigned: Monday, September 6 Due: 9:00 AM Friday September 20

Introduction

For this assignment you will write five short programs, as described.

Part 1 Peter the pool boy has a pool that needs additional water. He needs to add water to the pool from a garden hose connected to the homeowner’s house. He needs to determine, given a rate of flow, how long it will take to fill the pool to the desired depth so he can tell the homeowner when to turn the hose off. He knows:

1. The length of the pool. 2. The width of the pool. 3. The number of inches of water needed to raise the pool to the correct depth. 4. The rate of flow of the garden hose.

He needs to know how long it will take to add water. Write a python program called pool.py to help him. Here is a sample run of the program:

Pool length (feet): 40 Pool width (feet): 20 Additional depth desired (inches): 1 Water fill rate (gal/min): 6.7 : 01:14:26

Part 2 Erin the Equestrian Club president is holding a monthly club meeting during dinner. She needs to buy enough pizza for the club. She knows how many “standard” pizza (say 16-inch pizzas) slices the club will eat, but she isn’t going to buy standard pizzas. In order to save money, Erin will buy the equivalent number of Super Pies! Your task is to write a program called pizzas.py that, given the size of a standard pie, the number of slices in a standard pie, the number of standard slices the club will eat, and the size of the Super Pie!, computes the number of Super Pies! to buy. Here is a sample run of the program:

What is the diameter of a "standard" size pie? 16 How many slices are in a standard size pie? 8 How many standard slices do you want? 14 What is the diameter of the pies you will buy? 4 You will need to buy 28 4-inch diameter pies.

1 CS 110 Fall 2013 Lab 1 - Calculations

Here is another run:

What is the diameter of a "standard" size pie? 16 How many slices are in a standard size pie? 8 How many standard slices do you want? 75 What is the diameter of the pies you will buy? 30 You will need to buy 3 30-inch diameter pies.

Part 3 Gary the Graphic Designer is considering a square of a certain side length, centered at (Xc,Yc). There’s also an important point, P, within the square (Xp,Yp). Gary is considering giving the square a new side length. That is, the square may get bigger or it may get smaller, but the center point won’t change. However, the position of P (relative to the square’s center) should change. For example, if P were in the middle of the upper right quadrant of the original square, then the new P should also be in the middle of the upper right quadrant after the square changes size. Because Gary is working with a computer graphics system,1 all input and output coordinates and lengths should be integers. Here is a sample run.

Enter center x coordinate: 50 Enter center y coordinate: 50 Enter side length: 100 Enter point x coordinate: 75 Enter point y coordinate: 75 Enter new side length: 115 After changing the side length from 100 to 115, the new point is: (79, 79)

Part 4 Tom the time-keeper has just bought a new designer . It has 12 crystal clear cubic zirconia chips denoting each . Unfortunately, when Tom bought the watch, he didn’t realize it isn’t possible to tell the top (12 o’) from the bottom (6 o’clock) since the watch is symmetric in every way. Fortunately, the watch specialist at Target set the watch to the correct time, so Tom just has to either put the watch on correctly, or he has to master reading the time upside down. Tom chooses to read the time upside down (when necessary), so he writes a python program to help him out. Tom’s program works as follows: Tom enters the “time” as it appears on his watch. The program tells him what time it is if the watch is upside-down. Tom just has to determine which of the two is correct. Your job is to write the same program. Call it watch.py. Here is an example run of his program:

What time does your upside-down watch read (:)? 4:24 The right-side-up time is: 10:54

Here is another run of his program:

What time does your upside-down watch read (hours:minutes)? 12:00 The right-side-up time is: 6:30

1This problem will come around again later this semester!

2 CS 110 Fall 2013 Lab 1 - Calculations

Part 5 On September 6, 2012, while searching for sources of water, NASA’s Spirit rover encountered a higher life form: Martians! Early efforts at communication were difficult, in part, because of our archaic time system. You see, Martians are fully metric. In addition, their concept of the length of a and length of a are based on Mars rotational characteristics. So, the Martians struck a compromise: metric Earth time. Since there are 86,400 in an Earth day, they set the length of a at 1/100,000 of an Earth day. This keeps seconds at about the same length of time as a traditional second. There are 100 metric seconds in a metric and 10 metric minutes in a metric hour (leaving 100 metric hours in a day). Your task is to write an Earth time to Metric time converter so we can easily communicate times with our new friends. Here are some example runs:

Enter the time of day in military time (HH:MM:SS): 3:00:00 The "metric" time is: 12:5:00.00

Enter the time of day in military time (HH:MM:SS): 9:20:35 The "metric" time is: 38:9:29.40

Enter the time of day in military time (HH:MM:SS): 15:34:23 The "metric" time is: 64:8:87.73

Enter the time of day in military time (HH:MM:SS): 22:15:00 The "metric" time is: 92:7:08.33

Be careful to handle leading zeros in the output and handle hundredths of a “second” appropriately.

What to hand in Submit your work using the course submission procedure. You will need the following five files: pool.py, pizzas.py, scale.py, watch.py, and metricTime.py. Evaluation criteria. Your work will be evaluated according to criteria in two general categories, style and correctness. Each category counts for half of your grade. For this assignment, the criteria are:

1. Style

• The header (large docstring at the top) contains all the appropriate information: your name, the name of the file, etc; and that the program description is accurate and complete, • The logic (approach to solving the problem) is clear and reasonably simple, • Variable names are descriptive, that is, they accurately describe the values they name, • Commenting is accurate and complete, and • The horizontal and vertical spacing effectively enhances the structure of the program. • The program is efficient and avoids redundant computations. If the same calculation is used twice, it is better to do it once and store the result in a variable. • No variables are unnecessary. A rule-of-thumb is that a variable is necessary only when it names an important part of the logic, or when it is used in the logic more than once after it is assigned. • “Magic” numbers are avoided. Obvious literals like 1 and 0 are fine, but other numbers should be named by variables for clarity in the logic. For example, instead of using 86400, name it with the variable secondsPerDay

3 CS 110 Fall 2013 Lab 1 - Calculations

2. Correctness

• The submission system will evaluate how well your program passes the automatic tests.

4