• • Table of Contents Index C++ Primer Plus, Fourth Edition By Stephen Prata Publisher : Sams Publishing Pub Date : November 14, 2001 ISBN : 0-672-32223-4 Pages : 1128 C++ Primer Plus, Fourth Edition presents the ANSI C++ standard beginning with a discussion of the essential elements of C++ programming: loops, expressions, functions, and classes It walks readers through the basics of object-oriented programming: classes, inheritance, templates, and exceptions, as well as the latest objectoriented programming techniques C++ Primer Plus contains hundreds of sample programs The friendly tone, concise programs, and end-of-chapter review exercises allow beginners to write their own programs immediately • • Table of Contents Index C++ Primer Plus, Fourth Edition By Stephen Prata Publisher : Sams Publishing Pub Date : November 14, 2001 ISBN : 0-672-32223-4 Pages : 1128 Copyright PREFACE Preface to the Fourth Edition Note to Instructors How This Book Is Organized ABOUT THE AUTHOR ACKNOWLEDGMENTS TELL US WHAT YOU THINK! Chapter 1 GETTING STARTED Learning C++ Portability and Standards Conventions Used in This Book A Little History The Mechanics of Creating a Program Our System Chapter 2 SETTING OUT TO C++ C++ Initiation More About C++ Statements More C++ Statements Functions Summary Programming Exercises Review Questions Chapter 3 DEALING WITH DATA Simple Variables The const Qualifier Floating-Point Numbers Summary Programming Exercises C++ Arithmetic Operators Review Questions Chapter 4 COMPOUND TYPES Introducing Arrays Strings Introducing Structures Enumerations Pointers, Arrays, and Pointer Arithmetic Review Questions Unions Pointers and the Free Store Summary Programming Exercises Chapter 5 LOOPS AND RELATIONAL EXPRESSIONS Introducing the for Loop Relational Expressions The while Loop Loops and Text Input Summary Programming Exercises The do while Loop Nested Loops and Two-Dimensional Arrays Review Questions Chapter 6 BRANCHING STATEMENTS AND LOGICAL OPERATORS The if Statement Logical Expressions The cctype Library of Character Functions The switch Statement The ?: Operator The break and continue Statements Summary Programming Exercises Number-Reading Loops Review Questions Chapter 7 FUNCTIONSC++'S PROGRAMMING MODULES Function Review Function Arguments and Passing by Value Functions and Arrays Functions and C-Style Strings Recursion Summary Programming Exercises Functions and Two-Dimensional Arrays Functions and Structures Pointers to Functions Review Questions Chapter 8 ADVENTURES IN FUNCTIONS Inline Functions Reference Variables Default Arguments Function Templates Review Questions Function Polymorphism (Function Overloading) Summary Programming Exercises Chapter 9 MEMORY MODELS AND NAMESPACES Separate Compilation Storage Duration, Scope, and Linkage Namespaces Review Questions Summary Programming Exercises Chapter 10 OBJECTS AND CLASSES Procedural and Object-Oriented Programming Abstraction and Classes Class Constructors and Destructors An Array of Objects Knowing Your Objects: The this Pointer Class Scope Summary Programming Exercises An Abstract Data Type Review Questions Chapter 11 WORKING WITH CLASSES Operator Overloading Time on Our Hands Introducing Friends More Overloading: A Vector Class Summary Programming Exercises Overloaded Operators: Member Versus Nonmember Functions Automatic Conversions and Type Casts for Classes Review Questions Chapter 12 CLASSES AND DYNAMIC MEMORY ALLOCATION Dynamic Memory and Classes A Queue Simulation Summary Programming Exercises Review Questions Chapter 13 CLASS INHERITANCE Beginning with a Simple Base Class Special Relationships InheritanceAn Is-a Relationship Access Control-protected Inheritance and Dynamic Memory Allocation Summary Programming Exercises Polymorphic Public Inheritance Abstract Base Classes Class Design Review Review Questions Chapter 14 REUSING CODE IN C++ Classes with Object Members Private Inheritance Multiple Inheritance Summary Class Templates Review Questions Programming Exercises Chapter 15 FRIENDS, EXCEPTIONS, AND MORE Friends Nested Classes Exceptions Type Cast Operators Review Questions RTTI Summary Programming Exercises Chapter 16 THE string CLASS AND THE STANDARD TEMPLATE LIBRARY The string Class The auto_ptr Class The Standard Template Library Function Objects (aka Functors) Other Libraries Review Questions Generic Programming Algorithms Summary Programming Exercises Chapter 17 INPUT, OUTPUT, AND FILES An Overview of C++ Input and Output Output with cout Input with cin Incore Formatting Summary Programming Exercises File Input and Output What Now? Review Questions Appendix A NUMBER BASES Octal Integers Hexadecimal Numbers Binary Numbers Binary and Hex Appendix B C++ KEYWORDS Appendix C THE ASCII CHARACTER SET Appendix D OPERATOR PRECEDENCE Appendix E OTHER OPERATORS Bitwise Operators Member Dereferencing Operators Appendix F THE string TEMPLATE CLASS Thirteen Types and a Constant Data Information, Constructors, and So On String Access String Searching String Modifiers Basic Assignment Comparison Methods and Functions Output and Input Appendix G THE STL METHODS AND FUNCTIONS Members Common to All Containers Additional Members for Vectors, Lists, and Deques Additional Members for Sets and Maps STL Functions Appendix H SELECTED READINGS Appendix I CONVERTING TO ANSI/ISO STANDARD C++ Preprocessor Directives Use Function Prototypes Type Casts Use the New Header Organization Use the autoptr Template Use the STL Become Familiar with C++ Features Use Namespaces Use the string Class Appendix J ANSWERS TO REVIEW QUESTIONS Chapter 2 Chapter 3 Chapter 4 Chapter 6 Chapter 8 Chapter 10 Chapter 5 Chapter 7 Chapter 9 Chapter 11 Chapter 12 Chapter 14 Chapter 16 Chapter 13 Chapter 15 Chapter 17 Index Copyright Copyright ©2002 by Sams Publishing All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Library of Congress Catalog Card Number: 2001089224 Printed in the United States of America First Printing: November 2001 03 02 01 00 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been 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 any trademark or service mark Warning and Disclaimer reference variables 2nd 3rd 4th 5th 6th 7th Student class containment 2nd 3rd 4th 5th 6th 7th private inheritance 2nd 3rd 4th 5th 6th subroutines subscripts subtraction arithmetic operator 2nd 3rd precedence rules 2nd subtraction operator operator-() subtraction operators combined with assignment operators 2nd swap() function 2nd 3rd swap() method 2nd 3rd swap_ranges() function 2nd 3rd switch statement 2nd 3rd 4th 5th 6th 7th 8th 9th 10th symbolic constants files climits 2nd syntax prototypes 2nd [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] tables arrays of function addresses 2nd tabs reading cin.get(char) function tags template classes 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th arrays with non-type arguments 2nd 3rd auto_ptr 2nd 3rd 4th 5th 6th complex deque 2nd explicit instantiations 2nd explicit specializations 2nd implicit instantiations 2nd list 2nd member functions 2nd 3rd 4th TEMPLATE CLASSES LIST MEMBER FUNCTIONS template classes list member functions 2nd 3rd 4th members 2nd 3rd 4th partial specializations 2nd 3rd priority queue 2nd queue 2nd stack 2nd string 2nd access methods 2nd 3rd assignment methods 2nd 3rd 4th comparison methods 2nd constructors 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th copy methods 2nd defined types 2nd erase methods 2nd input/output insertion methods 2nd memory methods 2nd methods that append/add 2nd replacement methods 2nd search methods 2nd 3rd 4th swap methods valarray vector 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th versatility 2nd 3rd 4th recursively with family of classes 2nd template keyword templates autoptr converting to Standard C++ 2nd classes nested 2nd 3rd friend classes bound templates 2nd 3rd 4th non-template functions 2nd 3rd unbound templates 2nd function 2nd 3rd 4th explicit instantiation 2nd explicit specializations 2nd 3rd 4th 5th 6th 7th 8th 9th implicit instantiation 2nd 3rd overload resolution 2nd 3rd 4th 5th 6th 7th 8th overloading 2nd 3rd partial ordering rules 2nd 3rd 4th trivial conversions for exact matches 2nd 3rd istream iterator 2nd ostream iterator 2nd 3rd parameters 2nd 3rd Standard Template Library converting to Standard C++ temporary files random access 2nd temporary variables 2nd 3rd 4th terminate() function 2nd 3rd test-condition expression test-conditions zero or nonzero text files 2nd this pointer 2nd 3rd 4th 5th throw keyword 2nd 3rd 4th 5th time delays with while loop 2nd 3rd 4th 5th tokens 2nd tolower() function top-down design total ordering toupper() function trailing zeros/decimal points printing 2nd 3rd 4th 5th 6th 7th 8th transform() function 2nd 3rd 4th 5th 6th translation units compiling separately 2nd 3rd 4th translator (cfront) trivial conversions for exact matches 2nd 3rd troubleshooting compilers type conversions 2nd try blocks 2nd 3rd 4th 5th 6th 7th 8th 9th 10th nesting 2nd unwinding stacks 2nd 3rd try keyword two-dimensional arrays initializing 2nd 3rd type cast operators 2nd 3rd type casting 2nd 3rd 4th 5th 6th 7th automatically 2nd 3rd type casts 2nd 3rd converting to Standard C++ 2nd type conversions 2nd 3rd 4th 5th 6th 7th 8th 9th 10th type casts 2nd 3rd type info class TYPE INFO CLASS type info class TYPE INFO CLASS type info structure type parameters typeid operator 2nd 3rd TYPEID OPERATORS 2nd typeid operators 2nd typename keyword 2nd 3rd 4th types iterators 2nd static variables 2nd [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] UML (Unified Modeling Language) unary functions 2nd 3rd unary minus operator vector class 2nd unbound templates 2nd uncaught exceptions 2nd 3rd 4th underlying integer type unexpected exceptions 2nd 3rd 4th unexpected() function unformatted input functions Unicode character set 2nd Unicode Consortium Web site Unified Modeling Language (UML) unions anonymous 2nd unique() function 2nd 3rd unique() method 2nd 3rd 4th unique_copy() function 2nd universal character names 2nd UNIX commands CC 2nd compilers CC 2nd g++ 2nd MS-DOS 2nd unnamed memory new operator 2nd 3rd 4th unnamed namespaces 2nd unqualified names unqualified names of functions unsetf() function 2nd unsigned integers 2nd 3rd 4th 5th char 2nd criteria for type 2nd unwinding stacks 2nd 3rd upcasting 2nd 3rd 4th 5th 6th implicit update expressions 2nd upper bound() method upper_bound() function 2nd upper_bound() member functions upper_bound() method 2nd uppercase characters case-sensitive uppercase manipulator use() function 2nd 3rd 4th 5th use-case analysis user-defined functions 2nd 3rd form 2nd headings 2nd 3rd operator overloading 2nd with return values 2nd 3rd 4th 5th uses-a relationship, inheritance using declarations base classes 2nd using directives 2nd 3rd using keyword 2nd 3rd 4th using namespace keyword 2nd 3rd 4th using-declaration 2nd 3rd 4th 5th 6th 7th 8th 9th 10th using-directive 2nd 3rd 4th 5th 6th 7th [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] valarray class template values [See also return values] arguments, passing by assigning to pointers indirect passing objects 2nd variables automatic 2nd 3rd 4th 5th 6th 7th initializing register keyword 2nd stacks 2nd Boolean dynamic enum 2nd 3rd value ranges 2nd values 2nd keywords static 2nd local 2nd 3rd 4th 5th memory dynamic 2nd naming 2nd 3rd 4th pointers 2nd 3rd 4th 5th 6th declaring 2nd 3rd 4th 5th 6th initializing 2nd 3rd 4th 5th 6th reference 2nd creating 2nd 3rd 4th function parameters 2nd 3rd 4th properties 2nd 3rd references structures 2nd 3rd 4th 5th 6th 7th scope global 2nd 3rd local 2nd 3rd 4th 5th 6th 7th 8th 9th 10th namespace statements assignment 2nd declaration 2nd 3rd 4th static 2nd 3rd external 2nd 3rd 4th 5th 6th 7th 8th types 2nd temporary 2nd 3rd 4th type conversions 2nd 3rd 4th 5th vector class 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th declaring 2nd member functions 2nd 3rd 4th operators multiplication 2nd unary minus 2nd state members 2nd 3rd vector class templates 2nd vector containers 2nd versions compilers virtual base classes 2nd constructors 2nd 3rd dominance 2nd VIRTUAL BASE CLASSES METHODS virtual base classes methods 2nd 3rd 4th 5th VIRTUAL BASE CLASSES METHODS virtual base classes methods with nonvirtual 2nd virtual functions 2nd 3rd 4th constructors 2nd destructors 2nd friends 2nd pure 2nd 3rd redefinition 2nd virtual methods 2nd virutal destructors derived classes virutal method behavior derived classes 2nd 3rd 4th void functions void keyword 2nd volatile keyword 2nd [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] wchar t integers 2nd wchar_t data type Web sites Sams Publishing Unicode Consortium while loop 2nd 3rd compared to for loop 2nd 3rd 4th time delays 2nd 3rd 4th 5th white spaces 2nd wide character integers 2nd width() method 2nd 3rd Windows compilers 2nd 3rd 4th 5th write() member function 2nd 3rd write() method 2nd 3rd writing to files 2nd 3rd 4th [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] zeros trailing 2nd 3rd 4th 5th 6th 7th 8th 9th ... The Fourth Edition of C++ Primer Plus reflects the ISO/ANSI standard and describes this matured version of C++ C++ Primer Plus integrates discussing the basic C language with presenting C++ features, making this book self-contained... Index C++ Primer Plus, Fourth Edition By Stephen Prata Publisher : Sams Publishing Pub Date : November 14, 2001 ISBN : 0-672-32223-4 Pages : 1128 Copyright PREFACE Preface to the Fourth Edition. .. are some of the features that support using C++ Primer Plus, Fourth Edition as a textbook: This book describes generic C++, so it isn't dependent upon a particular implementation The contents track the ISO/ANSI C++ standards