1. 首页
  2. 编程语言
  3. C++ 
  4. C++PRIMERPLUS5THEDITIONPDF

C++PRIMERPLUS5THEDITIONPDF

上传者: 2019-05-13 16:56:12上传 PDF文件 500kb 热度 20次
C++ PRIMER PLUS 5TH EDITION PDFC++ primer plusASSOCIATE PUBLISHERMichael StephensCopyright o 2005 by Sams PublishingACQUISITIONS EDITORAll rights reserved. No part of this book shall be reproduced, stored in a retrieval systemLoretta Yatesor transmitted by any means, electronic, mechanical, photocopying, recording, or otherwiseDEVELOPMENT EDITORwithout written permission from the publisher. No patent liability is assumed with respectto the use of the information contained herein. Although every precaution has been takenSonglin Qiuin the preparation of this book, the publisher and author assume no responsibility for errorsMANAGING EDITORor omissions. Nor is any liability assumed for damages resulting from the use of the inforCharlotte Clapmation contained hereinPROJECT EDITORInternational Standard Book Number: 0-672-32697-3George E. NedeffLibrary of Congress Catalog Card Number: 2004095067COPY EDITORPrinted in the United States of AmericaKitty JarrettFirst Printing: November 2004INDEXER7060504321Erika millenPROOFREADERTrademarksSuzanne thomasTECHNICAL EDITORall terms mentioned in this book that are known to be trademarks or service marks haveDavid horvathbeen appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of anyPUBLISHINGtrademark or service markCOORDINATORCindy teetersWarning and disclaimerMULTIMEDIA DEVELOPERDan ScherfEvery effort has been made to make this book as complete and as accurate as possible, butBOOK DESIGNERno warranty or fitness is implied. The information provided is on an "as is"basiGary adairBulk salesSams Publishing offers excellent discounts on this book when ordered in quantity for bulkpurchases or special sales. For more information, please contactU.S. Corporate and government sales1-800-3823419corpsales@pearsontechgroup.comFor sales outside of the U.S., please contactInternational Sales1-317-428-3341international@pearsontechgroup.comCONTENTS AT A GLANCEINTRODUCTIONCHAPTER 1 Getting StartedCHAPTER 2 Setting Out to C++29CHAPTER 3 Dealing with Data65CHAPTER 4 Compound Types109CHAPTER 5 Loops and Relational Expressions177CHAPTER 6 Branching Statements and logical operators231CHAPTER 7 Functions: C++'s Programming Modules279CHAPTer 8 Adventures in Functions337CHAPTER 9 Memory Models and Namespaces393CHAPTER 10 Obiects and Classes445CHAPTER 11 Working with ClassesChaPTer 12 Classes and Dynamic Memory allocation561CHaPTER 13 Class Inheritance...633CHAPTER 14 Reusing Code in C++701CHAPTER 15 Friends, Exceptions, and more787CHAPTER 16 The string Class and the Standard Template Library857CHAPTER 17 Input, Output, and Files951APPENDIX A Number Bases1041APPENDIX B C++ Reserved words1047APPENDIX C The aSCii Character Set1051APPENDIX D Operator Precedence1057APPENDIX E Other Operators1063APPENDIX F The string Template Class1075APPENDIX G The STL Methods and functions.1095APPENDIX H Selected Readings and Internet Resources1129APPENDIX I Converting to ANSI/ISO Standard C++1133APPENDIX J Answers to Review Questions114INDEX1165TABLE OF CONTENTSINTRODUCTIONCHAPTER 1: Getting StartedLearning C++: What Lies Before YouThe Origins of C++: A Little history.12The C langi13C Programming Philosophy3The C++ Shift: Object-Oriented Programming14C++ and Generic Programming.15The genesis of C++16Portability and standards.17The Mechanics of Creating a Program.19Creating the source code file20d Linking.22Summary27CHAPTER 2: Setting out to c29C++initiation29The main( Funct31C++ comments34The C++ Preprocessor and the iostream Fi5Header filenames36Namespaces37C++ Output with cout38CCode fng41C++ Statements4Declaration Statements and Variables43Assignment Statements45A New trick for cout46More ct+ statements47Using cil47Concatenating with cout.18cin and cout: A Touch of class4850Using a Function That Has a Return valueFunction variations54User-Defined Functions55Using a User-Defined Function That Has a Return value58Placing the using Directive in Multifunction Programsvi C++ PRImer PLUS. FIFTH EDITIoNummarProgramming Exercises64CHAPTER 3: Dealing with DataSimple variables66Names for variables66nteger typesThe short, int, and long Integer Types68d tyChoosing an Integer TypeHow C++ Decides What Type a Constant Is78The char Type: Characters and Small IntegersThe bool Type87The const QualifierFloating-Point Numbers89Writing Floating-Point NumbersFloating-Point type91Floating-Point ConstantsAdvantages and Disadvantages of Floating-Point Numbers94C++ Arithmetic Operators95Order of Operation: Operator Precedence and Associativity96Division diversions97The Modulus OperatorType Conversions100Summary105Review Questions106Programming Exercises.107CHAPTER 4: Compound TypesIntroducing Arrays110ogram Notes.112Initialization Rules for Arrays113Strings.114Concatenating String Constants116Using strgin an arra116Adventures in String InputReading string irg1gut a line at a time119Mixing String and Numeric Input124CONTENTSIntroducing the strg125Assignment, Concatenation, and Appending126More string Class Operations127More on string Class I/O129Introducing Structures131Using a Structure in a Program133Can a Structure Use a string Class Member?135Otheture Properties136Arrays of Structures137Bit Fields in Structu139Unions139Enumerations141Setting enumerator values142Value ranges for Enumerations143Pointers and the free sto144Declaring and Initializing Pointers147Pointer danger149Pointers and numbers150Allocating memory with new150Freeing Memory with delete152Using new to Create dynamic arrays153Pointers, Arrays, and Pointer arithme156Program notes157Pointers and str162Using new to Create Dynamic structures166Automatic Storage, Static Storage, and Dynamic Storage170Summary172Review QuestionsProgramming Exercises174CHAPTER 5: Loops and Relational Expressions177Introducing for loops178Pp Pal179Back to the for loop185Changing187Inside Strings with the for Loop188The Increment (++)and Decrement(--)Ope189Side effects and sequence points190Prefixing versus postfixing191The Increment/Decrement Operators and pointers191Combination Assignment Operators192viii C++ PRImer PLUS. FIFTH EDITIONCompound statements, or Blocks193The Comma Operator (or More Syntax Tricks).195Relational expressions198A Mistake You'll Probably make.199Comparing C-Style Strings201tring Class String204The while Loop205P207for versus while207Just a Moment--Building a Time-Delay Loop209The do while Loop211Loops and Text Input213Using Unadorned cin for Input214cin. get(char) to the rescue215Which cin. get(?216The End-of-File Condition217Yet Another Version of cin. get(220Nested Loops and Two-Dimensional arraysInitializing a Two-Dimensional array225SummaryReview questions228Programming Exercises229CHAPTER 6: Branching Statements and Logical operators231The if Statement231The if else Statement233Formatting if else Statements235The if else if else construction236Logical Expressions238The logical or Operator238The Logical AND Operator: &d239The logical not Operator244246Alternative representations247The ectype Library of Character Functions247The O250The switch Statement251Using Enumerators as labels255switch and if else256The break and continue Statements256ProCONTENTSⅸNumber-Reading Loops259Program notes262Simple File Input/Output262Text I/O and Text File263Writing to a Text file264Reading from a Text File268ummary273Review questions274Programming Exercises276CHAPTER 7: Functions: C++'s Programming Modules279Function review280Defining a function281Prototyping and Calling a Function283Function Arguments and Passing by value286Multiple arguments288Another Two-Argument Function290Functions and arrays293How Pointers Enable Array-Processing Functions294The Implications of Using Arrays as Arguments295More Array Function Examples297Functions Using Array Ranges303Pointers and const305Functions and Two-Dimensional Arrays308Functions and C-Style Strings309Functions with C-Style String Arguments310Functions That Return C-Style Strings312Functions and Structures313Passing and Returning Structures314Another Example of Using functions with Structures316Passing Structure Addresses320Functions and string Class Objects322Recursion324Recursion with a single recursive call324Recursion with Multiple recursive calls326Pointers to functions327Function pointer basics328A Function Pointer Example330Summary332Review questions333Programming exercises334
用户评论