World Headquarters
Jones & Bartlett Learning
5 Wall Street
Burlington, MA 01803
978-443-5000
www.jblearning.com
Jones & Bartlett Learning books and products are available through most bookstores and online booksellers. To contact Jones & Bartlett Learning directly, call 800-832-0034, fax 978-443-8000, or visit our website, www.jblearning.com.
Substantial discounts on bulk quantities of Jones & Bartlett Learning publications are available to corporations, professional associations, and other qualified organizations. For details and specific discount information, contact the special sales department at Jones & Bartlett Learning via the above contact information or send an email to .
Copyright 2014 by Jones & Bartlett Learning, LLC, an Ascend Learning Company
All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without written permission from the copyright owner.
Programming and Problem Solving with C++, Comprehensive Sixth Edition is an independent publication and has not been authorized, sponsored, or otherwise approved by the owners of the trademarks or service marks referenced in this product.
Some images in this book feature models. These models do not necessarily endorse, represent, or participate in the activities represented in the images.
The screenshots in this product are for educational and instructive purposes only. All trademarks displayed are the trademarks of the parties noted therein. Such use of trademarks is not an endorsement by said parties of Jones & Bartlett Learning, its products, or its services, nor should such use be deemed an endorsement by Jones & Bartlett Learning of said third partys products or services.
Production Credits
Chief Executive Officer: Ty Field
President: James Homer
SVP, Editor-in-Chief: Michael Johnson
SVP, Chief Marketing Officer: Alison M. Pendergast
Executive Publisher: Kevin Sullivan
Senior Developmental Editor: Amy Bloom
Director of Production: Amy Rose
Production Assistant: Eileen Worthley
Marketing Manager: Lindsay White
Associate Marketing Manager: Cassandra Peterson
V.P., Manufacturing and Inventory Control: Therese Connell
Composition: Northeast Compositors, Inc.
Cover and Title Page Design: Scott Moden
Cover and Title Page Image: Toncsi/ShutterStock, Inc.
Matters of Style box: iStockphoto/Thinkstock
Theoretical Foundations box: iStockphoto/Thinkstock
Background Information box: SergeyIT/Shutterstock, Inc.
Software Engineering Tip box: iStockphoto/Thinkstock
Illustration of George Boole: Photos.com/Thinkstock
Printing and Binding: Edwards Brothers Malloy
Cover Printing: Edwards Brothers Malloy
To order this product, use ISBN: 978-1-284-02876-8
Library of Congress Cataloging-in-Publication Data
Dale, Nell B.
Programming and problem solving with C++: comprehensive sixth edition / Nell Dale and Chip Weems. -- Comprehensive sixth edition.
pages cm.
Includes index.
ISBN-13: 978-1-4496-9426-5 (pbk.)
ISBN-10: 1-4496-9426-8 (pbk.)
1. C++ (Computer program language) I. Weems, Chip. II. Title.
QA76.73.C153D34 2014
005.133--dc23
2012043491
6048
Printed in the United States of America
17 16 15 14 13 10 9 8 7 6 5 4 3 2 1
Contents
Preface
Introduction to the Comprehensive Sixth Edition
The first five editions of Programming and Problem Solving with C++ have consistently been among the best-selling computer science textbooks in the United States. These editions, as well as the Java, Ada, and Pascal versions, have been accepted widely as model textbooks for ACM/IEEE-recommended curricula for the CS1/C101 course, and for the Advanced Placement exam in computer science.
Throughout the successive editions of this book, one thing has not changed: our commitment to the student. As always, our efforts are directed toward making the sometimes difficult concepts of computer science more accessible to all students. This edition of Programming and Problem Solving with C++ continues to reflect our philosophy that a textbook should be like a guide, blazing a trail and leading its readers through territory that can initially seem difficult to navigate.
Changes to the Sixth Edition
Programming and Problem Solving with C++, Comprehensive Sixth Edition continues to offer expanded coverage with the goal of making the book suitable for use across two terms, thereby providing greater value for students.
In this edition we have replaced the use of function-notation casting with the more modern static_cast throughout the text. The Quick Check exercises now appear at the end of each section with their answers following the chapter summary. We have moved coverage of pointers so that is a new section on C strings and using them in combination with the C++ string class. We have not yet adopted features of the C++11 standard because many users are still working with C++03.
Pedagogical Approach
Our approach, as always, is to provide a gradual layering of concepts, rather than piling on details and related alternatives that can be overwhelming. For example, many texts begin by introducing numeric types. Instead, we start with char and string types in we add numeric types. By separating the conceptual hurdles of statement and program syntax from the complexities of types that involve numeric precision, signedness, casting and precedence, we make it possible for more students to succeed early in the course.
Based on the research of Elliot Soloway with novice programmers, we continue to initially cover selection using only the If statement, and loops using only the While statement. However, because many instructors like to cover all selection control structures together and all looping control structures together, the chapter on additional control structures is directly after the chapters on selection and looping.
Similarly, students find it easier to comprehend the struct type, with its named fields that can mix types, than the array type with indexes that often involve arithmetic expressions for access. Thus, so that students can become comfortable with indirect access prior to working with values on the heap.
Recognizing that many students learn programming from mimicking existing solutions, we include numerous short example programs in every chapter. These programs illustrate chapter concepts in a more complete context than code segments and appear immediately after the introduction of new concepts. We have also organized chapters so that the discussion moves more quickly from a concept to its practical application early in the chapter, before moving on to related concepts. Chapters thus offer a series of concrete examples that serve as intermediate waypoints on the path to the major case studies.
C++ and Object-Oriented Programming
Some educators reject C and C++ as too permissive and too conducive to writing cryptic, unreadable programs. Our experience does not support this view, provided that the use of language features is modeled appropriately. The fact that the C family permits a terse, compact programming style cannot be labeled simply as good or bad. Almost
Next page