logo资料库

C++程序设计原理与实践(2nd).pdf

第1页 / 共968页
第2页 / 共968页
第3页 / 共968页
第4页 / 共968页
第5页 / 共968页
第6页 / 共968页
第7页 / 共968页
第8页 / 共968页
资料共968页,剩余部分请下载后查看
Cover
Contents
Preface
Chapter 0 Notes to the Reader
Chapter 1 Computers, People, and Programming
Chapter 2 Hello, World!
Chapter 3 Objects, Types, and Values
Chapter 4 Computation
Chapter 5 Errors
Chapter 6 Writing a Program
Chapter 7 Completing a Program
Chapter 8 Technicalities: Functions, etc.
Chapter 9 Technicalities: Classes, etc.
Chapter 10 Input and Output Streams
Chapter 11 Customizing Input and Output
Chapter 12 A Display Model
Chapter 13 Graphics Classes
Chapter 14 Graphics Class Design
Chapter 15 Graphing Functions and Data
Chapter 16 Graphical User Interfaces
Chapter 17 Vector and Free Store
Chapter 18 Vectors and Arrays
Chapter 19 Vector, Templates, and Exceptions
Chapter 20 Containers and Iterators
Chapter 21 Algorithms and Maps
Chapter 22 Ideals and History
Chapter 23 Text Manipulation
Chapter 24 Numerics
Chapter 25 Embedded Systems Programming
Chapter 26 Testing
Chapter 27 The C Programming Language
Appendix A Language Summary
Appendix B Standard Library Summary
Appendix C Getting Started with Visual Visual Studio
Appendix D Installing FLTK
Appendix E GUI Implementation
Glossary
Bibligraphy
Index
Programming: Principles and Practice Using C++ Second Edition Bjarne Stroustrup Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. A complete list of photo sources and credits appears on pages 1273–1274. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned.com or (800) 382-3419. For government sales inquiries, please contact governmentsales@pearsoned.com. For questions about sales outside the United States, please contact international@pearsoned.com. Visit us on the Web: informit.com/aw Library of Congress Cataloging-in-Publication Data Stroustrup, Bjarne, author. Programming : principles and practice using C++ / Bjarne Stroustrup. — Second edition. pages cm Includes bibliographical references and index. ISBN 978-0-321-99278-9 (pbk. : alk. paper) 1. C++ (Computer program language) I. Title. QA76.73.C153S82 2014 005.13'3—dc23 2014004197 Copyright © 2014 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290. ISBN-13: 978-0-321-99278-9 ISBN-10: 0-321-99278-4 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana. First printing, May 2014
Contents Preface Chapter 0 Notes to the Reader 0.1 The structure of this book 0.1.1 General approach 0.1.2 Drills, exercises, etc. 0.1.3 What comes after this book? 0.2 A philosophy of teaching and learning 0.2.1 The order of topics 0.2.2 Programming and programming language 0.2.3 Portability 0.3 Programming and computer science 0.4 Creativity and problem solving 0.5 Request for feedback 0.6 References 0.7 Biographies Bjarne Stroustrup Lawrence “Pete” Petersen Chapter 1 Computers, People, and Programming 1.1 Introduction 1.2 Software 1.3 People 1.4 Computer science 1.5 Computers are everywhere 1.5.1 Screens and no screens 1.5.2 Shipping 1.5.3 Telecommunications 1.5.4 Medicine 1.5.5 Information 1.5.6 A vertical view 1.5.7 So what? 1.6 Ideals for programmers Part I The Basics Chapter 2 Hello, World! 2.1 Programs 2.2 The classic first program 2.3 Compilation 2.4 Linking 2.5 Programming environments
Chapter 3 Objects, Types, and Values 3.1 Input 3.2 Variables 3.3 Input and type 3.4 Operations and operators 3.5 Assignment and initialization 3.5.1 An example: detect repeated words 3.6 Composite assignment operators 3.6.1 An example: find repeated words 3.7 Names 3.8 Types and objects 3.9 Type safety 3.9.1 Safe conversions 3.9.2 Unsafe conversions Chapter 4 Computation 4.1 Computation 4.2 Objectives and tools 4.3 Expressions 4.3.1 Constant expressions 4.3.2 Operators 4.3.3 Conversions 4.4 Statements 4.4.1 Selection 4.4.2 Iteration 4.5 Functions 4.5.1 Why bother with functions? 4.5.2 Function declarations 4.6 vector 4.6.1 Traversing a vector 4.6.2 Growing a vector 4.6.3 A numeric example 4.6.4 A text example 4.7 Language features Chapter 5 Errors 5.1 Introduction 5.2 Sources of errors 5.3 Compile-time errors 5.3.1 Syntax errors 5.3.2 Type errors 5.3.3 Non-errors 5.4 Link-time errors
5.5 Run-time errors 5.5.1 The caller deals with errors 5.5.2 The callee deals with errors 5.5.3 Error reporting 5.6 Exceptions 5.6.1 Bad arguments 5.6.2 Range errors 5.6.3 Bad input 5.6.4 Narrowing errors 5.7 Logic errors 5.8 Estimation 5.9 Debugging 5.9.1 Practical debug advice 5.10 Pre- and post-conditions 5.10.1 Post-conditions 5.11 Testing Chapter 6 Writing a Program 6.1 A problem 6.2 Thinking about the problem 6.2.1 Stages of development 6.2.2 Strategy 6.3 Back to the calculator! 6.3.1 First attempt 6.3.2 Tokens 6.3.3 Implementing tokens 6.3.4 Using tokens 6.3.5 Back to the drawing board 6.4 Grammars 6.4.1 A detour: English grammar 6.4.2 Writing a grammar 6.5 Turning a grammar into code 6.5.1 Implementing grammar rules 6.5.2 Expressions 6.5.3 Terms 6.5.4 Primary expressions 6.6 Trying the first version 6.7 Trying the second version 6.8 Token streams 6.8.1 Implementing Token_stream 6.8.2 Reading tokens 6.8.3 Reading numbers 6.9 Program structure
Chapter 7 Completing a Program 7.1 Introduction 7.2 Input and output 7.3 Error handling 7.4 Negative numbers 7.5 Remainder: % 7.6 Cleaning up the code 7.6.1 Symbolic constants 7.6.2 Use of functions 7.6.3 Code layout 7.6.4 Commenting 7.7 Recovering from errors 7.8 Variables 7.8.1 Variables and definitions 7.8.2 Introducing names 7.8.3 Predefined names 7.8.4 Are we there yet? Chapter 8 Technicalities: Functions, etc. 8.1 Technicalities 8.2 Declarations and definitions 8.2.1 Kinds of declarations 8.2.2 Variable and constant declarations 8.2.3 Default initialization 8.3 Header files 8.4 Scope 8.5 Function call and return 8.5.1 Declaring arguments and return type 8.5.2 Returning a value 8.5.3 Pass-by-value 8.5.4 Pass-by-const-reference 8.5.5 Pass-by-reference 8.5.6 Pass-by-value vs. pass-by-reference 8.5.7 Argument checking and conversion 8.5.8 Function call implementation 8.5.9 constexpr functions 8.6 Order of evaluation 8.6.1 Expression evaluation 8.6.2 Global initialization 8.7 Namespaces 8.7.1 using declarations and using directives Chapter 9 Technicalities: Classes, etc.
9.1 User-defined types 9.2 Classes and members 9.3 Interface and implementation 9.4 Evolving a class 9.4.1 struct and functions 9.4.2 Member functions and constructors 9.4.3 Keep details private 9.4.4 Defining member functions 9.4.5 Referring to the current object 9.4.6 Reporting errors 9.5 Enumerations 9.5.1 “Plain” enumerations 9.6 Operator overloading 9.7 Class interfaces 9.7.1 Argument types 9.7.2 Copying 9.7.3 Default constructors 9.7.4 const member functions 9.7.5 Members and “helper functions” 9.8 The Date class Part II Input and Output Chapter 10 Input and Output Streams 10.1 Input and output 10.2 The I/O stream model 10.3 Files 10.4 Opening a file 10.5 Reading and writing a file 10.6 I/O error handling 10.7 Reading a single value 10.7.1 Breaking the problem into manageable parts 10.7.2 Separating dialog from function 10.8 User-defined output operators 10.9 User-defined input operators 10.10 A standard input loop 10.11 Reading a structured file 10.11.1 In-memory representation 10.11.2 Reading structured values 10.11.3 Changing representations Chapter 11 Customizing Input and Output 11.1 Regularity and irregularity
分享到:
收藏