CS 16, Spring 2012
Programming Project 1

Due: Monday, July 23, 11:59pm
Worth: 4% of final grade

Before you begin:
  1. If you have the textbook, read through the end of chapter 2. Pay special attention to the C programs (particularly pages 21, 63 and 74).
  2. Read all of the instructions below to make sure you understand the problems completely before attempting to solve them.
  3. For each problem, plan to accomplish all parts of the 5-step problem-solving process outlined in the text:
    1. Problem statement - okay, so this part is done already, but you still have to verify that you understand the problems.
    2. Input/output description - this part is done too: see the sample runs below. Also you can execute (but not read) our solutions at CSIL to learn more about how we expect your solutions to work. Run either solution as follows, substituting either bmi or logbase for PGMNAME:
      -bash-4.2$ ~kyledewey/cs16/p1/PGMNAME
      Just one clarification: print all floating point values formatted with 1-digit precision.
    3. Hand example - do this part to know exactly what calculations are necessary, and the order in which those calculations must be done.
    4. Algorithm development - we give you some clues about the overall program structures below, but you must apply what you learned from the hand example to get the calculations right. In the text's process, this step also includes getting the programs typed in and working!
    5. Testing - Don't skip this step. Find and fix your errors before turning in.
  1. Write a C program to calculate a person's body mass index (BMI) for a user.
    At left is the formula for calculating BMI, given a person's weight in kilograms and height in meters. Your program will let the user enter weight in pounds and height in inches, and then convert to the metric units to calculate BMI.
  2. Write another C program to calculate a logarithm for a user, where the user enters both the original value and the base for which the logarithm is expressed. If you have the textbook, see Problems 41 and 42 on page 82 of the Etter text, and especially the formula shown above those problems. Your solution will actually be a general version that solves both of problems 41 and 42, plus infinite more like them. If you don't have the textbook, you may wish to consult http://www.sosmath.com/algebra/logs/log4/log43/log43.html and http://www.cplusplus.com/reference/clibrary/cmath/log/.
  3. Go to CSIL (in person unless you can manage this step remotely without any assistance from us). Open a terminal window, cd to the same directory as your source code files, then type the following:
    turnin p1@cs16 bmi.c logbase.c

Optional Challenges

Do not change bmi.c or logbase.c to accomplish these challenges. Write new programs instead. Do not turn in these challenges - they are for practice and to learn.


Adapted from the work of Michael Costanzo by Kyle Dewey