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
- Class head
- Member list: public section, private section
- Using a class
- Using a member function
- Demonstration program
- Implementing member functions
Constructors
- Default constructor
- Automatic default constructor
- Parameter constructor
- Copy constructor
Header and Implementation Files
- Header File (contains private member data declarations and private and public function declarations)
- Implementation file (contains function definitions)
- Sample program
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:
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.