CPSC 120 Postlab 2: Finding Your Pace
Due Before Class on Friday September 16
Overview
For runners, race distances are often given in kilometers -- 5K, 10K, etc.
A fast runner might run a 5K race in 20 minutes or so; the winning time is
usually closer to 15 minutes, and most of the population comes in between
20 and 35 minutes. Runners in the US, however, typically measure their pace
in minutes per mile. In this assignment you will write a program that
relates the user's race time to their speed in minutes per mile.
Your program should ask the user for the following input:
- The distance of the race, in kilometers
- The minutes part of their finish time
- The seconds part of their finish time
Your program should print the user's pace in minutes per mile,
then ask the user what
pace he or she is trying to achieve. After reading in this information,
the program should print what time the user would need to run a race of
the given distance in to achieve this pace.
A sample run of your program for a user who ran a 5K in 27 minutes and 15
seconds might look like this (items in bold are
entered by the user):
Enter the number of kilometers run: 5
Enter the minutes part of your time: 27
Enter the seconds part of your time: 15
Your pace is 8.72 minutes per mile.
How fast do you want to go, in minutes per mile? 6.0
To go that fast, you would have to run
5 kilometers in 18 minutes and 45 seconds.
Planning Your Program
- First declare your variables and constants. You will probably
need variables
to hold the distance in kilometers, the distance in miles, the minutes part
of the time, the seconds part of the time, the time in minutes, the pace in
minutes per mile, the desired pace, and the time required for the
desired pace. Phew! Think about what type each of these should be.
Note that there are 1.6 kilometers in a mile and 60 seconds in an minute
(these should be constants!!).
- Next, do the calculations to get the distance in miles and the time in
minutes. It's easy to convert the distance to miles -- just use the conversion
factor above. But be sure to use it the right way! Note that 5 kilometers
is about 3.1 miles; this should help you see if your answers make sense.
- Converting the time to minutes is also easy.
First, convert the seconds part to minutes (use the constant for the number of
seconds in a minute), then add the result to the
minutes part entered by the user. This gives you the total time in minutes.
- Once you have the distance in miles and the total time in minutes, it's
simple to get the pace -- just divide.
- When the user enters their desired pace, it's also easy
to calculate the necessary time in minutes; just solve the
formula (pace = minutes/miles) for minutes, since you know both the pace and
the miles. Of course, you'll need to convert the result to minutes and
seconds to print it out.
Be sure to put your name, the file name, and a description of the program
in the header.
Submission
To submit your code, upload a zip file containing your code to the
course Inquire site.