156. C++ Programming for C
Programmers
Rev. 8.0
This course is a comprehensive hands-on introduction to object
oriented programming in C++ for C programmers. Emphasis is placed on the
features of C++ that support effective modeling of the problem domain and reuse
of code. The course consists of two modules.
In the first module object oriented concepts are introduced. The C++
class construct is introduced and its key features elaborated step-by-step,
providing full implementation of abstract data types. C++ memory management is
discussed. Function and operator overloading and the use of references are
covered. The scope and access control mechanisms of C++ are described.
Inheritance is introduced. The use of virtual functions to implement
polymorphism is discussed.
The second module presents intermediate topics. The ANSI C++
Standard Library is covered, including namespaces, the new header files and
basic string class. Templates are covered, including an introduction to the
Standard Template Library (STL). There is a chapter on I/O streams, including
formatting and file I/O. Practical issues of C++ programming, such as
reliability, testing, efficiency and interfacing to C, are discussed. The
course introduces newer features of C++ such as exceptions, runtime type
information (RTTI), and the new C++ cast syntax.
Extensive programming examples and exercises are provided. The
course is designed so that it can be taught in any environment with an ANSI C++
compiler.
LEARNING OBJECTIVES
·
Learn object oriented concepts.
·
Acquire a thorough working knowledge of C++
programming.
·
Gain an understanding of the issues involved in
effective class design
·
Learn how to program with templates and become
introduced to STL
·
Become introduced to newer features of C++,
including the ASNI standard library, exception handling and RTTI
Course Duration: 5
days
Prerequisites: This
course assumes a good knowledge of C programming. Students without a strong
background in C should consider instead the course “C++ Programming for Non-C
Programmers”.
Module 1. Object Oriented C++ Programming Fundamentals
1.
Concepts of Object Oriented Programming
Objects
Information Hiding and Encapsulation
Abstract Data Types
Methods and Messages
Classes
Class Inheritance
Polymorphism
2.
Classes in C++
Data Encapsulation in C and C++
Definition of C++ Classes
Member Data and Functions
this Pointer
Abstract Data Types
Organizing Code for Classes
3.
Functions in C++
Function Prototypes and Type Checking
Conversion of Parameters
Default Arguments
Inline Functions
Function Overloading
4.
Constructors and Destructors
Constructors and Initializations
Object Creation and Destruction
Destructors
Multiple Constructors in a Class
Hidden Constructors
5.
Memory Management in C++
Static, Automatic and Heap Memory
New and Delete
Handling Memory Allocation Errors
Hiding Details of Memory Management in a Class
Implementing a Dynamic String Class
6.
References and Argument Passing in C++
Call by Value
Reference Declarations
Reference Arguments
Copy Constructor
Constant Arguments and Functions
7.
Operator Overloading, Initialization, and
Assignment
Operator Overloading
Semantics of Assignment
Initialization vs. Assignment
Overloading Assignment
Type Conversions
8.
Scope and Access Control
Scope in C++
Friend Functions
Const and Enumeration Types
Static Members
9.
Introduction to Inheritance
Inheritance for Modeling and Reuse
Class Derivation
Access Control
Base Class Initialization
Composition
Initializing Class Type Members
10. Polymorphism
and Virtual Functions
Virtual Functions and Dynamic Binding
Polymorphism in C++
Pointer Conversion
Virtual Destructors
Abstract Classes and Pure Virtual Functions
Module 2. Intermediate C++ Programming
1.
ANSI C++ Library
New Header Files
Namespaces in the Standard Library
ANSI C++ String Classes
Templates in the Standard Library
2.
Templates
C++ Template Mechanism
Function Templates
Class Templates
Generic Programming
Implementing a General Array Class
Standard Template Library
3.
Input/Output in C++
Streams I/O Library
Formatted Stream I/O
File I/O
I/O in User Defined Classes
4.
Practical Aspects of C++ Programming
Interfacing C and C++
Namespaces
Reliability in C++ Programs
Testing Considerations
Efficiency Considerations
5.
Exceptions
C++ Exception Mechanism
Exceptions Compared to Other Error Handling Techniques
throw, try and catch
Exception Context and Stack Unwinding
Uncaught Exceptions
Automatic Cleanup in Exception Handling
6.
Runtime Type Information
Runtime Type Information (RTTI) Mechanism
type_info Class and typeid Operator
Type Safe Pointer Conversion
New C++ Cast Syntax
Appendix A. Reading List
System Requirements
The course is designed to be delivered in any environment supporting
an ANSI C++ compiler. An optional version of the lab file contains project
files for Visual C++ 2005.