Teaching Approach
Small C++ How to Program, 5/e contains an abundant collection of examples, exercises and projects drawn from many fields to provide the student with a chance to solve interesting real-world problems. The book concentrates on the principles of good software engineering and stresses program clarity. We avoid arcane terminology and syntax specifications in favor of teaching by example. We are educators who teach programming languages courses in industry classrooms worldwide. Dr. Harvey M. Deitel has 20 years of college teaching experience, including serving as chairman of the Computer Science Department at Boston College, and 15 years of industry teaching experience. Paul Deitel has 12 years of industry teaching experience. The Deitels have taught C++ courses at all levels to the government, industry, military and academic clients of Deitel & Associates.
Learning C++ using the Live-Code Approach
Small C++ How to Program, 5/e, is loaded with C++ programs-each new concept is presented in the context of a complete working C++ program that is immediately followed by one or more sample executions showing the program's inputs and outputs. This style exemplifies the way we teach and write about programming. We call this method of teaching and writing the Live-Code Approach. We use programming languages to teach programming languages. Reading the examples in the text is much like typing and running them on a computer. We provide all the source code for the book's examples at www.deitel.com and on the accompanying CD-making it easy for students to run each example as they study it.
World Wide Web Access
All the source-code examples for Small C++ How to Program, 5/e, (and our other publications) are available on the Internet as downloads from
www.deitel.com
Registration is quick and easy, and the downloads are free. We suggest downloading all the examples (or copying them from the CD included in the back of this book), then running each program as you read the corresponding text. Making changes to the examples and immediately seeing the effects of those changes is a great way to enhance your C++ learning experience.
Objectives
Each chapter begins with a statement of objectives. This lets students know what to expect and gives them an opportunity, after reading the chapter, to determine if they have met these objectives. This is a confidence builder and a source of positive reinforcement.
Quotations
The learning objectives are followed by quotations. Some are humorous, some philosophical and some offer interesting insights. We hope that you will enjoy relating the quotations to the chapter material. Many of the quotations are worth a second look after reading the chapter.
8,720 Lines of Syntax-Colored Code in 124 Example Programs with Live Sample Program Inputs and Outputs
Our Live-Code programs range in size from just a few lines of code to substantial larger examples. Each program is followed by a window containing the input/output dialogue produced when the program is run, so students can confirm that the programs run as expected. Relating outputs to the program statements that produce them is an excellent way to learn and to reinforce concepts. Our programs demonstrate the diverse features of C++. The code is line-numbered and syntax colored-with C++ keywords, comments and other program text appearing in different colors. This facilitates reading the code-students will especially appreciate the syntax coloring when they read the larger programs.
402 Illustrations/Figures
An abundance of charts, tables, line drawings, programs and program outputs is included. We model the flow of control in control statements with UML activity diagrams. UML class diagrams model the data members, constructors and member functions of classes.
403 Programming Tips
We include programming tips to help students focus on important aspects of program development. We highlight these tips in the form of Good Programming Practices, Common Programming Errors, Performance Tips, Portability Tips, Software Engineering Observations and Error-Prevention Tips. These tips and practices represent the best we have gleaned from a combined six decades of programming and teaching experience. One of our students, a mathematics major, told us that she feels this approach is like the highlighting of axioms, theorems, lemmas and corollaries in mathematics books-it provides a basis on which to build good software.
Good Programming Practices are tips for writing clear programs. These techniques help students produce programs that are more readable, self-documenting and easier to maintain.
Students who are new to programming (or a programming language) tend to make certain errors frequently. Focusing on these Common Programming Errors reduces the likelihood that students will make the same mistakes and shortens long lines outside instructors' offices during office hours!
.In our experience, teaching students to write clear and understandable programs is by far the most important goal for a first programming course. But students want to write the programs that run the fastest, use the least memory, require the smallest number of keystrokes or dazzle in other nifty ways. Students really care about performance. They want to know what they can do to "turbo charge" their programs. So we highlight opportunities for improving program performance-making programs run faster or minimizing the amount of memory that they occupy.
Software development is a complex and expensive activity. Organizations that develop software must often produce versions customized to a variety of computers and operating systems. So there is a strong emphasis today on portability, i.e., on producing software that will run on a variety of computer systems with few, if any, changes. Some programmers assume that if they implement an application in standard C++, the application will be portable. This simply is not the case. Achieving portability requires careful and cautious design. There are many pitfalls. We include Portability Tips to help students write portable code and to provide insights on how C++ achieves its high degree of portability.
The object-oriented programming paradigm necessitates a complete rethinking of the way we build software systems. C++ is an effective language for achieving good software engineering. The Software Engineering Observations highlight architectural and design issues that affect the construction of software systems, especially large-scale systems. Much of what the student learns here will be useful in upper-level courses and in industry as the student begins to work with large, complex real-world systems.
When we first designed this "tip type," we thought we would use it strictly to tell people how to test and debug C++ programs. In fact, many of the tips describe aspects of C++ that reduce the likelihood of "bugs" and thus simplify the testing and debugging processes.
Wrap-Up Sections
Each chapter ends with additional pedagogical devices. New in this edition, each chapter ends with a brief "wrap-up" section that recaps the topics that were presented. The wrap-ups also help the student transition to the next chapter.
Summary (567 Summary bullets)
We present a thorough, bullet-list-style summary at the end of every chapter. On average, there are 43 summary bullets per chapter. This focuses the student's review and reinforces key concepts.
333 Self-Review Exercises and Answers (Count Includes Separate Parts)
Extensive self-review exercises and answers are included for self-study. This gives the student a chance to build confidence with the material and prepare for the regular exercises. We encourage students to do all the self-review exercises and check their answers.
543 Exercises (Solutions in Instructor's Manual; Count Includes Separate Parts)
Each chapter concludes with a substantial set of exercises including simple recall of important terminology and concepts; writing individual C++ statements; writing small portions of C++ functions and classes; writing complete C++ functions, classes and programs; and writing major term projects. The large number of exercises enables instructors to tailor their courses to the unique needs of their audiences and to vary course assignments each semester. Instructors can use these exercises to form homework assignments, short quizzes and major examinations. The solutions for the vast majority of the exercises are included on the Instructor's Resource CD (IRCD), which is available only to instructors through their Prentice Hall representatives. [NOTE: Please do not write to us requesting the Instructor's CD. Distribution of this ancillary is limited strictly to college instructors teaching from the book. Instructors may obtain the solutions manual only from their Prentice Hall representatives.] Students will have access to approximately half the exercises in the book in the free, Web-based Cyber Classroom which will be available in late spring 2005. For more information about the Cyber Classroom, please visit www.deitel.com or sign up for the free Deitel? Buzz Online e-mail newsletter at www.deitel.com/newsletter/subscribe.html.
Software Bundled with Small C++ How to Program, 5/e
For the academic educational market only, this textbook is available in a value pack with Microsoft? Visual C++ .NET 2003 Standard Edition integrated development environment as a free supplement. There is no time limit for using the software. [Note: If you are a professional using this publication, you will have to either purchase the necessary software to build and run the applications in this textbook or download one of the many free compilers available online.][Note: If you are a student in a course for which this book is the required textbook, you must purchase your book from your college bookstore to ensure that you get the value pack with the software. College bookstores will need to order the books directly from Prentice Hall to get the value pack with the software. A caution-used books may not include the software.]
Free C++ Compilers and Trial-Edition C++ Compilers on the Web
Many C++ compilers are available for download from the Web. We discuss several that are available for free or as free-trial versions. Please keep in mind that in many cases, the trial-edition software cannot be used after the (often brief) trial period has expired.
One popular organization that develops free software is the GNU Project (www.gnu.org), originally created to develop a free operating system similar to UNIX. GNU offers developer resources, including editors, debuggers and compilers. Many developers use the GCC (GNU Compiler Collection) compilers, available for download from gcc.gnu.org. The GCC contains compilers for C, C++, Java and other languages. The GCC compiler is a command-line compiler (i.e., it does not provide a graphical user interface). Many Linux and UNIX systems come with the GCC compiler installed. Red Hat has developed Cygwin (www.cygwin.com), an emulator that allows developers to use UNIX commands on Windows. Cygwin includes the GCC compiler.
Borland provides a Windows-based C++ developer product called C++Builder (www.borland.com/cbuilder/cppcomp/index.html). The basic C++Builder compiler (a command-line compiler) is free for download. Borland also provides several versions of C++Builder that contain graphical user interfaces (GUIs). These GUIs are formally called integrated development environments (IDEs) and enable the developer to edit, debug and test programs quickly and conveniently. Using an IDE, many of the tasks that involved tedious commands can now be executed via menus and buttons. Some of these products are available on a free-trial basis. For more information on C++Builder, visit
www.borland.com/products/downloads/download_cbuilder.html
For Linux developers, Borland provides the Borland Kylix development environment. The Borland Kylix Open Edition, which includes an IDE, can be downloaded from
www.borland.com/products/downloads/download_kylix.html
Borland also provides C++BuilderX-a cross-platform integrated C++ development environment. The free Personal Edition is available from
www.borland.com/products/downloads/download_cbuilderx.html
The command-line compiler (version 5.6.4) that comes with C++BuilderX was one of several compilers we used to test the programs in this book. Many of the downloads available from Borland require users to register.
The Digital Mars C++ Compiler (www.digitalmars.com), is available for Windows and DOS, and includes tutorials and documentation. Readers can download a command-line or IDE version of the compiler. The DJGPP C/C++ development system is available for computers running DOS. DJGPP stands for DJ's GNU Programming Platform, where DJ is for DJ Delorie, the creator of DJGPP. Information on DJGPP can be found at www.delorie.com/djgpp. Locations where the compiler can be downloaded at are provided at www.delorie.com/djgpp/getting.html.
For a list of other compilers that are available free for download, visit the following sites:
www.thefreecountry.com/compilers/cpp.shtml
www.compilers.net
Warnings and Error Messages on Older C++ Compilers
The programs in this book are designed to be used with compilers that support standard C++. However, there are variations among compilers that may cause occasional warnings or errors. In addition, though the standard specifies various situations that require errors to be generated, it does not specify the messages that compilers should issue. Warnings and error messages vary among compilers-this is normal.
Some older C++ compilers, such as Microsoft Visual C++ 6, Borland C++ 5.5 and various earlier versions of GNU C++, generate error or warning messages in places where newer compilers do not. Although most of the examples in this book will work with these older compilers, there are a few examples that need minor modifications to work with older compilers. The Web site for this book (www.deitel.com/books/scpphtp5/index.html) lists the warnings and error messages that are produced by several older compilers and what, if anything, you can do to fix the warnings and errors.
Notes Regarding using Declarations and C Standard Library Functions
The C++ Standard Library includes the functions from the C Standard Library. According to the C++ standard document, the contents of the header files that come from the C Standard Library are part of the "std" namespace. Some compilers (old and new) generate error messages when using declarations are encountered for C functions. We will post a list of these issues at www.deitel.com/books/scpphtp5/index.html.
Dive-Into? Series Tutorials for Popular C++ Environments
Our free Dive-Into? Series publications, which are available with the resources for Small C++ How to Program, 5/e at www.deitel.com/books/downloads.html, help students and instructors familiarize themselves with various C++ development tools. These publications include:
Dive-Into Microsoft? Visual C++? 6
Dive-Into Microsoft? Visual C++? .NET
Dive-Into Borland?C++Builder? Compiler (command-line version)
Dive-Into Borland? C++Builder? Personal (IDE version)
Dive-Into GNU C++ on Linux and Dive-Into GNU C++ via Cygwin on Windows (Cygwin is a UNIX emulator for Windows. It includes the GNU C++ compiler)
Each of these tutorials shows how to compile, execute and debug C++ applications in that particular compiler product. Many of these documents also provide step-by-step instructions with screenshots to help readers install the software. Each document overviews the compiler and its online documentation.
Teaching Resources for Small C++ How to Program, 5/e
Small C++ How to Program, 5/e, has extensive resources for instructors. The Instructor's Resource CD (IRCD) contains the Solutions Manual with solutions to the vast majority of the end-of-chapter exercises, a Test Item File of multiple-choice questions (approximately two per book section) and PowerPoint slides containing all the code and figures in the text, plus bulleted items that summarize the key points in the text. Instructors can customize the slides. [Note: The IRCD is available only to instructors through their Prentice Hall representatives. To find your local sales representative, visit
vig.prenhall.com/replocator
If you need additional help or if you have any questions about the IRCD, please email us at deitel@deitel.com. We will respond promptly.]
C++ Multimedia Cyber Classroom, 5/e, Online
C++ How to Program, 5/e and Small C++ How to Program, 5/e each include a free, Web-based interactive multimedia ancillary to the book-The C++ Multimedia Cyber Classroom, 5/e-available with the purchase of a new book. Our Web-based Cyber Classroom will include audio walkthroughs of code examples in the text, solutions to about half of the exercises in the book, a free lab manual and more. For more information about the new Web-based Cyber Classroom, please visit our Web site at www.deitel.com or sign up for the free Deitel? Buzz Online e-mail newsletter at
www.deitel.com/newsletter/subscribe.html.
Students who use our Cyber Classrooms tell us that they like the interactivity and that the Cyber Classroom is a powerful reference tool. Professors tell us that their students enjoy using the Cyber Classroom and consequently spend more time on the courses, mastering more of the material than in textbook-only courses. For a complete list of our current CD-ROM-based Cyber Classrooms, see the Deitel? Series page at the beginning of this book, the product listing and ordering information at the end of this book, or visit www.deitel.com, www.prenhall.com/deitel or www.InformIT.com/deitel.
C++ in the Lab
C++ in the Lab: Lab Manual to Accompany C++ How to Program, 5/e, our online lab manual that is now part of the Cyber Classroom, complements C++ How to Program, 5/e, and Small C++ How to Program, 5/e, with hands-on lab assignments designed to reinforce students' comprehension of lecture material. C++ in the Lab will be available with new books purchased from Prentice Hall for fall 2005 classes. This lab manual is designed for closed laboratories-regularly scheduled classes supervised by an instructor. Closed laboratories provide an excellent learning environment, because students can use concepts presented in class to solve carefully designed lab problems. Instructors are better able to measure the students' understanding of the material by monitoring the students' progress in lab. This lab manual also can be used for open laboratories, homework and for self-study.
Chapters 1-13 in the lab manual are divided into Prelab Activities, Lab Exercises and Postlab Activities. Each chapter contains objectives that introduce the lab's key topics and an assignment checklist for students to mark which exercises the instructor has assigned.
Solutions to the lab manual's Prelab Activities, Lab Exercises and Postlab Activities are available in electronic form. Instructors can obtain these materials from their regular Prentice Hall representatives; the solutions are not available to students.
Prelab Activities
Prelab Activities are intended to be completed by students after studying each chapter of Small C++ How to Program, 5/e. Prelab Activities test students' understanding of the textbook material and prepare students for the programming exercises in the lab session. The exercises focus on important terminology and programming concepts and are effective for self-review. Prelab Activities include Matching Exercises, Fill-in-the-Blank Exercises, Short-Answer Questions, Programming-Output Exercises (determine what short code segments do without actually running the program) and Correct-the-Code Exercises (identify and correct all errors in short code segments).
Lab Exercises
The most important section in each chapter is the Lab Exercises. These teach students how to apply the material learned in Small C++ How to Program, 5/e, and prepare them for writing C++ programs. Each lab contains one or more lab exercises and a debugging problem. The Lab Exercises contain the following:
Lab Objectives highlight specific concepts on which the lab exercise focuses.
Problem Descriptions provide the details of the exercise and hints to help students implement the program.
Sample Outputs illustrate the desired program behavior, which further clarifies the problem descriptions and aids the students with writing programs.
Program Templates take complete C++ programs and replace key lines of code with comments describing the missing code.
Problem-Solving Tips highlight key issues that students need to consider when solving the lab exercises.
Follow-Up Questions and Activities ask students to modify solutions to lab exercises, write new programs that are similar to their lab-exercise solutions or explain the implementation choices that were made when solving lab exercises.
Debugging Problems consist of blocks of code that contain syntax errors and/or logic errors. These alert students to the types of errors they are likely to encounter while programming.
Postlab Activities
Professors typically assign Postlab Activities to reinforce key concepts or to provide students with more programming experience outside the lab. Postlab Activities test the students' understanding of the Prelab and Lab Exercise material, and ask students to apply their knowledge to creating programs from scratch. The section provides two types of programming activities: coding exercises and programming challenges. Coding exercises are short and serve as review after the Prelab Activities and Lab Exercises have been completed. The coding exercises ask students to write programs or program segments using key concepts from the textbook. Programming Challenges allow students to apply their knowledge to substantial programming exercises. Hints, sample outputs and pseudocode are provided to aid students with these problems. Students who successfully complete the Programming Challenges for a chapter have mastered the chapter material. Answers to the programming challenges are available at www.deitel.com/books/downloads.html.
CourseCompassSM, WebCTTM and BlackboardTM
Selected content from the Deitels' introductory programming language How to Program series textbooks, including Small C++ How to Program, 5/e, is available to integrate into various popular course management systems, including CourseCompass, Blackboard and WebCT. Course management systems help faculty create, manage and use sophisticated Web-based educational tools and programs. Instructors can save hours of inputting data by using the Deitel course-management-systems content.
Blackboard, CourseCompass and WebCT offer:
Features to create and customize an online course, such as areas to post course information (e.g., policies, syllabi, announcements, assignments, grades, performance evaluations and progress tracking), class and student management tools, a gradebook, reporting tools, page tracking, a calendar and assignments.
Communication tools to help create and maintain interpersonal relationships between students and instructors, including chat rooms, whiteboards, document sharing, bulletin boards and private e-mail.
Flexible testing tools that allow an instructor to create online quizzes and tests from questions directly linked to the text, and that grade and track results effectively. All tests can be inputted into the gradebook for efficient course management. WebCT also allows instructors to administer timed online quizzes.
Support materials for instructors are available in print and online formats.
In addition to the types of tools found in Blackboard and WebCT, CourseCompass from Prentice Hall includes:
CourseCompass course home page, which makes the course as easy to navigate as a book. An expandable table of contents allows instructors to view course content at a glance and to link to any section.
Hosting on Prentice Hall's centralized servers, which allows course administrators to avoid separate licensing fees or server-space issues. Access to Prentice Hall technical support is available.
"How Do I" online-support sections are available for users who need help personalizing course sites, including step-by-step instructions for adding PowerPoint slides, video and more.
Instructor Quick Start Guide helps instructors create online courses using a simple, step-by-step process.
To view free online demonstrations and learn more about these Course Management Systems, which support Deitel content, visit the following Web sites:
Blackboard: www.blackboard.com and www.prenhall.com/blackboard
WebCT: www.webct.com and www.prenhall.com/webct
CourseCompass: www.coursecompass.com and www.prenhall.com/coursecompass
About the Authors
Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 43 years experience in the computing field, including extensive industry and academic experience. Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts Institute of Technology and a Ph.D. from Boston University. He worked on the pioneering virtual-memory operating-systems projects at IBM and MIT that developed techniques now widely implemented in systems such as UNIX, Linux and Windows XP. He has 20 years of college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military. He and Paul are the co-authors of several dozen books and multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels' texts have earned international recognition.
Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of MIT's Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered C++, Java, C, Internet and World Wide Web courses to industry clients including IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, PalmSource, White Sands Missile Range, Rogue Wave Software, Boeing, Stratus, Cambridge Technology Partners, TJX, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems and many other organizations. Paul is one of the world's most experienced Java and C++ corporate trainers having taught over 100 professional Java and C++ training courses. He has also lectured on C++ and Java for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world's best-selling Computer Science textbook authors.
About Deitel & Associates, Inc.
Deitel & Associates, Inc., is an internationally recognized corporate training and content-creation organization specializing in computer programming languages, Internet/World Wide Web software technology and object technology education. The company provides instructor-led courses on major programming languages and platforms such as Java, Advanced Java, C, C++, .NET programming languages, XML, Perl, Python; object technology; and Internet and World Wide Web programming. The founders of Deitel & Associates, Inc., are Dr. Harvey M. Deitel and Paul J. Deitel. The company's clients include many of the world's largest computer companies, government agencies, branches of the military and business organizations. Through its 29-year publishing partnership with Prentice Hall, Deitel & Associates, Inc. publishes leading-edge programming textbooks, professional books, interactive multimedia Cyber Classrooms, Complete Training Courses, Web-based training courses and course management systems e-content for popular CMSs such as WebCT, Blackboard and Pearson's CourseCompass. Deitel & Associates, Inc., and the authors can be reached via e-mail at:
deitel@deitel.com
To learn more about Deitel & Associates, Inc., its publications and its worldwide Dive Into? Series Corporate Training curriculum, see the last few pages of this book or visit:
www.deitel.com
and subscribe to the free Deitel? Buzz Online e-mail newsletter at:
www.deitel.com/newsletter/subscribe.html
Individuals wishing to purchase Deitel books, Cyber Classrooms, Complete Training Courses and Web-based training courses can do so through:
www.deitel.com/books/index.html
Bulk orders by corporations and academic institutions should be placed directly with Prentice Hall. See the last few pages of this book for worldwide ordering details.