1. Trang chủ
  2. » Khoa Học Tự Nhiên

C++ for everyone cay horstmann 2nd edition

696 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 696
Dung lượng 13,93 MB

Nội dung

C++ FOR EVERYONE This page intentionally left blank C++ FOR EVERYONE SECOND EDITION Cay Horstmann San Jose State University John Wiley & Sons, Inc VICE PRESIDENT AND EXECUTIVE PUBLISHER EXECUTIVE EDITOR EDITORIAL PROGRAM ASSISTANT PRODUCTION SERVICES MANAGER SENIOR PRODUCTION EDITOR EXECUTIVE MARKETING MANAGER MARKETING ASSISTANT CREATIVE DIRECTOR SENIOR PHOTO EDITOR SENIOR DESIGNER EXECUTIVE MEDIA EDITOR PRODUCTION SERVICES COVER PHOTO Don Fowley Beth Lang Golub Michael Berlin Dorothy Sinclair Janet Foxman Christopher Ruel Diana Smith Harry Nolan Lisa Gee Madelyn Lesure Tom Kulesa Cindy Johnson © Ricardo Azoury/iStockphoto This book was set in Stempel Garamond by Publishing Services, and printed and bound by RRD Jefferson City The cover was printed by RRD Jefferson City 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 ¹ 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) 7486011, fax (201) 748-6008, website 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 instructions and a free of charge return shipping label are available at www.wiley.com/go/returnlabel Outside of the United States, please contact your local representative Library of Congress Cataloging in Publication Data: Horstmann, Cay S., 1959C++ for everyone / Cay S Horstmann 2nd ed p cm Includes index ISBN 978-0-470-92713-7 (pbk.) C++ (Computer program language) I Title QA76.73.C153H6685 2010 005.13'3 dc22 2010039907 ISBN 978-0-470-92713-7 (Main Book) ISBN 978-0-470-92092-3 (Binder-Ready Version) Printed in the United States of America 10 P R E FA C E 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 programming experience is required, and only a modest amount of high school algebra is needed Here are the key features of this book: Guidance and worked examples help students succeed Beginning programmers often ask “How I start? Now what I do?” Of course, an activity as complex as programming cannot be reduced to cookbook-style instructions 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 online 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 This book contains a substantial number of self-check questions at the end of each section “Practice It” pointers suggest exercises to try after each section At the end of each chapter, you will find a great variety of programming assignments, ranging from simple practice problems to realistic applications Teach computer science principles, not just C++ or object-orientation This book uses the C++ programming language as a vehicle for introducing computer science 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, stressing control structures, procedural decomposition, and array algorithms, before turning to the design of classes in the final chapters A visual approach motivates the reader and eases navigation Photographs present visual analogies that explain the nature and behavior of computer concepts Step-bystep figures illustrate complex program operations Syntax boxes and example tables present a variety of typical and special cases in a compact 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 technically accurate Visual features help the reader An encyclopedic coverage is not helpful for a begin- with navigation ning programmer, but neither is the opposite— reducing the material to a list of simplistic bullet points In this book, the essentials are presented in digestible chunks, with separate 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 v vi Preface New to This Edition Problem Solving Strategies This edition adds practical, step-by-step illustrations of techniques that can 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 • Test Cases • Hand-Tracing • Storyboards • Reusable Functions • Stepwise Refinement • Adapting Algorithms • Discover Algorithms by Manipulating Physical Objects • Draw a Picture (pointer diagrams) • Tracing Objects (identifying state and behavior) • Discovering Classes Optional Engineering Exercises End-of-chapter exercises have been enhanced with problems from scientific and engineering domains Geared to students learning C++ for a technical major, the exercises are designed to illustrate the value of programming in those fields Additional exercises are available on the book’s companion web site New and Reorganized Topics All chapters were revised and enhanced to respond to user feedback and improve the flow of topics Loop algorithms are now introduced explicitly in Chapter Debugging is now introduced in a lengthy Worked Example in Chapter Arrays are covered before vectors are introduced in Chapter 6, and a new section on vector algorithms builds on the array algorithms presented earlier in the chapter A new optional section on structure types is now in Chapter New example tables, photos, and exercises appear throughout the book A Tour of the Book The core material of the book is: Chapter Introduction Chapter Fundamental Data Types Chapter Decisions Chapter Loops Chapter Functions Chapter Arrays and Vectors In a course for engineers with a need for systems and embedded programming, you will want to cover Chapter on pointers Sections 7.1 and 7.4 are sufficient for using pointers with polymorphism in Chapter 10 Preface vii File processing is the subject of Chapter Section 8.1 can be covered sooner for an introduction to reading and writing text files The remainder of the chapter gives additional material for practical applications Chapters and 10 introduce the object-oriented features of C++ Chapter introduces class design and implementation Chapter 10 covers inheritance and polymorphism Four additional chapters are available on the Web They can be used individually for a capstone chapter, or they can be combined for teaching a two-semester course (They can also be incorporated into a custom print version of the text; ask your Wiley sales representative for details.) Chapter 11 Recursion Chapter 12 Sorting and Searching Chapter 13 Lists, Stacks, and Queues Chapter 14 Sets, Maps, and Priority Queues Figure shows the dependencies between the chapters Fundamentals Introduction Online Fundamental Data Types Decisions Loops A gentle introduction to recursion is optional Functions Section 8.1 contains the core material Arrays and Vectors Figure Chapter Dependencies Pointers Streams Classes Sections 7.1 and 7.4 are required 13 Lists, Stacks, and Queues 10 Inheritance 14 Sets, Maps, Priority Queues 11 Recursion 12 Sorting and Searching viii Walkthrough A Walkthrough of the Learning Aids The pedagogical elements in this book work together to focus on and reinforce key concepts and fundamental principles of programming, with additional tips and detail organized to support and deepen these fundamentals In addition to traditional features, such as chapter objectives and a wealth of exercises, each chapter contains elements geared to today’s visual learner 4.3 The for Loop Throughout each chapter, margin notes show where new concepts are introduced and provide an outline of key ideas 143 4.4 The for Loop The for loop is used when a value runs from a starting point to an ending point with a constant increment or decrement It often happens that you want to execute a sequence of statements a given number of times You can use a while loop that is controlled by a counter, as in the following example: counter = 1; // Initialize the counter while (counter

Ngày đăng: 16/10/2021, 15:34

TỪ KHÓA LIÊN QUAN

w