UMBC CMSC201, Computer Science I, Fall 1994
Sections 0101, 0102 and Honors
Tuesday October 18, 1994
Assigned Reading: 5.6
Handouts (available on-line): none
Topics Covered:
- A program
that rounds numbers within a given precision.
Sample run.
The meaning of functions like floor can be found
in the Unix manual pages for floor
by typing man floor.
- A second program that rounds
numbers within a given precision using the standard pow
function instead of our home-brewed version (see
sample run).
- When we use a function we should be careful to call the function
with parameters that are of the same type as declared in the
function's prototype. Here's a program
that violates this dictum; it lets the C compiler do the type
conversion. It works (see sample run),
but I consider this very poor programming style. If the C compiler
cannot convert the type of the actual parameter to the type
of the formal parameter, as in this program,
the compiler should give a compile time
error.
- The calendar program. We discussed many aspects of Top-Down design
(also known as "stepwise refinement") with regards to the calendar
program. Then we developed the program in steps.
- Step 1 is a small loop that prints the calendar for
one month, given the number of days in the month and
the weekday of the first day of the month.
See program and
sample run.
- Step 2 is another small program that uses a function to
determine the weekday of a day x days after a certain weekday.
(E.g., what is the weekday of the day that is 365 days after
a Monday?) See program and
sample run.
- Step 3 puts Step 1 and Step 2 together as a "trial test".
We print the calendars for several months in a row, assuming
all months have 31 days. It's not what we want in the final
program, but we can check if our strategy works.
See program and
sample run.
- Step 4 was not shown in class. We steal some functions from
the textbook's calendar program to compute the number of
days in a given month and the number of days in a given year.
See program and
sample run.
- Step 5 puts it all together and now we have our own version
of the calendar program that is somewhat different from the
textbook's version. Both work, but we got to experience how
we might put a larger program together.
See program and
sample run.
Last Modified:
Tue Oct 18 16:46:48 EDT 1994
Richard Chang, chang@gl.umbc.edu