ebook img

Brief C++: Late Objects PDF

619 Pages·2017·19.89 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Brief C++: Late Objects

Brief C+Cay+ Horstmann Late Objects 3/e Brief C++ Late Objects 3/e Brief C++ Late Objects 3/e Cay Horstmann San Jose State University PUBLISHER Laurie Rosatone EDITORIAL DIRECTOR Don Fowley DEVELOPMENTAL EDITOR Cindy Johnson ASSISTANT DEVELOPMENT EDITOR Ryann Dannelly EXECUTIVE MARKETING MANAGER Dan Sayre SENIOR PRODUCTION EDITOR Laura Abrams SENIOR CONTENT MANAGER Valerie Zaborski EDITORIAL ASSISTANT Anna Pham SENIOR DESIGNER Tom Nery SENIOR PHOTO EDITOR Billy Ray PRODUCTION MANAGEMENT Cindy Johnson COVER IMAGE © Monty Rakusen/Getty Images This book was set in Stempel Garamond LT Std by Publishing Services, and printed and bound by Quad/ Graphics, Versailles. The cover was printed by Quad/Graphics, Versailles. This book is printed on acid-free paper. ∞ Founded in 1807, John Wiley & Sons, Inc. has been a valued source of knowledge and understanding for more than 200 years, helping people around the world meet their needs and fulfill their aspirations. Our company is built on a foundation of principles that include responsibility to the communities we serve and where we live and work. In 2008, we launched a Corporate Citizenship Initiative, a global effort to address the environmental, social, economic, and ethical challenges we face in our business. Among the issues we are addressing are carbon impact, paper specifications and procurement, ethical conduct within our business and among our vendors, and community and charitable support. For more information, please visit our website: www.wiley.com/go/ citizenship. Copyright © 2018, 2012, 2009 John Wiley & Sons, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc. 222 Rosewood Drive, Danvers, MA 01923, website www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, (201) 748-6011, fax (201) 748-6008, website http://www.wiley.com/go/permissions. Evaluation copies are provided to qualified academics and professionals for review purposes only, for use in their courses during the next academic year. These copies are licensed and may not be sold or transferred to a third party. Upon completion of the review period, please return the evaluation copy to Wiley. Return instruc- tions and a free of charge return shipping label are available at www.wiley.com/go/returnlabel. If you have chosen to adopt this textbook for use in your course, please accept this book as your complimentary desk copy. Outside of the United States, please contact your local representative. ISBN 13: 978-1-119-40042-4 The inside back cover will contain printing identification and country of origin if omitted from this page. In addition, if the ISBN on the back cover differs from the ISBN on this page, the one on the back cover is correct. Printed in the United States of America. 10 9 8 7 6 5 4 3 2 1 PREFACE This book is an introduction to C++ and computer programming that focuses on the essentials—and on effective learning. The book is designed to serve a wide range of student interests and abilities and is suitable for a first course in programming for computer scientists, engineers, and students in other disciplines. No prior program- ming experience is required, and only a modest amount of high school algebra is needed. Here are the key features of this book: Present fundamentals first. This book uses the C++ programming language as a vehicle for introducing com- puter sci ence concepts. A substantial subset of the C++ language is covered, focusing on the modern features of standard C++ that make students productive. The book takes a traditional route, first stressing control structures, procedural decomposition, and array algorithms. Objects are used when appropriate in the early chapters. Stu- dents start designing and implementing their own classes in Chapter 9. Guidance and worked examples help students succeed. Beginning programmers often ask “How do I start? Now what do I do?” Of course, an activity as complex as programming cannot be reduced to cookbook-style instruc- tions. However, step-by-step guidance is immensely helpful for building confidence and providing an outline for the task at hand. “Problem Solving” sections stress the importance of design and planning. “How To” guides help students with common programming tasks. Additional Worked Examples are available in the E-Text or online. Tip: Source files for all of the program examples in the book, including the Worked Examples, are provided with the source code for this book. Download the files to your computer for easy access as you work through the chapters. Practice makes perfect. Of course, programming students need to be able to implement nontrivial programs, but they first need to have the confidence that they can succeed. The Enhanced E-Text immerses students in activities designed to foster in-depth learning. Students don’t just watch animations and code traces, they work on generating them. The activities provide instant feedback to show students what they did right and where they need to study more. A wealth of practice opportunities, including code completion ques- tions and skill-oriented multiple-choice questions, appear at the end of each section, and each chapter ends with well-crafted review exercises and programming projects. Problem solving strategies are made explicit. Practical, step-by-step illustrations of techniques help students devise and evaluate solutions to programming problems. Introduced where they are most relevant, these strategies address barriers to success for many students. Strategies included are: • Algorithm Design (with pseudocode) • First Do It By Hand (doing sample calculations by hand) • Flowcharts v vi Preface • Selecting Test Cases • Hand-Tracing • Storyboards • Solve a Simpler Problem First • Reusable Functions • Stepwise Refinement • Adapting Algorithms • Discovering Algorithms by Manipulating Physical Objects • Draw a Picture (pointer diagrams) • Tracing Objects (identifying state and behavior) • Discovering Classes A visual approach motivates the reader and eases navigation. Photographs present visual analogies that explain the nature and behavior of computer concepts. Step-by-step figures illustrate complex program operations. Syntax boxes and example tables pres- ent a variety of typical and special cases in a com- pact format. It is easy to get the “lay of the land” by browsing the visuals, before focusing on the textual material. Focus on the essentials while being © Terraxplorer/iStockphoto. technically accurate. An encyclopedic coverage is not helpful for a Visual features help the reader beginning programmer, but neither is the oppo- with navigation. site—reducing the material to a list of simplistic bullet points. In this book, the essentials are presented in digestible chunks, with sep- arate notes that go deeper into good practices or language features when the reader is ready for the additional information. You will not find artificial over-simplifications that give an illusion of knowledge. Reinforce sound engineering practices. A multitude of useful tips on software quality and common errors encourage the development of good programming habits. The focus is on test-driven development, encouraging students to test their programs systematically. Engage with optional engineering and business exercises. End-of-chapter exercises are enhanced with problems from scientific and business domains. Designed to engage students, the exercises illustrate the value of program- ming in applied fields. Preface vii New to This Edition Updated for Modern Versions of C++ A number of features of the C++ 2011 and C++ 2014 standards are described either as recommended “best practice” or as Special Topics. New and Reorganized Topics The book now supports two pathways into object-oriented programming and inher- itance. Pointers and structures can be covered before introducing classes. Alterna- tively, pointers can be deferred until after the implementation of classes. A sequence of Worked Examples and exercises introduces “media computa- tion”—generating and modifying images, sounds, and animations. Lower-Cost, Interactive Format This third edition is published as a lower-cost Enhanced E-Text that supports active learning through a wealth of interactive activities. These activities engage and prepare students for independent programming and the Review Exercises, Practice Exercises, and Programming Projects at the end of each E-Text chapter. The Enhanced E-Text may also be bundled with an Abridged Print Companion, which is a bound book that contains the entire text for reference, but without exercises or practice material. Interactive learning solutions are expanding every day, so to learn more about these options or to explore other options to suit your needs, please contact your Wiley account manager (www.wiley.com/go/whosmyrep) or visit the product information page for this text on wiley.com (http://wiley.com/college/sc/horstmann). The Enhanced E-Text is designed to enable student practice without the instructor assigning the interactivities or recording their scores. If you are interested in assign- ing and grading students’ work on them, ask your Wiley Account Manager about the online course option implemented in the Engage Learning Management System. The Engage course supports the assignment and automatic grading of the interactivities. Engage access includes access to the Enhanced E-Text. Features in the Enhanced E-Text The interactive Enhanced E-Text guides students from the basics to writing complex pro grams. After they read a bit, they can try all of the interactive exercises for that section. Active reading is an engaging way for students to ensure that students are prepared before going to class. There five types of interactivities: Code Walkthrough Code Walkthrough activities ask students to trace through a segment of code, choosing which line will be executed next and entering the new values of variables changed by the code’s execution. This activity simulates the hand- tracing problem solving technique taught in Chapters 3 and 4—but with immediate feedback. viii Preface Example Table Example table activities make the student the active participant in building up tables of code examples similar to those found in the book. The tables come in many different forms. Some tables ask the student to determine the output of a line of code, or the value of an expression, or to provide code for certain tasks. This activity helps students assess their understanding of the reading—while it is easy to go back and review. Algorithm Animation An algorithm animation shows the essential steps of an algorithm. However, instead of passively watching, students get to predict each step. When finished, students can start over with a different set of inputs. This is a surpris- ingly effective way of learning and remembering algorithms. Rearrange Code Rearrange code activities ask the student to arrange lines of code by dragging them from the list on the right to the area at left so that the resulting code fulfills the task described in the problem. This activity builds facility with coding structure and implementing common algorithms. Object Diagram Object diagram activities ask the student to create a memory diagram to illustrate how variables and objects are initialized and updated as sample code executes. The activity depicts variables, objects, and references in the same way as the figures in the book. After an activity is completed, pressing “Play” replays the animation. This activity goes beyond hand-tracing to illuminate what is happening in memory as code executes. Code Completion Code completion activities ask the student to finish a partially- completed program, then paste the solution into CodeCheck (a Wiley-based online code evaluator) to learn whether it produces the desired result. Tester classes on the CodeCheck site run and report whether the code passed the tests. This activity serves as a skill-building lab to better prepare the student for writing programs from scratch. A Tour of the Book This book is intended for a two-semester introduction to programming that may also include algorithms and data structures. The organization of chapters offers the same flexibility as the previous edition; dependencies among the chapters are also shown in Figure 1. Part A: Fundamentals (Chapters 1–8) The first six chapters follow a traditional approach to basic programming concepts. Students learn about control structures, stepwise refinement, and arrays. Objects are used only for input/output and string processing. Input/output is first covered in Chapter 2, which may be followed by an introduction to reading and writing text files in Section 8.1. In a course for engineers with a need for systems and embedded programming, you will want to cover Chapter 7 on pointers. Sections 7.1 and 7.4 are sufficient for using pointers with polymorphism in Chapter 10. File processing is the subject of Chapter 8. Section 8.1 can be covered sooner for an intro duction to reading and writing text files. The remainder of the chapter gives addi tional material for practical applications. Preface ix Part B: Object-Oriented Design (Chapters 9–10) After students have gained a solid foundation, they are ready to tackle the implemen- tation of classes. Chapters 9 and 10 introduce the object-oriented features of C++. Chapter 9 introduces class design and implementation. Chapter 10 covers inheritance and polymorphism. By the end of these chapters, students will be able to implement programs with multiple interacting classes. Any subset of these chapters can be incorporated into a custom print version of this text; ask your Wiley sales representative for details, or visit customselect.wiley.com to create your custom order. Appendices Appendices A and B summarize C++ reserved words and operators. Appendix C lists character escape sequences and ASCII character code values. Appendix D docu- ments all of the library functions and classes used in this book. Appendix E contains a programming style guide. Using a style guide for program- ming assignments benefits students by directing them toward good habits and reduc- ing gratuitous choice. The style guide is available in electronic form on the book’s companion web site so that instructors can modify it to reflect their preferred style. Appendix F, available in the E-Text, introduces common number systems used in computing. Fundamentals 1.Introduction Object-Oriented Design 2.Fundamental Data Types 3.Decisions 4.Loops A gentle introduction to recursion 5.Functions is optional. Section 8.1 contains the core material 6.Arrays 6. Iteration and Vectors 7.Pointers 8.Streams 9.Classes Sections 10.Inheritance 7.1 and 7.4 are required Figure 1 Chapter Dependencies x Preface Web Resources This book is complemented by a complete suite of online resources. Go to www.wiley. com/go/bclo3 to visit the online companion sites, which include • Source code for all example programs in the book and its Worked Examples, plus additional example programs. • Worked Examples that apply the problem-solving steps in the book to other realistic examples. • Lecture presentation slides (for instructors only). • Solutions to all review and programming exercises (for instructors only). • A test bank that focuses on skills, not just terminology (for instructors only). This extensive set of multiple-choice questions can be used with a word processor or imported into a course management system. • “CodeCheck” assignments that allow students to work on programming prob- lems presented in an innovative online service and receive immediate feedback. Instructors can assign exercises that have already been prepared, or easily add their own. Visit http://codecheck.it to learn more. Pointers in the print companion describe what students will find in their WORKED EXAMPLE 2.1 E-Text or online. Computing Travel Time Learn how to develop a hand calculation to compute the time that a robot requires to retrieve an item from rocky terrain. See your E-Textor visit wiley.com/go/bclo.3 Courtesy of NASA. EXAMPLE CODE See how_to_1/scores_vector in your companion code for a solution using vectors instead of arrays.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.