CS 3323, Topics in Programming Languages
Review for C++ Exam, Fall 1999
(Topics arranged according to the text: Deitel and Deitel,
C++: How to Program,
2nd Edition. Emphasis not on text, but on what was covered in
class, on handouts, and in assignments.)
- Chapters 1-5: Standard topics and a "better C".
- Stroustrup thought the name should be ++C.
- Goals of C++:
- Provide features for object-oriented programming
(primarily classes and inheritance).
- Nearly as efficient at C for the same task.
- (Mostly) upwardly compatible with C.
- Provide features that make a "better C".
- Provide most features that anyone might want
(resulting in a very complex language).
- Basic I/O with << and >>.
- Reference parameters (i.e., int &).
Return of a reference.
- Storage model: similar to C, with auto,
static, and dynamic storage, the latter
using new and delete.
- inline functions to replace C macros.
- Chapters 6 and 7: Classes.
- Handout: C structs.
- "Bare" struct: copies when a parameter, when returned,
or when assigned.
- Pointer to struct: passes, returns, and assigns a pointer.
- Uses fixed amount of storage, known at compile time.
- public and private members.
- Data members and member functions.
- Constructors (essential for dynamic data).
- Destructors: essential when dynamic data present.
- this pointer. (Return *this to return
the class as a reference (and a pointer is returned).)
- Handout: Examples of contructors, destructors.
- Handout: Dice statistics (showing header files
and separation of interface from implementation).
- Assign 1: Rational numbers (classes, constructors).
- Chapter 8: Operator overloading.
- Must use existing C++ operators, with unchanged properties
(precedence, arity, and associativity).
- At least one operand must be user-defined.
- When member function, one operand is implcit.
- When friend function, all operands are explicit.
- Handout: Complex numbers, showing friend
and member overloaded operators.
- Handout: String class example.
- Handout: Time example.
- Handout: Date example.
- Assign 2: Time and Overloaded ++
(overloading both postfix and prefix ++).
- Chapter 9: Inheritance.
- Base class and derived classes.
- protected members.
- public inheritance.
- Constructors work down from the base class to derived
classes, while destructors work up from derived to base.
- Handout: Multiple inheritance
(Time and Date).
- Chapter 10: Virtual Functions and Polymorphism.
- Declare a function virtual; then if redefined in a
derived class, a pointer to a derived class object
will choose the correct function at run time.
- Handout: Final Shape class,
showing polymorphism: (Array of pointers to Shape,
pointing to derived class objects. In this case the system will pick
correct derived class member function, assuming the
function is virtual.)
- Assign 3: Vehicle class.
(Inheritance and polymorphism).
- Chapter 11: Stream I/O.
- Overloads << and >> operators,
with first operand a Stream (cin or cout),
returning the Stream.
- Type safe, unlike scanf or printf.
- Just the basics.
- Chapter 12: Templates.
- Allow parameterized code with an arbitrary type as the
parameter, even a user-defined type.
- In essence, does a textual replacement and compiles
the resulting code.
- Handout: Simple stack of int versus stack as template.
- Chapter 15: Data structures.
- Modest additional possibilities because of the object-oriented
features of C++.
- Handout: Binary tree in C++ (compared with Java).