Please send questions to st10@humboldt.edu .

// function definition

double disk_area (double radius)
{

     return 3.14159 * (radius * radius);

}

// function declaration

double disk_area (double radius);

// an expression that is a function call

disk_area(10)

3.14159 * (10 * 10)
3.14159 * 100
314.159

disk_area(10 * 5)



design recipe

* a step-by-step prescription of WHAT to do and
  a suggested order in which we can DO those steps


our INTRO design recipe: to design and write and test a function

1. Understand the function's purpose
   a. Come up with a CONTRACT for your function
   b. Come up with a HEADER for your function
   c. Come up with a short PURPOSE STATEMENT for your function
      (that includes the parameter names)

2. Develop/make up function examples
   ...and write them as SPECIFIC calls, with results, after the
   Purpose Statement.

3. formulate/develop the function's body

4. test the resulting function

// Contract: disk_area: double -> double
//
// Purpose: computes the area of a disk whose radius is <radius>
//
// Example: disk_area(1) should return 3.14159
//          disk_area(10) should return 314.159

double disk_area (double radius)

// Contract: ring_area: double double -> double
//
// Purpose: calculates the area of a ring whose outer radius is
//          <outer> and whose hole has radius <inner>
//
// Example: ring_area(10, 5) should return 235.619

double ring_area (double outer, double inner)

// Contract: pizza_cost: double int int -> double
//
// Purpose: determine how much I owe for pizza given that I
//          ate <num_ate> slices, that the pizza cost <cost_pizza>,
//          and that each pizza has <num_slices> slices.
//
// Example: pizza_cost(12, 8, 2) should return 3.0

double pizza_cost (double cost_pizza, int num_slices, int num_ate)

1. Write a CONTRACT for a function to compute the perimeter
   of a rectangle.

2. Write a CONTRACT for a function to compute the total cost
   of a purchase consisting of some quantity of an item (that has
   a cost per item)

3. Now write HEADERS for those two contracts (from #1 and #2)

4. Now write PURPOSE STATEMENTS for #1 and #2
 
5. Now write an EXAMPLE(S) section for #1 and #2

6. Now write the function definitions for #1 and #2

Course style standards so far:
1. Identifiers must be chosen so that they are descriptive and 
   meaningful.
2. Statements inside of a block { } must be indented by at least
   4 spaces. (And, sequential statements should be lined up.)
3. Purpose statements should include the parameter names.