Problem Solving with C++: The Object of Programming (3rd Edition)
A Resource-Not a Straightjacket  Early Classes   Flexibility in Topic Ordering   Summary Boxes   Support Material  AcknowledgmentsThis book is meant to be used in a first course in programming and computer science using the C++ language. It assumes no previous programming experience and no mathematics beyond high school algebra. It could also be used as a text for a course designed to teach C++ to students who have already had some other programming course, in which case the first few chapters can be assigned as outside reading.A Resource-Not a StraightjacketMost introductory textbooks that use C++ have a very detailed agenda that an instructor must follow in order to use the book in a class. If you are an instructor, this book adapts to the way you teach, rather than making you adapt to the book. This book explains C++ and basic programming techniques in a way suitable for beginning students, but it does not tightly prescribe the order in which your course must cover topics and does not prescribe the specialized libraries, if any, that must be used in your course. You can easily change the order in which chapters and sections are covered without loss of continuity in reading the book. The details about rearranging material are explained in the section of this preface on flexibility. Although this book uses libraries and teaches students the importance of libraries, it requires no special libraries. It was designed to be used with a "standard" C++ implementation and only uses libraries that are provided with essentially all C++ implementations. Instructors who wish to do so may use additional libraries of their own choosing.Early ClassesThere are at least two ways that a book can introduce classes early. A book can teach students how to design their own classes early in the book or it can merely teach them how to use classes early without defining them. This book teaches students to design and define their own classes early and does not merely teach them how to use classes early. In order to effectively design classes, a student needs some basic tools such as some simple control structures and function definitions. This book thus starts out covering these basics in chapters 2, 3, and 4. It then moves immediately to classes. In Chapter 5 file I/O streams are used to teach students how to use classes. In Chapter 6 students learn how to write their own classes.This book uses a measured approach to classes. It teaches students to write some very simple  classes, then adds constructors, then overloading simple operators, then overloading the I/O  operators >, and so forth. This measured approach keeps the student from being  overwhelmed with a long list of complicated constructions and concepts. However, one goal of this  book is to get students writing realistic class definitions as soon as possible, and not to have them  spending time writing classes that are artificially simple. By the end of Chapter 8, they are writing  essentially the same kinds of classes that they will be writing when they finish the course.There are a few topics related to classes that are not introduced at the beginning. Destructors,  templates, and sophisticated use of inheritance are not introduced early.Destructors are not introduced until dynamic data structures are covered. Introducing them before  dynamic data structures would be pointless, since they would have no purpose.Templates are not introduced early for three reasons: First, many compilers still do not handle them  gracefully. With many compilers, class templates require special care if they are to be compiled  separately. Often separate compilation of class templates has restrictions that make separate  compilation impractical. Second, a template is a schema that generates numerous nontemplate  classes. Thus, before one can understand what a template class is, one needs to know what a  nontemplate class is. Once a student is comfortable with nontemplate classes, template classes are  an easy and natural generalization. Third, many of the examples that benefit most from templates  are data structures, like stacks and queues, which are usually not covered until the second  programming course. However, if an instructor wishes to cover templates earlier, the material on  templates was written so that it can be moved to earlier in the course.Inheritance is covered briefly in Chapter 5 so that students become aware of the concept. However,  this book does not teach students how to write their own derived classes. The reason for this is that  the examples that strongly motivate inheritance and derived classes often do not arise until the  second course. One can make a point of introducing examples that use derived classes in the first  course, but it is difficult for students to get much realistic utility out of derived classes until they are  more sophisticated programmers. These more advanced topics can easily be introduced later, and  even without these topics students have a sophisticated and realistic concept of classes. Brief  coverage of how to write derived classes is given in an appendix.Even though we postpone the discussion of destructors and templates, the classes that are used  early in the book are very sophisticated and many would argue that they are too complicated to be  covered so early in a first programming course. After all, in addition to the basic notions of  member variables and member functions, beginning students reading this book will learn all of the  following topics very early: public and private members, function overloading, operator  overloading, friend functions, returning a reference so that they can overload the I/O operators >, constructors for automatic initialization, constructors for type conversion, and a number of  smaller issues. Many would argue that this is too much to give students so early. We have class  tested this material and found that the examples become unrealistic or poorly behaved if we omit  any of these topics. Moreover, in class testing we found that students respond to early classes in  basically the same way that they respond to early functions. Certainly the material presents some  problems. However, they are as capable of learning it early in the course as they will be later in the  course. Moreover, covering classes early leaves students with a better working knowledge of  classes. Students have a strong loyalty to the first technique they learn for solving a problem. So, if  you want them to really use a technique, then you need to teach it early. Moreover, classes are not  the hardest topic the students encounter. For example, classes are more intuitive and better behaved  than ordinary (C style) arrays, which they learn later in the course.Having made the case for early classes, we are still aware that not everybody wants to introduce  classes as early as we do and so we have written the book to allow instructors to move coverage of  classes to later in the course. This is discussed in the section of this preface on flexibility.Flexibility in Topic OrderingThis book was written to allow instructors wide latitude  in reordering  the  material. Our goal was to write the book so that an instructor making the  transition  to  teaching  the introductory  course  in  C++  could,  if she or he desired, start with a course that is essentially an  ANSI  C  course, change  the  course  slightly  each  term  it is taught, and quickly be teaching a course that is a full-blown C++ course with  students  defining  their  own  classes  early  in the course. We would urge instructors to move  along  this  path quickly,  but  that  decision  is  up to each instructor. To illustrate this flexibility we give a number of  alternative orderings  of  topics after this paragraph. There is no loss of continuity when the book is read in any of these  orders. In  order  to  ensure  this  continuity  when  you rearrange material you do need to sometimes move sections rather  than entire  chapters. However, only large sections in convenient locations are moved. Under any of these orderings,  whenever a chapter is first introduced the chapter is covered without interruption up to some point. One  cut  point  is  inserted into  the  chapter  and  all  the material before the cut is moved as a unit and all the material after the cut is  moved as  another  unit.  To  help  customize  an  ordering to any particular  class's  needs,  the  dependency  charts,  which follow  this  preface, describe many more possible orders in which the chapters and sections can be covered without  loss of continuity.Reordering 1: Late ClassesThis version essentially covers all  of  an  ANSI  C  course before  going  on  to  cover classes. The only thing that is very C++ like before the introduction of classes is the  use of streams for I/O:Basics: Chapters 1, 2, 3, 4, 5, and 7 (omitting Chapter 6 on  defining  classes).  This  material  covers  all  of control  structures, function definitions, and basic file I/O.Arrays: Chapters 9 omitting the last section (section  9.4),  which  uses  classes.  Chapter  10 omitting the last section  (sectio--This text refers to an out of print or unavailable edition of this title.