CS201
Lab 7 - Function Parameters
Objectives:
- Calculate the area under a curve using a C program.
- Practice use of for-type loops, switch statements, and enumerated types.
Readings:
- Read Chapter 7 in the Hanly/Koffman text.
Deliverables: (DUE 72 HRS AFTER THE END OF YOUR LAB!)
- Submittal of the following files:
- Makefile
- Proto.h
- Lab7.c
- Trap.c
- XSquaredSinX.c
- HalfCircle.c
- TestFunction.c
TO DO (for this lab)
- Design and Write a program to solve Programming Project #6
on page 363-364 of the Hanly/Koffman text.
- Carefully choose which parameters need to be passed by reference, and when
passing by value is enough...
- Make sure to use nested (i.e. double)
for-type loop to calculate and print out your results.
- Define enumerated type to reflect your three functions (i.e.
xsquaredsinx, halfcircle, testfunction), and use
it in the nested loop. Switch-type statement may also prove itself to be helpful. :)
- Make sure that your Makefile is going to properly rebuild the run image.
- You will need to build four separate source files,
one include file for prototypes, and a stub for my TestFunction
that will be supplied after submittal.
- TestFunction Stub
- Type of function is double.
- Name of function is TestFunction.
- Number of parameters is one.
- Type of parameter is double.
- Your stub will need to be called properly in your main
program. The value it returns (can be anything) should be
properly formatted as an output statement (see below).
- When we grade your program, we will overwrite your
TestFunction.c with our version of TestFunction.c and
your program will then produce an expected output that
we will check for.
- Inputs: none, the program just runs.
- Outputs: (#'s represents your calculated data):
CS201 - Lab 7 - Area Under The Curve
g(x) = XSquaredSinX
a = 0.00000, b = 3.14159
n = 2, h = #.#####, area = ######.#####
n = 4, h = #.#####, area = ######.#####
n = 8, h = #.#####, area = ######.#####
n = 16, h = #.#####, area = ######.#####
n = 32, h = #.#####, area = ######.#####
n = 64, h = #.#####, area = ######.#####
n = 128, h = #.#####, area = ######.#####
h(x) = HalfCircle
a =-2.00000, b = 2.00000
n = 2, h = #.#####, area = ######.#####
n = 4, h = #.#####, area = ######.#####
n = 8, h = #.#####, area = ######.#####
n = 16, h = #.#####, area = ######.#####
n = 32, h = #.#####, area = ######.#####
n = 64, h = #.#####, area = ######.#####
n = 128, h = #.#####, area = ######.#####
f(x) = TestFunction
a = 0.00000, b = 12.00000
n = 2, h = #.#####, area = ######.#####
n = 4, h = #.#####, area = ######.#####
n = 8, h = #.#####, area = ######.#####
n = 16, h = #.#####, area = ######.#####
n = 32, h = #.#####, area = ######.#####
n = 64, h = #.#####, area = ######.#####
n = 128, h = #.#####, area = ######.#####