商品描述
本書將C++程序設計語言作為描述工具,對面向對象程序設計及統一建模語言UML進行介紹。內容包括:C++基礎知識、函數、數組、指針和字符串、I/O流對象、類和數據抽象、友元函數、重載操作符、繼承、多態性、模板等。本書由淺入深,由日常生活及工程應用案例,逐步引入面向對象程序設計基本概念和方法。每章提供案例研究,後續部分章節提供綜合案例分析。案例研究及分析註重講解使用UML進行程序設計的方法,使面向對象設計與C++程序設計語言相結合,提高學生利用對象思維解決實際問題的能力。本書既可作為高等學校計算機相關專業面向對象程序設計雙語教材,也可作為留學生相關課程教材。
作者簡介
方潛生,博士,二級教授,博士生導師,任職於安徽建築大學,獲得全國優秀教、安徽省學術和技術帶頭人、安徽省高校學科拔尖人才、安徽省教學名師等稱號,受國務院政府特殊津貼,擔任智能建築與建築節能安徽省重點實驗室主任、樓宇控與節能優化國家級實驗教學示範中心主任,兼任高等學校土木類專業教學指導委員副主任委員、高等學校建築電氣與智能化專業教學指導分委員會主任委員、中國節協會群智能建築節能專業委員會主任委員。
目錄大綱
Contents
Chapter 1 Overview of Object-Oriented Programming 1
1.1 Programming 1
1.2 Structured Programming 1
1.3 Object-Oriented Programming 4
1.4 Object-Oriented Programming Languages 6
1.4.1 C++ 6
1.4.2 Java 7
1.4.3 C# 7
1.5 Development Environments and Tools 7
1.5.1 Microsoft Visual Studio Express 7
1.5.2 Microsoft Visual C++ 6.0 8
1.5.3 Code::Blocks 8
1.5.4 Eclipse 8
1.5.5 Dev-C++ 9
1.6 Unified Modeling Language 9
1.6.1 Introduction to Unified Modeling Language 9
1.6.2 UML Tools Comparison 10
1.7 Exercises 12
Chapter 2 C++ Basics 14
2.1 C++ Program Structure 14
2.1.1 Variables and Assignments 14
2.1.2 Input and Output 15
2.1.3 Flow of Control 17
2.1.4 Data Types and Expressions 21
2.2 Functions 25
2.2.1 Basics of Functions 25
2.2.2 Call-by-Reference Parameters 29
2.2.3 Overloading Function Names 30
2.3 Reference 33
2.3.1 Introduction of Reference 33
2.3.2 Reference Variables as Parameters 35
2.3.3 A Reference as a Value-Returning 36
2.4 Case Study 36
2.5 Exercises 39
Chapter 3 Class and Object 42
3.1 Class 43
3.1.1 Definition of Classes 43
3.1.2 Class Scope 45
3.1.3 Member Functions 47
3.2 Constructors and Destructors 50
3.2.1 Constructors 50
3.2.2 Copy Constructors 52
3.2.3 Destructors 56
3.2.4 Sequence of Constructor and Destructor Execution 57
3.3 Friend Functions and Classes 58
3.4 Case Study 61
3.5 Exercises 64
Chapter 4 Object Thinking 69
4.1 Constant Object and Constant Member Function 69
4.1.1 Constant Object 69
4.1.2 Constant Data Members 71
4.1.3 Constant Member Functions 72
4.2 Object Pointer and this Pointer 74
4.2.1 Object Pointer 74
4.2.2 Pointers to Object Members 75
4.2.3 The 'This' Pointer 77
4.3 Static Members 79
4.3.1 Static Data Members 79
4.3.2 Static Member Functions 82
4.4 Object Array 86
4.4.1 Object Array 86
4.4.2 Pointer to an Array of Objects 89
4.4.3 An Array of Pointers to Objects 90
4.5 Class String 91
4.6 Passing an Object to the Function 95
4.6.1 Using an Object as a Function Parameter 95
4.6.2 Using an Object Pointer as a Function Parameter 96
4.6.3 Using Object Parameters as Function Parameters 97
4.7 Object Combination 98
4.7.1 Definition of Object Combination 98
4.7.2 Instantiation for Object Composition 99
4.8 Case Study 104
4.9 Exercises 106
Chapter 5 Overloading Operators 110
5.1 Introduction 110
5.2 Overloading Binary and Unary Operators 111
5.2.1 Overloading Binary Operators 111
5.2.2 Overloading Unary Operators 113
5.3 Overloading Assignment Operator 116
5.4 Overloading Special Operators 118
5.4.1 Overloading Subscript Operator 118
5.4.2 Overloading Function Call Operator 120
5.4.3 Overloading Input/Output Operators 122
5.5 Overloading Type Conversion Operator 124
5.6 Case Study 125
5.7 Exercises 129
Chapter 6 Inheritance 132
6.1 Introduction to Inheritance 132
6.1.1 Base Classes and Derived Classes 132
6.1.2 Declaration of Derived Classes 135
6.1.3 Structure of Derived Classes 136
6.2 Access Control 137
6.2.1 Public Inheritance 138
6.2.2 Private Inheritance 139
6.2.3 Protected Inheritance 140
6.3 Constructors and Destructors of Derived Classes 142
6.3.1 Constructors 142
6.3.2 Copy Constructors 145
6.3.3 Destructors 148
6.4 Multiple Inheritance 149
6.4.1 Definition of Multiple Inheritance 150
6.4.2 Multiple Inheritance Ambiguities 151
6.4.3 Constructors of the Multiple Inheritance 155
6.4.4 Virtual Base Classes 156
6.5 Case Study 158
6.6 Exercises 166
Chapter 7 Polymorphism 170
7.1 Introduction to Polymorphism 170
7.1.1 Categories of Polymorphism 171
7.1.2 Implementation of Polymorphism 172
7.2 Virtual Functions 175
7.2.1 Definition of Virtual Functions 175
7.2.2 Overloading and Overriding 176
7.3 Abstract Base Classes 178
7.3.1 Base Class and Abstract Class 178
7.3.2 An Abstract Base Class and Its Member Functions 179
7.4 Case Study 182
7.4.1 Declare the Base Class Point 182
7.4.2 Declare Derived Class Circle 184
7.4.3 Declare the Derived Class Cylinder of Circle 187
7.5 Exercises 191
Chapter 8 Templates 194
8.1 Introduction 194
8.2 Function Templates 194
8.2.1 Definition of Function Templates 195
8.2.2 Function Template Instantiation 195
8.3 Class Templates 198
8.3.1 Definition of Class Templates 199
8.3.2 Instantiation of Class Template 200
8.4 Case Study 203
8.5 Exercises 207
Chapter 9 I/O Stream 208
9.1 Stream and Basic file I/O 208
9.1.1 Introduction 208
9.1.2 C++ Stream 208
9.1.3 C++ I/O Class 209
9.1.4 File and Basic File I/O 210
9.2 Tools for Stream I/O 211
9.2.1 Ios 211
9.2.2 Defining Field Width 211
9.2.3 Setting Precision 212
9.2.4 Filling, Padding with fill() 213
9.2.5 Formatting Flags with setf() 213
9.2.6 Manipulator 214
9.3 Character I/O 216
9.3.1 Overloaded operators >> and << 216
9.3.2 The put() Function 218
9.3.3 The get() and getline() Functions 218
9.3.4 The read() and write() Functions 221
9.4 Access to Files 223
9.4.1 Opening and Closing a File 223
9.4.2 Checking the End of a File 227
9.4.3 Sequential Access to a File 227
9.4.4 Random Access to a File 229
9.5 Case study 233
9.6 Exercises 235
Chapter 10 Comprehensive Cases Analysis 237
10.1 Student Grade Management System 237
10.2 Object-Oriented Analysis and Design 238
10.2.1 Use Case Diagram 238
10.2.2 Class Diagram 238
10.3 Module Design and Corresponding Code Implementation 241
10.3.1 Sequence Diagram and Code Implementation for System Management 241
10.3.2 Sequence Diagram and Code for Grade Management 243
10.3.3 Sequence Diagram and Code for Grade Query 245
10.4 The Whole C++ Codes of the Project 247
10.4.1 Main Menu of the Project. 247
10.4.2 The Class Admin 251
10.4.3 The Class Course and the Class CourseManage 252
10.4.4 The Class Grade and the Class GradeManage 257
10.4.5 The Class Person and the Class PersonManage 264
10.4.6 The Class Teacher and the Class TeacherManage 269
References 274