UMBC CMSC202, Computer Science II, Spring 1998,
Sections 0101, 0102, 0103, 0104 and Honors
Tuesday January 27, 1998
Assigned Reading:
- A Book on C: 6.1-6.6 and 11.1-11.5
- Programming Abstractions in C: 2.1-2.5 and 3.4
Handouts (available on-line):
course description,
syllabus and
project policy.
Topics Covered:
- Prerequisites for CMSC 202:
See
FAQ on Introductory Computer Science Courses on material
that you are expected to know from CMSC 201.
For example, you should really understand parameter passing
by reference.
- Noted the existence of the course web page, which you already know
about if you are reading this page. (Reminder:
check in if you haven't already.)
- Went over course description.
Note: the Roberts textbook is optional. Also, you will be required to
purchase Dr. Mayfield's excellent notes on pointers "Understanding
Pointers in C" for $6.50. The notes will be available in the
bookstore shortly.
- Went over course syllabus and
project policy. NB: I'm serious
about catching cheaters on the projects. Read over the
course policy on cheating well.
- Motivational lecture on how to learn advanced programming skills.
Main point: you should be able to sort out the syntactic issues
by now. In this course you need to consider higher-level issues
in data structures and problem-solving strategies.
- One way to learn how to use new features in a programming language
is to understand simple programs and learn how to generalize from
the simple example. In the following sequence of programs, we first
examine the use of parameter passing by reference for integers.
We also examine a simple program that uses structures. From the
two, we are able to concoct a program that passes structure parameters
by reference.
- A simple function:
program and
sample run.
- A simple function with an integer reference parameter:
program and
sample run.
- A simple program that uses structures:
program and
sample run.
- A simple function that takes a structure as
a parameter and returns a structure value:
program and
sample run.
Note that the syntax in this function is not much different
from the syntax for the function which takes an integer
parameter and returns an integer value.
- A revision of the previous function which
fixes a problem where the minute field might exceed
59 minutes:
program and
sample run.
- Finally, we write a function that takes a structure
reference parameter.
program and
sample run.
This function fixes the minute field of the parameter if the
field exceeds 60 minutes. Note that the syntax for
accessing the field of the structure parameter is
(*p).minute. The parentheses are necessary because
the . operator has a higher precedence than the
dereference * operator. C provides a short cut
notation, p->minute is identical to
(*p).minute. Nevertheless, the mechanism for
working with reference parameters is essentially the same as
that of our second program.
Last Modified:
22 Jul 2024 11:27:44 EDT
by
Richard Chang
Back up
to Spring 1998 CMSC 202 Section Homepage