OBJECT-ORIENTED DESIGN AND PROGRAMMING IN c++ TABLE OF CONTENTS CHAPTER 0 SOFTWARE ENGINEERING PRINCIPLES 1 CHAPTER 1 OVERVIEW OF C++ 3 1.1 What is Object - Oriented Programming? 3 1.2 History of the C++ Programming Language 6 1.3 What is C++? 7 1.4 Classes 8 1.5 Inheritance, Polymorphism, and Overloading 8 Summary 11 Exercises 11 CHAPTER 2 ELEMENTARY PROGRAMMING IN C++ 13 2.1 Structure of a Single Unit C++ Program 13 2.2 Fundamental Data Types in C++ 18 2.3 Output with cout 24 2.4 Formatted output in C++ 27 2.5 Input with cin 31 2.6 Documentation and Commenting of C++ Programs 41 2.7 Control of C++ Programs 43 2.8 Operators in C++ 45 2.9 An Example - Processing An Input Stream 50 2.10 Differences in I/O Between C and C++ 52 2.11 Testing Issues 53 Summary 57 Exercises 58 CHAPTER 3 ELEMENTARY C++ PROGRAM STRUCTURE 59 3.1 Derived and Base Classes 59 3.2 Constructors, Destructors, and Other Functions 73 3.3 Passing Parameters to Functions in C and C++ 81 3.4 The inline Qualifier for Functions 82 3.5 Member and Friend Functions 85 3.6 The C++ Preprocessor 88 3.7 Library Functions and Class Libraries 102 3.8 Testing Issues 103 Summary 103 Exercises 104 CHAPTER 4 ARRAYS AND POINTERS 107 4.1 Pointers, Arrays, and Pointer Arithmetic 107 4.2 Array Indexing and Pointer Arithmetic in C++ 116 4.3 Multi-dimensional Arrays in C++ 119 4.4 Matrices in C++ 124 4.5 Interfacing with the Command Line - Parameters to main() 131 4.6 Pointers to Functions 134 4.7 Functions with a Variable Number of Arguments 143 4.8 Virtual Functions 147 4.9 Pointers to void 150 4.10 A Special Pointer - this 151 Summary 153 Exercises 154 CHAPTER 5 STRUCTURED DATA TYPES IN C++ 162 5.1 Classes, Structs, and Templates 162 5.2 Stacks in C++ 166 5.3 Implementing Stacks in C++ Using Templates 173 5.3 Lists in C++ 178 5.4 Implementation of Lists using Templates 183 5.5 Using Lists With Sparse Matrices 192 5.6 Queues in C++ 201 5.7 Implementation of Queues using Templates 207 5.8 The Tree Data Type in C++ 210 5.9 Implementation of Trees using Templates 216 5.10 The Standard C and C++ Libraries 221 5.11 Other C++ Class Libraries 225 Summary 229 Exercises 229 CHAPTER 6 ADVANCED INPUT AND OUTPUT 231 6.1 Input and Output in C and C++ 231 6.2 File Input and Output in C++ 233 6.3 Overloading the << and >> Operators 241 6.4 Using C++ File Streams for Random Access 245 Summary 248 Exercises 249 CHAPTER 7 ADVANCED C++ PROGRAM STRUCTURE 253 7.1 Separate Compilation 253 7.2 The make Utility and Separate Compilation 260 7.3 Organization of Class Libraries 264 7.4 Examples of Class Libraries 268 7.5 Testing Issues 269 7.6 Exceptions in C++ 271 Summary 279 Exercises 280 CHAPTER 8 MODELING OBJECT-ORIENTED SYSTEMS 283 8.1 Design Representations 283 8.1.1 Terminal concentrators 284 8.1.2 A flowchart representation for a terminal concentrator 285 8.1.3 A dataflow representation for a terminal concentrator 287 8.1.4 A pseudocode representation for a terminal concentrator 289 8.1.5 Other non-object-oriented representations for a terminal concentrator 290 8.1.6 An object-oriented representation for a terminal concentrator 291 8.2 Object-Oriented Systems 292 8.3 Class Design Issues 294 8.4 What is an Object? 295 8.5 An Example of Class Development - The String Class 298 8.6 Concepts Related to Objects 312 8.7 Design Representations for Object-Oriented Systems 313 Summary 317 Exercises 317 CHAPTER 9 AN EXAMPLE - A GRAPHICAL DATABASE 321 9.1 Requirements 321 9.2 Determination of Objects for Representation of Polyhedra 325 9.2.1 Use of polyhedra as fundamental objects 325 9.2.2 Use of faces as fundamental objects 328 9.2.3 Use of edges as fundamental objects 329 9.2.4 Use of vertices as fundamental objects 330 9.2.5 Selection of fundamental objects for describing polyhedra 330 9.3 Class Descriptions 331 9.4 A Graphical Database 338 Summary 348 Exercises 348 CHAPTER 10 TRANSITIONING TO AN OBJECT-ORIENTED SYSTEM 351 10.1 Introduction 351 10.2 Specifications for a File System Simulation 352 10.3 Procedurally-based System Design 357 10.4 Implementation Details for a Procedurally-based Disk Simulation 365 10.5 Source Code for Procedural System (Optional) 376 10.6 Reengineering a Procedurally-based System into an Object-Oriented One 388 10.7 An Object-Oriented Disk Simulation Program 389 10.8 Source Code for an Object-Oriented Solution 390 10.9 Comparison of Object-Oriented and Procedural Solutions 401 Summary 402 Exercises 402 References 405 APPENDIX 1 Reserved Words in C++ 409 APPENDIX 2 Syntax Summary of C++ 411 APPENDIX 3 Review of The C Language 423 APPENDIX 4 The ANSI Standard C Library 435 Appendix 4.1 Organization 435 Appendix 4.2 Commonly-Used Functions 435 Appendix 4.3 Some UNIX I/O C Functions 455 Appendix 4.4 Rarely-used Functions 456 Appendix 4.5 Constants, variables, and Types 458 APPENDIX 5 The Draft ANSI Standard C++ Library 463 APPENDIX 6 Answers to Selected Exercises 467