Next:
Contents
Lessons in Object-oriented Programming and C++
Contents
1. Introduction
1.1 Scope
1.2 Revision Status
1.3 Plan of these Notes
1.4 Acknowledgements
2. Introduction to Object-oriented Programming
2.1 Choice of Language
2.2 Standard Library
2.3 Software Engineering and its Requirements and Goals
2.4 The Waterfall Lifecycle and Structured Systems Analysis and Design
2.5 Shortcomings of Waterfall and Top-down Decomposition
2.6 Key Application: Event-driven Interaction
2.7 Cornerstones of Software Engineering and Object-oriented Systems
2.8 Resources
2.8.1 Journals, Books, Articles
2.8.2 WWW
2.9 Summary
3. Programming Languages & Paradigms.
3.1 Introduction
3.2 Programming Language - definition
3.3 Brief Historical Background
3.4 Classification of Programming Languages
3.5 C++ - Its History and Origins
3.6 Imperative Paradigm
3.6.1 Sequence
3.6.2 Selection
3.6.3 Repetition
3.6.4 Procedural Abstraction
3.6.5 Procedural Abstraction with Parameters
3.7 Declarative Paradigm
3.8 Declarative versus Imperative
3.9 Object-oriented Paradigm
3.10 Some worthwhile considerations
4. Tutorial Introduction to C++
4.1 Get Started
4.1.1 Your First C++ Program
4.2 Variables and Arithmetic
4.3 For Loop
4.4 Symbolic Constants and the Preprocessor
4.5 Character Input and Output
4.5.1 File copying
4.5.2 Character counting
4.5.3 Line Counting
4.5.4 Word Counting
4.6 Arrays
4.7 Functions
4.7.1 Declaration of functions
4.7.2 Program Split into Modules
4.8 Creation of Executables
4.8.1 Basics - Compiling and Linking
4.8.2 Other Libraries
4.8.3 Static versus Shared Libraries
4.8.4 Make and Makefile
4.9 Summary
5. Variables, Types, Operators and Expressions
5.1 Introduction
5.2 Variable names
5.3 Elementary Data Types and Sizes
5.3.1 Integer types
5.3.2 Floating-point types
5.3.3 Implementation Dependencies
5.4 References
5.5 Arrays
5.6 Pointers
5.6.1 Introduction
5.6.2 Declaration / Definition of Pointers
5.6.3 Referencing and Dereferencing Operators
5.6.4 Pointers and Arrays
5.7 Strings in C++
5.7.1 Introduction
5.7.2 C-strings
5.8 Standard String Class
5.9 Constants and their Types
5.10 Declaration versus Definition
5.11 Arithmetic Operators
5.12 Relational and Logical Operators
5.13 Type Conversions and Casts
5.14 Assignment Operators and Expressions
5.15 Increment and Decrement Operators
5.16 Conditional Expressions
5.17 Bitwise Operators
5.18 Precedence and Order of Evaluation of Operators
6. Control Flow
6.1 Introduction
6.2 Statements and Blocks
6.3 Selection
6.3.1 Two-way Selection - if else
6.3.2 Multi-way Selection - else if
6.3.3 Multi-way Selection - switch - case
6.4 Repetition
6.4.1 while
6.4.2 for
6.4.3 do - while
6.5 break and continue
6.6 goto and Labels
7. Functions and Program Structure
7.1 Introduction
7.2 Basics
7.3 Declarations of Functions - Prototypes
7.4 Function parameters
7.4.1 Parameters
7.4.2 Pass-by-value parameters
7.4.3 Pass-by-reference parameters
7.4.4 Programmed pass-by-reference via pointers
7.4.5 Semantics of parameter passing
7.4.6 Arrays as Parameters
7.4.7 Default parameters
7.5 Function return values
7.6 Overloaded function names
7.7 Inline functions
7.8 External variables
7.9 Scope of variables
7.10 Namespaces
7.11 Heap memory management
7.11.1 Introduction
7.11.2 Operator new
7.11.3 Operator delete
7.11.4 Anonymous variables
7.11.5 Garbage
7.12 Lifetime of variables
7.12.1 Lifetime of variables - summary
7.13 Memory layout of a C++ program - a model
7.14 Initialisation
7.15 Register Variables
7.16 Block Structure
7.17 Recursion
7.18 The C++ Preprocessor
7.18.1 File inclusion
7.18.2 Symbolic constants and text substitution
7.18.3 Macro substitution
7.18.4 Conditional compilation / inclusion
8. Records - struct, class, union
8.1 Introduction
8.2 A Point record
8.3 Operations on Structs
8.4 Unions
9. Classes and Objects
9.1 Introduction
9.2 A Cell Class
9.2.1 Informal Specification of the Class
9.2.2 Class Cell
9.2.3 Some additions
9.2.4 Constness
9.2.5 Constructor Initialiser List
9.3 A Coordinate Class
9.3.1 Informal Specification of the Class
9.3.2 Class Interface, Methods
9.3.3 Class implementation code
9.3.4 A Client Program
9.4 A Simple Array Class
9.4.1 Array, First Try
9.4.2 Array, Second try, Error Checking
9.4.3 Third try, separate class file
9.4.4 Array, separate class.h file, class.cpp file
10. Types, Variables, Values
10.1 Introduction
10.2 Data Types
10.3 Values
10.4 Variable
10.5 L-Values and Values
10.6 Aliases, dangling references, garbage
10.6.1 Aliases
10.6.2 Dangling References
10.6.3 Uninitialised Pointers
10.6.4 Garbage
11. Inheritance
11.1 Introduction
11.2 Example 1: Class Cell extended via inheritance
11.2.1 First Attempt
11.2.2 'protected'
11.2.3 Virtual Functions and Dynamic Binding
11.3 Dynamic Typing, Run-time Binding and Polymorphism
11.4 Overriding (virtual functions) versus Overloading
11.5 Strong Typing
11.6 Inheritance & Virtual Functions - Summary
11.7 Inheritance versus Inclusion, is-A versus has-a
11.8 Reuse - the Real Power of Inheritance & Virtual Functions
11.9 Example 2: a Person class hierarchy
11.10 A Person Class
11.11 An Employee Class
11.12 Use of the Person Hierarchy
11.13 Polymorphism
12. Objects That Use Heap Memory
12.1 Introduction
12.2 An Heap-based Array Class
12.2.1 Class Declaration
12.2.2 Class implementation code
12.2.3 A simple client program
12.3 The 'this' pointer
12.4 Copy Constructors and Parameter Passing and Value Return
12.4.1 Naïve member-wise constructor, shallow copy
12.4.2 Proper 'deep' copy constructor
12.4.3 Copy constructor and parameter passing and return
12.5 Assignment
12.6 Destructor
12.7 The Big-Three
12.8 Reference parameters and reference return
12.9 Privacy is class-based, not object-based
13. Operator Overloading
13.1 Introduction
13.2 Lead-in - Add Functions for Array
13.3 Chaining calls to member functions
13.4 Operators
13.5 Member versus Non-member Functions, Conversions
13.5.1 Introduction
13.5.2 A String Class
13.5.2.1 Class Interface, Methods
13.5.2.2 Class implementation code
13.5.2.3 A very simple client program
13.5.3 Implicit Arguments
13.5.3.1 Member function
13.5.3.2 Non-member function
13.5.3.3 Non-member operator
13.5.3.4 Member operator
13.5.4 Coercion of Arguments
13.5.5 Constructors for conversion - explicit
14. A List Class
14.1 Introduction
14.2 Friend Functions and Classes
14.3 A List Class
14.3.1 Informal Specification of the Class
14.3.2 Class Interface
14.3.3 Dissection of Listint.h
14.4 List implementation code
14.5 Deep Copy: Copy Constructor & Assignment
14.5.1 Copy constructor
14.5.2 Deep-copy assignment
14.5.3 Destructor for heap objects
14.6 The Big-Three
14.6.1 Defence against naive defaults
14.7 Overloading the Stream Output Operator
14.8 A simple client program
15. Correctness and Specification
15.1 Introduction
15.2 Syntactic Specification
15.3 Semantic Specification
15.3.1 Introduction
15.3.2 Assertions
15.3.3 Axiomatic Specification
15.3.4 Model-based Specification: Pre- and Post-conditions
15.4 Design-by-Contract
15.5 Pre-conditions and Defensive Programming
16. Templates
16.1 Introduction
16.2 Template Functions
16.2.1 Overloaded Functions recalled
16.2.2 Template Function
16.3 Polymorphism - Parametric
16.4 Alternative Approaches to Generiticity
16.5 Template Array
16.5.1 Class declaration and implementation
16.5.2 A simple client program
16.6 Template List
16.6.1 Class Interface
16.6.2 Dissection of Listt.h
16.6.3 Implementation of functions
16.6.4 Dissection of functions
16.7 A simple client program
17. Queue and Stack Classes
17.1 Introduction
17.2 A Queue Class
17.2.1 Informal Specification of the Class
17.2.2 Class Interface
17.3 Queue implementation code
17.4 A simple client program
17.5 A Stack Class
17.5.1 Informal Specification of the Class
17.5.2 Class Interface
17.6 Stack implementation code
17.7 A simple client program
18. A Multi-class Program - Graphics
18.1 Introduction
18.2 Matrix class
18.3 Image class
18.4 Figure Class
18.5 Open-Closed Principle
18.6 Figure Classes
18.7 Program using Figure hierarchy
Bibliography
About this document ...
平成17年1月7日