Example: dental hygienist

Programming: Principles and Practice Using C++

programming Second Edition This page intentionally left blank 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.

Programming Principles and Practice Using C++ Second Edition Bjarne Stroustrup Upper Saddle River, NJ † Boston † Indianapolis † San Francisco

Tags:

  Programming, Using, Principles, Practices, Principles and practice using, Programming principles and practice using

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Programming: Principles and Practice Using C++

1 programming Second Edition This page intentionally left blank 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.

2 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 ex- pressed 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 or (800) 382-3419.

3 For government sales inquiries, please contact For questions about sales outside the United States, please contact Visit us on the Web: 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. 2014. '3 dc23. 2014004197. Copyright 2014 Pearson Education, Inc.

4 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 ma- terial 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.

5 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. Second printing, January 2015. Contents Preface xxv Chapter 0 Notes to the Reader 1. The structure of this book 2. General approach 3. Drills, exercises, etc. 4. What comes after this book? 5. A philosophy of teaching and learning 6. The order of topics 9. programming and programming language 10. Portability 11. programming and computer science 12. Creativity and problem solving 12.

6 Request for feedback 12. References 13. Biographies 13. Bjarne Stroustrup 14. Lawrence Pete Petersen 15. Chapter 1 Computers, People, and programming 17. Introduction 18. Software 19. People 21. Computer science 24. Computers are everywhere 25. Screens and no screens 26. Shipping 26. Telecommunications 28. Medicine 30. v vi CONTENTS. Information 31. A vertical view 33. So what? 34. Ideals for programmers 34. Part I The Basics 41. Chapter 2 Hello, World! 43. Programs 44. The classic first program 45.

7 Compilation 47. Linking 51. programming environments 52. Chapter 3 Objects, Types, and Values 59. Input 60. Variables 62. Input and type 64. Operations and operators 66. Assignment and initialization 69. An example: detect repeated words 71. Composite assignment operators 73. An example: find repeated words 73. Names 74. Types and objects 77. Type safety 78. Safe conversions 79. Unsafe conversions 80. Chapter 4 Computation 89. Computation 90. Objectives and tools 92. Expressions 94. Constant expressions 95.

8 Operators 97. Conversions 99. Statements 100. Selection 102. Iteration 109. Functions 113. Why bother with functions? 115. Function declarations 117. CONTENTS vii vector 117. Traversing a vector 119. Growing a vector 119. A numeric example 120. A text example 123. Language features 125. Chapter 5 Errors 133. Introduction 134. Sources of errors 136. Compile-time errors 136. Syntax errors 137. Type errors 138. Non-errors 139. Link-time errors 139. Run-time errors 140. The caller deals with errors 142.

9 The callee deals with errors 143. Error reporting 145. Exceptions 146. Bad arguments 147. Range errors 148. Bad input 150. Narrowing errors 153. Logic errors 154. Estimation 157. Debugging 158. Practical debug advice 159. Pre- and post-conditions 163. Post-conditions 165. Testing 166. Chapter 6 Writing a Program 173. A problem 174. Thinking about the problem 175. Stages of development 176. Strategy 176. Back to the calculator! 178. First attempt 179. Tokens 181. Implementing tokens 183. Using tokens 185.

10 Back to the drawing board 186. viii CONTENTS. Grammars 188. A detour: English grammar 193. Writing a grammar 194. Turning a grammar into code 195. Implementing grammar rules 196. Expressions 197. Terms 200. Primary expressions 202. Trying the first version 203. Trying the second version 208. Token streams 209. Implementing Token_stream 211. Reading tokens 212. Reading numbers 214. Program structure 215. Chapter 7 Completing a Program 221. Introduction 222. Input and output 222. Error handling 224.


Related search queries