( the book home page)
In particular, this is a book designed to teach programming using C++, not a book designed to teach C++. Nevertheless, I expect students who use this book will be reasonably adept C++ programmers. Object-oriented programming is not a programmer's panacea although it can make some jobs much easier. To mix metaphors, no matter how you slice it learning to program is a hard task --- it takes time to master just as bread takes time to rise.
The material here is grounded in the concept that the study of computer science should be part of the study of programming. It is also based on the idea that program design is a very difficult task for novices to master, but that program enhancement or modification (a much more manageable skill) permits beginning programmers to develop programming skills in the context of meaningful programs. Most importantly, this book takes the view that the study of computer science should involve hands-on activity and should be fun. The study of programming must cover those areas that are acknowledged as fundamental to computer science, but should do so in such a way that the foundation that is constructed during this study can be used to study current trends that change and should do so in a way that enables students to want to learn more. Support for this position can be found in several places, I offer two quotes that express my sentiments quite well.
Having surveyed the relationships of computer science with other disciplines, it remains to answer the basic questions: What is the central core of the subject? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple --- it is the art of programming a computer. It is the art of designing efficient and elegant methods of getting a computer to solve problems, theoretical or practical, small or large, simple or complex. It is the art of translating this design into an effective and accurate computer program. This is the art that must be mastered by a practising computer scientist; the skill that is sought by numerous advertisements in the general and technical press; the ability that must be fostered and developed by computer science courses in universities.C.A.R. Hoare
A supporting view is expressed in the following quote:
Programming is unquestionably the central topic of computing.John V. Guttag
In addition to being important, programming is an enormously exciting intellectual activity. In its purest form, it is the systematic mastery of complexity. For some problems, the complexity is akin to that associated with designing a fine mechanical watch, i.e., discovering the best way to assemble a relatively small number of pieces into a harmonious and efficient mechanism. For other problems, the complexity is more akin to that associated with putting a man on the moon, i.e, managing a massive amount of detail.
In addition to being important and intellectually challenging, programming is a great deal of fun. Programmers get to build things and see them work.. What could be more satisfying?
I believe that a one-semester course that attempts to cover programming to the same extent as is done in a traditional Pascal, C, or C++ CS1 course and, at the same time, attempts to cover at even a superficial level the core areas of computer science is most likely doomed to failure. There is simply too much material to be covered.
At the same time, there has been an unfortunate though well-motivated tendency in many colleges and universities to move from Pascal-based courses to C-based courses. There are many good reasons for this change, but there is a fundamental pedagogical flaw in using C in a first course that more than counterbalances all the good reasons that so many have propounded: C is not designed to insulate the novice programmer from the machine --- as such it is a disaster when used in a first course.(It is possible to use C in a first course in a reasonable way, but the only example of doing this that I have seen is in a book by Eric Roberts, The Art and Science of C. Using C++ is much simpler than using C.)
Of course these statements not only border on hyperbole, they embrace it with open arms. Nevertheless, watching students struggle with the many idiosyncrasies of C while trying to develop and master general principles of programming has not been a pretty sight --- we did just this for several years before switching to C++ in our first course. At one level, the approach used in this book is the approach we adopted initially in our courses --- C++ is simply a much better C. At a superficial level its I/O support and its support of more than one mode of parameter passing --- by value and by reference --- free students from worrying about pointers in the first week of the course. At a deeper level C++ and its support of objects and libraries allows students to make use of supplied code in a standard and useful way.
Introductory courses are evolving to take advantage of new and current trends in software-engineering and programming language design. One of these trends is object-oriented design and object-oriented programming or OOP. Some schools will adopt the approach that learning object-oriented principles should be the focus of a first programming course. Although this approach certainly has some merit, students in the first course traditionally have a very difficult time with the design of programs. I believe that attempting to cover program design in addition to object design will not be as conducive to a successful programming experience as will using object-oriented concepts in the context of learning to program by reading programs before writing them. This may seem a subtle distinction, but if the focus of the course is on learning about the design and use of both objects and programs, there may be a tendency to delve too quickly and too deeply into the details of C++.
The approach taken in this book is that C++ and OOP permit students with little or no programming background to make great strides towards developing foundational knowledge and expertise in programming. In subsequent courses students will hone the skills that are first learned in the study of the material in this book and will expand the coverage of computer science begun here. Computer science is not just programming, and students in a first course in computer science must be shown something of what the discipline is about. At the same time, programming provides a means of relating the subdisciplines that comprise computer science. Many of the examples and programs in this book rely on the use of classes, code, and libraries that are documented and supplied. It is possible that these examples could be studied using C rather than C++, but this would be very cumbersome and difficult to do in anything but an ad-hoc manner specific to this book at best.
A major tenet of the approach used here is that students should read, modify, and extend programs before designing and writing from scratch. This is enabled to a large extent by using the object-oriented features of C++ whenever appropriate. However, neither I nor the book are compelled to delve into design methodologies and features of OOP; C++ is a tool to be used rather than studied. One of the most important ideas underlying the use of classes and objects in C++ and one of the most important concepts in computer science is the idea of abstraction.
Its [computer science] study involves development of the ability to abstract the essential features of a problem and its solution, to reason effectively in the abstract plane, without confusion by a mass of highly relevant detail. The abstraction must then be related to the detailed characteristics of computers as the design of the solution progresses; and it must culminate in a program in which all the detail has been made explicit; and at this stage, the utmost care must be exercised to ensure a very high degree of accuracy. At all stages the programmer must be articulate about his activity. The need for abstract thought together with meticulous accuracy, the need for imaginative speculation in the search for a solution, together with a sound knowledge of the practical limitations of the tools available for its implementation, the combination of formal rigour with a clear style for its explanation to others --- these are the combinations of attributes which should be inculcated and developed in a student by any university academic discipline; and which must be developed in high degree in students of computer science.C.A.R. Hoare
Students and teachers of computer science are not obliged to understand the IEEE standards for floating point numbers in order to write code that uses such numbers. Although at one time a deep understanding of machine architecture was necessary in order to write programs, this is no longer the case. Just as Hoare exhorts the programmer to be articulate about his or her activity, this book is designed to bring the novice programmer and student of computer science to a point where such behavior is possible. The use of C++ provides a mechanism for doing this so that details can be revealed if and when it is appropriate to do so and hidden otherwise.
Many thought and programming exercises are integrated in the text, particularly in the pause and reflect sections. These exercises are designed to make students think about what they're doing, and to cover some of the messier language details in thought-provoking and interesting ways. Online materials accessible via the world-wide web will provide supporting programming lab assignments.
In addition, the following people have reviewed the material and offered many useful suggestions (if I've left someone out, I apologize).
Educational Testing Service
| Clayton Lewis
University of Colorado
| Bob Noonan
College of William and Mary
| Richard Prosl
College of William and Mary
| Stephen Schach
| Andrew Holey
St. John's University
| David Teague
Western Carolina University
| Robert Plantz
Sonoma State University
| Arthur Farley
University of Oregon
| David Mutchler
| Deganit Armon
| Stuart Reges
University of Arizona
| Jerry Mead
Students in the Fall 1994 CPS 06 and 08 courses at Duke suffered through a draft of the material here. Several of them offered useful suggestions that appear in this draft. In particular Travis Pouarz and Derek Mims combed the material for errors and offered useful improvements. Students in the Spring, 1995 CPS 08 course had to make do with a version of the book with no index. Nevertheless, several students made useful suggestions. In particular, Jay Kamm found many errors, even looking at code that wasn't in the book and offering suggestions.
Students in the Fall 1995 CPS 06 course had a book with an index, but the pages fell out. These students persevered, and new books arrived. In the interim several students combed the book for typos. I cannot possibly thank them all enough, but one stands out for her diligence: Christine Hong found countless errors and made many suggestions for improvement. Mackenzie Steele offered several quotations in addition to finding errors.
Several schools used a beta-edition of the book, and the feedback from these schools has been incorporated into the final version. These schools include the University of Iowa, Rose-Hulman Institute of Technology, Gettysburg College, St. John's College (Minnesota), Mills College, and U. California, Berkeley.
Versions of all the programs used in the book are available for Mac, DOS, and Unix machines. The software is currently available via anonymous ftp in pub/ola/book/code. It is also accessible using your favorite browser (or you wouldn't be reading this)
Although beta-editions of the book have been through extensive classroom testing, there are undoubtedly errors that persist. Occasional slips of the tongue (or keyboard) have almost certainly crept into the manuscript.
Nevertheless, all code has been compiled and executed and is reproduced in this work directly from the source, it is not retyped. The material here is intended to provide complete coverage for many different kinds of introductory computer science courses based on C++.
I am anxious to correct all the errors and fuzzy, incoherent, or otherwise incomprehensible passages for the first (and hopefully not last) edition of the book. I am not anxious to hear about misplaced commas and semi-colons. I haven't mastered comma placement and will leave this to experts. I would be ecstatic to hear about methods that might improve certain sections, or comments about sections that caused problems even without suggestions for improvement.
Please send all comments by electronic mail , I will try to acknowledge all mail received. Materials for the book are also accessible via the world-wide web. A listserv is available for discussing any aspects of the book or course. To subscribe, send email with the message subscribe tapestry as the message body to email@example.com, to unsubscribe send the message unsubscribe tapestry to the same address. To send mail to the listserv use the address firstname.lastname@example.org.
To paraphrase Newton, the work in this book is not mine alone; I have stood on the shoulders of giants. Of course Newton paraphrased Robert Burton who said ``a dwarf standing on the shoulders of a giant may see farther than a giant himself.'' The styles used in several books serve as models for different portions of this text. In particular Eric Roberts' The Art and Science of C provided style guidelines for formatting; the book A Logical Approach to Discrete Math (by David Gries and Fred B. Schneider) motivated the biographies; books by Bjarne Stroustrup: The C++ Programming Language (2nd edition) and The Design and Evolution of C++ and Scott Meyers: Effective C++ were indispensable in delving into C++. Rick Mercer's C++ book, Computing Fundamentals with C++ provided a good example of how to do things well and simply. Stuart Reges' book Building Pascal Programs (now out of print) had a strong influence.
I've borrowed ideas from almost all the textbooks I've read in eighteen years of teaching, so I acknowledge them en masse.
Thanks to Duke University and the Computer Science Department for providing an atmosphere in which teaching is rewarded and this book is possible.
Finally, thanks to Laura for always understanding.