CS 102 Lecture Notes

Week Two, Tuesday: Abstract Data Types and C++ Classes

Classes and Members

An "abstract data type" (ADT) hides information from the programmer. It presents the programmer with an interface that allows him (or her) to perform all the necesarry operations on the data without "bothering" the programmer with the implementation details. This allows the programmer to concentrate on working with the ADT in relation to other ADTs.

One way to implement an ADT is with a C "struct," but a better way is to use a "class." A class allows us to include actions in the ADT along with its attributes.

Programming Example: Throttle Class

Constructors

Header and Implementation Files

First Project: Lunar Lander

Example program: run from the DOS prompt.


Output Example

Here is another example with a graphical user interface (GUI), written in Java:

You need a Java-enabled browser to see the applet.

Lunar Lander Applet.
Use the up and down arrow keys to adjust the throttle.


This page established September 4, 1999; last updated Jan 16, 2000.