Contents
Chapter 1 Overview of Object-Oriented Programming1
1.1 Programming1
1.2 Structured Programming1
1.3 Object-Oriented Programming4
1.4 Object-Oriented Programming Languages6
1.4.1 C 6
1.4.2 Java7
1.4.3 C#7
1.5 Development Environments and Tools7
1.5.1 Microsoft Visual Studio Express7
1.5.2 Microsoft Visual C 6.08
1.5.3 Code::Blocks8
1.5.4 Eclipse8
1.5.5 Dev-C 9
1.6 Unified Modeling Language9
1.6.1 Introduction to Unified Modeling Language9
1.6.2 UML Tools Comparison10
1.7 Exercises12
Chapter 2 C Basics14
2.1 C Program Structure14
2.1.1 Variables and Assignments14
2.1.2 Input and Output15
2.1.3 Flow of Control17
2.1.4 Data Types and Expressions21
2.2 Functions25
2.2.1 Basics of Functions25
2.2.2 Call-by-Reference Parameters29
2.2.3 Overloading Function Names30
2.3 Reference33
2.3.1 Introduction of Reference33
2.3.2 Reference Variables as Parameters35
2.3.3 A Reference as a Value-Returning36
2.4 Case Study36
2.5 Exercises39
Chapter 3 Class and Object42
3.1 Class43
3.1.1 Definition of Classes43
3.1.2 Class Scope45
3.1.3 Member Functions47
3.2 Constructors and Destructors50
3.2.1 Constructors50
3.2.2 Copy Constructors52
3.2.3 Destructors56
3.2.4 Sequence of Constructor and Destructor Execution57
3.3 Friend Functions and Classes58
3.4 Case Study61
3.5 Exercises64
Chapter 4 Object Thinking69
4.1 Constant Object and Constant Member Function69
4.1.1 Constant Object69
4.1.2 Constant Data Members71
4.1.3 Constant Member Functions72
4.2 Object Pointer and this Pointer74
4.2.1 Object Pointer74
4.2.2 Pointers to Object Members75
4.2.3 The 'This' Pointer77
4.3 Static Members79
4.3.1 Static Data Members79
4.3.2 Static Member Functions82
4.4 Object Array86
4.4.1 Object Array86
4.4.2 Pointer to an Array of Objects89
4.4.3 An Array of Pointers to Objects90
4.5 Class String91
4.6 Passing an Object to the Function95
4.6.1 Using an Object as a Function Parameter95
4.6.2 Using an Object Pointer as a Function Parameter96
4.6.3 Using Object Parameters as Function Parameters97
4.7 Object Combination98
4.7.1 Definition of Object Combination98
4.7.2 Instantiation for Object Composition99
4.8 Case Study104
4.9 Exercises106
Chapter 5 Overloading Operators110
5.1 Introduction110
5.2 Overloading Binary and Unary Operators111
5.2.1 Overloading Binary Operators111
5.2.2 Overloading Unary Operators113
5.3 Overloading Assignment Operator116
5.4 Overloading Special Operators118
5.4.1 Overloading Subscript Operator118
5.4.2 Overloading Function Call Operator120
5.4.3 Overloading Input/Output Operators122
5.5 Overloading Type Conversion Operator124
5.6 Case Study125
5.7 Exercises129
Chapter 6 Inheritance132
6.1 Introduction to Inheritance132
6.1.1 Base Classes and Derived Classes132
6.1.2 Declaration of Derived Classes135
6.1.3 Structure of Derived Classes136
6.2 Access Control137
6.2.1 Public Inheritance138
6.2.2 Private Inheritance139
6.2.3 Protected Inheritance140
6.3 Constructors and Destructors of Derived Classes142
6.3.1 Constructors142
6.3.2 Copy Constructors145
6.3.3 Destructors148
6.4 Multiple Inheritance149
6.4.1 Definition of Multiple Inheritance150
6.4.2 Multiple Inheritance Ambiguities151
6.4.3 Constructors of the Multiple Inheritance155
6.4.4 Virtual Base Classes156
6.5 Case Study158
6.6 Exercises166
Chapter 7 Polymorphism170
7.1 Introduction to Polymorphism170
7.1.1 Categories of Polymorphism171
7.1.2 Implementation of Polymorphism172
7.2 Virtual Functions175
7.2.1 Definition of Virtual Functions175
7.2.2 Overloading and Overriding176
7.3 Abstract Base Classes178
7.3.1 Base Class and Abstract Class178
7.3.2 An Abstract Base Class and Its Member Functions179
7.4 Case Study182
7.4.1 Declare the Base Class Point182
7.4.2 Declare Derived Class Circle184
7.4.3 Declare the Derived Class Cylinder of Circle187
7.5 Exercises191
Chapter 8 Templates194
8.1 Introduction194
8.2 Function Templates194
8.2.1 Definition of Function Templates195
8.2.2 Function Template Instantiation195
8.3 Class Templates198
8.3.1 Definition of Class Templates199
8.3.2 Instantiation of Class Template200
8.4 Case Study203
8.5 Exercises207
Chapter 9 I/O Stream208
9.1 Stream and Basic file I/O208
9.1.1 Introduction208
9.1.2 C Stream208
9.1.3 C I/O Class209
9.1.4 File and Basic File I/O210
9.2 Tools for Stream I/O211
9.2.1 Ios211
9.2.2 Defining Field Width211
9.2.3 Setting Precision212
9.2.4 Filling, Padding with fill()213
9.2.5 Formatting Flags with setf()213
9.2.6 Manipulator214
9.3 Character I/O216
9.3.1 Overloaded operators >> and <<216
9.3.2 The put() Function218
9.3.3 The get() and getline() Functions218
9.3.4 The read() and write() Functions221
9.4 Access to Files223
9.4.1 Opening and Closing a File223
9.4.2 Checking the End of a File227
9.4.3 Sequential Access to a File227
9.4.4 Random Access to a File229
9.5 Case study233
9.6 Exercises235
Chapter 10 Comprehensive Cases Analysis237
10.1 Student Grade Management System237
10.2 Object-Oriented Analysis and Design238
10.2.1 Use Case Diagram238
10.2.2 Class Diagram238
10.3 Module Design and Corresponding Code Implementation241
10.3.1 Sequence Diagram and Code Implementation for System Management241
10.3.2 Sequence Diagram and Code for Grade Management243
10.3.3 Sequence Diagram and Code for Grade Query245
10.4 The Whole C Codes of the Project247
10.4.1 Main Menu of the Project.247
10.4.2 The Class Admin251
10.4.3 The Class Course and the Class CourseManage252
10.4.4 The Class Grade and the Class GradeManage257
10.4.5 The Class Person and the Class PersonManage264
10.4.6 The Class Teacher and the Class TeacherManage269
References274