COMPUTER SCIENCE SET 1 6W4

1)      Print and turn in each program as it is complete.  Put the date and time submitted.

2)      Document the contract and purpose for each program.

3)      The examples can be done with a calculator, so I do not need to see this.

4)      But, make sure you check and record for your tests.

5)      Test with data used in your examples.

PROGRAM 1 - POWERS

1. Write a function that finds the square of a number.
2. Write a function that find the cube of a number reusing the square function.
3. Write a function that raises a number to the fourth power reusing the only functions calls.
4. Write a function that raises a number to the fifth power reusing a combination of the above functions.
5. Write a function that raises a number to the sixth power reusing the above.
6. Write 4 more functions that raises a number the Nth power.  You determine the power.
• Test with the same 2 numbers for each function.
• Each function should have 2 function calls, ie:  (cube 2) = 8  (cube 3) = 27

PROGRAM 2 - RATIOS

v     Declare constants for the following:  (CONSTANT IDENTIFIERS SHOULD BE IN ALL CAPS)

§         12 inches                                  Function: feet->inches

§         3 feet                                        Function:  yards->feet

§         1760 yards                               Function:  miles-> yards

§         3 teaspoons                              Function: tablespoon->teaspoon

§         16 tablespoons                         You get the idea.  Feel free to create your own program name

§         8 ounces

§         4 cups

§         4 quarts

v     Write a program that will determine number of inches in a given number of miles reusing functions.

v     Write a program that will determine the number of teaspoons in a gallon given the number of teaspoons reusing function.

v     Find another set of conversions and write a series of functions for that.

v     HINT:  Always test with 1 and then another easy number.

v     HINT: The function itself only contains constants and variables.

PROGRAM 3 – RATE

v     Specific Problem

§         This is the Amusement Park Graphing Linear Function scenario from worksheet and Quiz.

§         Read those directions to understand the specific problem.

v     General Problem

§         Write a function that will determine the distance from a location at any point in time until arrival.  The distance from the location and the rate you are driving are constants.  The program consumes the minutes you have driven.

§         Declare a CONSTANT for the distance from the location.

§         Declare a CONSTANT for the rate you are driving.

§         Create 2 new scenarios to use as examples

§         Test with data from the worksheet and quiz. You have already done the examples.