gogogo
Syndetics cover image
Image from Syndetics

C++ primer plus 5th edition / Stephen Prata.

By: Material type: TextTextPublication details: Indianapolis, Ind. : Sams, c2005.Edition: 5th edDescription: xvii, 1202 p. : ill. ; 24 cmISBN:
  • 0672326973 (pbk.)
  • 9780672326974 (pbk.)
Subject(s):
Holdings
Item type Current library Call number Copy number Status Date due Barcode
Standard Loan Thurles Library Main Collection 005.133 PRA (Browse shelf(Opens below)) 1 Available R18108WKRC
Standard Loan Thurles Library Main Collection 005.133 PRA (Browse shelf(Opens below)) 1 Available R18109XKRC

Enhanced descriptions from Syndetics:

Covers the language enhancements, the Standard Template Library and ways to streamline object-oriented programming with C++. This guide also illustrates how to handle input and output, make programs perform repetitive tasks, manipulate data, hide information, use functions and build flexible, easily modifiable programs.

Includes index.

Table of contents provided by Syndetics

  • Introduction (p. 1)
  • Chapter 1 Getting Started (p. 11)
  • Learning C++: What Lies Before You (p. 11)
  • The Origins of C++: A Little History (p. 12)
  • The C Language (p. 13)
  • C Programming Philosophy (p. 13)
  • The C++ Shift: Object-Oriented Programming (p. 14)
  • C++ and Generic Programming (p. 15)
  • The Genesis of C++ (p. 16)
  • Portability and Standards (p. 17)
  • The Mechanics of Creating a Program (p. 19)
  • Creating the Source Code File (p. 20)
  • Compilation and Linking (p. 22)
  • Summary (p. 27)
  • Chapter 2 Setting Out to C++ (p. 29)
  • C++ Initiation (p. 29)
  • The main() Function (p. 31)
  • C++ Comments (p. 34)
  • The C++ Preprocessor and the iostream File (p. 35)
  • Header Filenames (p. 36)
  • Namespaces (p. 37)
  • C++ Output with cout (p. 38)
  • C++ Source Code Formatting (p. 41)
  • C++ Statements (p. 43)
  • Declaration Statements and Variables (p. 43)
  • Assignment Statements (p. 45)
  • A New Trick for cout (p. 46)
  • More C++ Statements (p. 47)
  • Using cin (p. 47)
  • Concatenating with cout (p. 48)
  • cin and cout: A Touch of Class (p. 48)
  • Functions (p. 50)
  • Using a Function That Has a Return Value (p. 50)
  • Function Variations (p. 54)
  • User-Defined Functions (p. 55)
  • Using a User-Defined Function That Has a Return Value (p. 58)
  • Placing the using Directive in Multifunction Programs (p. 60)
  • Summary (p. 62)
  • Review Questions (p. 63)
  • Programming Exercises (p. 64)
  • Chapter 3 Dealing with Data (p. 65)
  • Simple Variables (p. 66)
  • Names for Variables (p. 66)
  • Integer Types (p. 68)
  • The short, int, and long Integer Types (p. 68)
  • Unsigned Types (p. 73)
  • Choosing an Integer Type (p. 75)
  • Integer Constants (p. 76)
  • How C++ Decides What Type a Constant Is (p. 78)
  • The char Type: Characters and Small Integers (p. 79)
  • The bool Type (p. 87)
  • The const Qualifier (p. 88)
  • Floating-Point Numbers (p. 89)
  • Writing Floating-Point Numbers (p. 89)
  • Floating-Point Types (p. 91)
  • Floating-Point Constants (p. 93)
  • Advantages and Disadvantages of Floating-Point Numbers (p. 94)
  • C++ Arithmetic Operators (p. 95)
  • Order of Operation: Operator Precedence and Associativity (p. 96)
  • Division Diversions (p. 97)
  • The Modulus Operator (p. 99)
  • Type Conversions (p. 100)
  • Summary (p. 105)
  • Review Questions (p. 106)
  • Programming Exercises (p. 107)
  • Chapter 4 Compound Types (p. 109)
  • Introducing Arrays (p. 110)
  • Program Notes (p. 112)
  • Initialization Rules for Arrays (p. 113)
  • Strings (p. 114)
  • Concatenating String Constants (p. 116)
  • Using Strings in an Array (p. 116)
  • Adventures in String Input (p. 118)
  • Reading String Input a Line at a Time (p. 119)
  • Mixing String and Numeric Input (p. 124)
  • Introducing the string Class (p. 125)
  • Assignment, Concatenation, and Appending (p. 126)
  • More string Class Operations (p. 127)
  • More on string Class I/O (p. 129)
  • Introducing Structures (p. 131)
  • Using a Structure in a Program (p. 133)
  • Can a Structure Use a string Class Member? (p. 135)
  • Other Structure Properties (p. 136)
  • Arrays of Structures (p. 137)
  • Bit Fields in Structures (p. 139)
  • Unions (p. 139)
  • Enumerations (p. 141)
  • Setting Enumerator Values (p. 142)
  • Value Ranges for Enumerations (p. 143)
  • Pointers and the Free Store (p. 144)
  • Declaring and Initializing Pointers (p. 147)
  • Pointer Danger (p. 149)
  • Pointers and Numbers (p. 150)
  • Allocating Memory with new (p. 150)
  • Freeing Memory with delete (p. 152)
  • Using new to Create Dynamic Arrays (p. 153)
  • Pointers, Arrays, and Pointer Arithmetic (p. 156)
  • Program Notes (p. 157)
  • Pointers and Strings (p. 162)
  • Using new to Create Dynamic Structures (p. 166)
  • Automatic Storage, Static Storage, and Dynamic Storage (p. 170)
  • Summary (p. 172)
  • Review Questions (p. 173)
  • Programming Exercises (p. 174)
  • Chapter 5 Loops and Relational Expressions (p. 177)
  • Introducing for Loops (p. 178)
  • for Loop Parts (p. 179)
  • Back to the for Loop (p. 185)
  • Changing the Step Size (p. 187)
  • Inside Strings with the for Loop (p. 188)
  • The Increment (++) and Decrement (--) Operators (p. 189)
  • Side Effects and Sequence Points (p. 190)
  • Prefixing Versus Postfixing (p. 191)
  • The Increment/Decrement Operators and Pointers (p. 191)
  • Combination Assignment Operators (p. 192)
  • Compound Statements, or Blocks (p. 193)
  • The Comma Operator (or More Syntax Tricks) (p. 195)
  • Relational Expressions (p. 198)
  • A Mistake You'll Probably Make (p. 199)
  • Comparing C-Style Strings (p. 201)
  • Comparing string Class Strings (p. 204)
  • The while Loop (p. 205)
  • Program Notes (p. 207)
  • for Versus while (p. 207)
  • Just a Moment-Building a Time-Delay Loop (p. 209)
  • The do while Loop (p. 211)
  • Loops and Text Input (p. 213)
  • Using Unadorned cin for Input (p. 214)
  • cin.get(char) to the Rescue (p. 215)
  • Which cin.get()? (p. 216)
  • The End-of-File Condition (p. 217)
  • Yet Another Version of cin.get() (p. 220)
  • Nested Loops and Two-Dimensional Arrays (p. 223)
  • Initializing a Two-Dimensional Array (p. 225)
  • Summary (p. 227)
  • Review Questions (p. 228)
  • Programming Exercises (p. 229)
  • Chapter 6 Branching Statements and Logical Operators (p. 231)
  • The if Statement (p. 231)
  • The if else Statement (p. 233)
  • Formatting if else Statements (p. 235)
  • The if else if else Construction (p. 236)
  • Logical Expressions (p. 238)
  • The Logical OR Operator: [double vertical bar] (p. 238)
  • The Logical AND Operator: && (p. 239)
  • The Logical NOT Operator: ! (p. 244)
  • Logical Operator Facts (p. 246)
  • Alternative Representations (p. 247)
  • The cctype Library of Character Functions (p. 247)
  • The ?: Operator (p. 250)
  • The switch Statement (p. 251)
  • Using Enumerators as Labels (p. 255)
  • switch and if else (p. 256)
  • The break and continue Statements (p. 256)
  • Program Notes (p. 258)
  • Number-Reading Loops (p. 259)
  • Program Notes (p. 262)
  • Simple File Input/Output (p. 262)
  • Text I/O and Text Files (p. 263)
  • Writing to a Text File (p. 264)
  • Reading from a Text File (p. 268)
  • Summary (p. 273)
  • Review Questions (p. 274)
  • Programming Exercises (p. 276)
  • Chapter 7 Functions: C++'s Programming Modules (p. 279)
  • Function Review (p. 280)
  • Defining a Function (p. 281)
  • Prototyping and Calling a Function (p. 283)
  • Function Arguments and Passing by Value (p. 286)
  • Multiple Arguments (p. 288)
  • Another Two-Argument Function (p. 290)
  • Functions and Arrays (p. 293)
  • How Pointers Enable Array-Processing Functions (p. 294)
  • The Implications of Using Arrays as Arguments (p. 295)
  • More Array Function Examples (p. 297)
  • Functions Using Array Ranges (p. 303)
  • Pointers and const (p. 305)
  • Functions and Two-Dimensional Arrays (p. 308)
  • Functions and C-Style Strings (p. 309)
  • Functions with C-Style String Arguments (p. 310)
  • Functions That Return C-Style Strings (p. 312)
  • Functions and Structures (p. 313)
  • Passing and Returning Structures (p. 314)
  • Another Example of Using Functions with Structures (p. 316)
  • Passing Structure Addresses (p. 320)
  • Functions and string Class Objects (p. 322)
  • Recursion (p. 324)
  • Recursion with a Single Recursive Call (p. 324)
  • Recursion with Multiple Recursive Calls (p. 326)
  • Pointers to Functions (p. 327)
  • Function Pointer Basics (p. 328)
  • A Function Pointer Example (p. 330)
  • Summary (p. 332)
  • Review Questions (p. 333)
  • Programming Exercises (p. 334)
  • Chapter 8 Adventures in Functions (p. 337)
  • C++ Inline Functions (p. 337)
  • Reference Variables (p. 340)
  • Creating a Reference Variable (p. 341)
  • References as Function Parameters (p. 344)
  • Reference Properties and Oddities (p. 347)
  • Using References with a Structure (p. 351)
  • Using References with a Class Object (p. 355)
  • Another Object Lesson: Objects, Inheritance, and References (p. 358)
  • When to Use Reference Arguments (p. 361)
  • Default Arguments (p. 362)
  • Program Notes (p. 364)
  • Function Overloading (p. 365)
  • An Overloading Example (p. 367)
  • When to Use Function Overloading (p. 370)
  • Function Templates (p. 370)
  • Overloaded Templates (p. 374)
  • Explicit Specializations (p. 376)
  • Instantiations and Specializations (p. 380)
  • Which Function Version Does the Compiler Pick? (p. 382)
  • Summary (p. 388)
  • Review Questions (p. 389)
  • Programming Exercises (p. 390)
  • Chapter 9 Memory Models and Namespaces (p. 393)
  • Separate Compilation (p. 393)
  • Storage Duration, Scope, and Linkage (p. 399)
  • Scope and Linkage (p. 399)
  • Automatic Storage Duration (p. 400)
  • Static Duration Variables (p. 406)
  • Specifiers and Qualifiers (p. 415)
  • Functions and Linkage (p. 418)
  • Language Linking (p. 419)
  • Storage Schemes and Dynamic Allocation (p. 419)
  • The Placement new Operator (p. 420)
  • Program Notes (p. 423)
  • Namespaces (p. 424)
  • Traditional C++ Namespaces (p. 424)
  • New Namespace Features (p. 426)
  • A Namespace Example (p. 433)
  • Namespaces and the Future (p. 437)
  • Summary (p. 437)
  • Review Questions (p. 438)
  • Programming Exercises (p. 441)
  • Chapter 10 Objects and Classes (p. 445)
  • Procedural and Object-Oriented Programming (p. 446)
  • Abstraction and Classes (p. 447)
  • What Is a Type? (p. 447)
  • Classes in C++ (p. 448)
  • Implementing Class Member Functions (p. 453)
  • Using Classes (p. 458)
  • Reviewing Our Story to Date (p. 462)
  • Class Constructors and Destructors (p. 463)
  • Declaring and Defining Constructors (p. 464)
  • Using Constructors (p. 465)
  • Default Constructors (p. 466)
  • Destructors (p. 467)
  • Improving the Stock Class (p. 468)
  • Constructors and Destructors in Review (p. 475)
  • Knowing Your Objects: The this Pointer (p. 477)
  • An Array of Objects (p. 483)
  • The Interface and Implementation Revisited (p. 486)
  • Class Scope (p. 487)
  • Class Scope Constants (p. 488)
  • Abstract Data Types (p. 489)
  • Summary (p. 495)
  • Review Questions (p. 496)
  • Programming Exercises (p. 496)
  • Chapter 11 Working with Classes (p. 501)
  • Operator Overloading (p. 502)
  • Time on Our Hands: Developing an Operator Overloading Example (p. 503)
  • Adding an Addition Operator (p. 506)
  • Overloading Restrictions (p. 510)
  • More Overloaded Operators (p. 512)
  • Introducing Friends (p. 515)
  • Creating Friends (p. 516)
  • A Common Kind of Friend: Overloading the (p. 518)
  • Overloaded Operators: Member Versus Nonmember Functions (p. 524)
  • More Overloading: A Vector Class (p. 525)
  • Using a State Member (p. 533)
  • Overloading Arithmetic Operators for the Vector Class (p. 535)
  • An Implementation Comment (p. 537)
  • Taking the Vector Class on a Random Walk (p. 538)
  • Automatic Conversions and Type Casts for Classes (p. 541)
  • Program Notes (p. 547)
  • Conversion Functions (p. 547)
  • Conversions and Friends (p. 553)
  • Summary (p. 556)
  • Review Questions (p. 558)
  • Programming Exercises (p. 558)
  • Chapter 12 Classes and Dynamic Memory Allocation (p. 561)
  • Dynamic Memory and Classes (p. 562)
  • A Review Example and Static Class Members (p. 562)
  • Implicit Member Functions (p. 571)
  • The New, Improved String Class (p. 579)
  • Things to Remember When Using new in Constructors (p. 590)
  • Observations About Returning Objects (p. 593)
  • Using Pointers to Objects (p. 596)
  • Reviewing Techniques (p. 606)
  • A Queue Simulation (p. 607)
  • A Queue Class (p. 608)
  • The Customer Class (p. 618)
  • The Simulation (p. 621)
  • Summary (p. 626)
  • Review Questions (p. 627)
  • Programming Exercises (p. 629)
  • Chapter 13 Class Inheritance (p. 633)
  • Beginning with a Simple Base Class (p. 634)
  • Deriving a Class (p. 636)
  • Constructors: Access Considerations (p. 638)
  • Using a Derived Class (p. 641)
  • Special Relationships Between Derived and Base Classes (p. 643)
  • Inheritance: An Is-a Relationship (p. 645)
  • Polymorphic Public Inheritance (p. 647)
  • Developing the Brass and BrassPlus Classes (p. 648)
  • Static and Dynamic Binding (p. 660)
  • Pointer and Reference Type Compatibility (p. 660)
  • Virtual Member Functions and Dynamic Binding (p. 662)
  • Things to Know About Virtual Methods (p. 664)
  • Access Control: protected (p. 668)
  • Abstract Base Classes (p. 670)
  • Applying the ABC Concept (p. 672)
  • ABC Philosophy (p. 677)
  • Inheritance and Dynamic Memory Allocation (p. 677)
  • Case 1 Derived Class Doesn't Use new (p. 677)
  • Case 2 Derived Class Does Use new (p. 679)
  • An Inheritance Example with Dynamic Memory Allocation and Friends (p. 681)
  • Class Design Review (p. 685)
  • Member Functions That the Compiler Generates for You (p. 686)
  • Other Class Method Considerations (p. 687)
  • Public Inheritance Considerations (p. 691)
  • Class Function Summary (p. 695)
  • Summary (p. 696)
  • Review Questions (p. 697)
  • Programming Exercises (p. 698)
  • Chapter 14 Reusing Code in C++ (p. 701)
  • Classes with Object Members (p. 701)
  • The valarray Class: A Quick Look (p. 702)
  • The Student Class Design (p. 703)
  • The Student Class Example (p. 705)
  • Private Inheritance (p. 712)
  • The Student Class Example (New Version) (p. 713)
  • Multiple Inheritance (p. 723)
  • How Many Workers? (p. 728)
  • Which Method? (p. 732)
  • MI Synopsis (p. 743)
  • Class Templates (p. 744)
  • Defining a Class Template (p. 744)
  • Using a Template Class (p. 748)
  • A Closer Look at the Template Class (p. 750)
  • An Array Template Example and Non-Type Arguments (p. 756)
  • Template Versatility (p. 758)
  • Template Specializations (p. 762)
  • Member Templates (p. 765)
  • Templates as Parameters (p. 768)
  • Template Classes and Friends (p. 770)
  • Summary (p. 777)
  • Review Questions (p. 779)
  • Programming Exercises (p. 781)
  • Chapter 15 Friends, Exceptions, and More (p. 787)
  • Friends (p. 787)
  • Friend Classes (p. 788)
  • Friend Member Functions (p. 793)
  • Other Friendly Relationships (p. 796)
  • Nested Classes (p. 798)
  • Nested Classes and Access (p. 800)
  • Nesting in a Template (p. 801)
  • Exceptions (p. 805)
  • Calling abort() (p. 805)
  • Returning an Error Code (p. 807)
  • The Exception Mechanism (p. 808)
  • Using Objects as Exceptions (p. 812)
  • Unwinding the Stack (p. 816)
  • More Exception Features (p. 822)
  • The exception Class (p. 824)
  • Exceptions, Classes, and Inheritance (p. 829)
  • When Exceptions Go Astray (p. 834)
  • Exception Cautions (p. 837)
  • RTTI (p. 839)
  • What Is RTTI For? (p. 840)
  • How Does RTTI Work? (p. 840)
  • Type Cast Operators (p. 848)
  • Summary (p. 852)
  • Review Questions (p. 853)
  • Programming Exercises (p. 854)
  • Chapter 16 The string Class and the Standard Template Library (p. 857)
  • The string Class (p. 857)
  • Constructing a String (p. 858)
  • string Class Input (p. 862)
  • Working with Strings (p. 864)
  • What Else Does the string Class Offer? (p. 870)
  • The auto_ptr Class (p. 873)
  • Using auto_ptr (p. 874)
  • auto_ptr Considerations (p. 876)
  • The STL (p. 877)
  • The vector Template Class (p. 878)
  • Things to Do to Vectors (p. 880)
  • More Things to Do to Vectors (p. 885)
  • Generic Programming (p. 890)
  • Why Iterators? (p. 890)
  • Kinds of Iterators (p. 894)
  • Iterator Hierarchy (p. 897)
  • Concepts, Refinements, and Models (p. 898)
  • Kinds of Containers (p. 905)
  • Associative Containers (p. 915)
  • Function Objects (aka Functors) (p. 922)
  • Functor Concepts (p. 923)
  • Predefined Functors (p. 926)
  • Adaptable Functors and Function Adapters (p. 928)
  • Algorithms (p. 930)
  • Algorithm Groups (p. 931)
  • General Properties of Algorithms (p. 932)
  • The STL and the string Class (p. 933)
  • Functions Versus Container Methods (p. 934)
  • Using the STL (p. 936)
  • Other Libraries (p. 940)
  • vector and valarray (p. 940)
  • Summary (p. 946)
  • Review Questions (p. 948)
  • Programming Exercises (p. 949)
  • Chapter 17 Input, Output, and Files (p. 951)
  • An Overview of C++ Input and Output (p. 952)
  • Streams and Buffers (p. 952)
  • Streams, Buffers, and the iostream File (p. 955)
  • Redirection (p. 957)
  • Output with cout (p. 958)
  • The Overloaded (p. 958)
  • The Other ostream Methods (p. 961)
  • Flushing the Output Buffer (p. 964)
  • Formatting with cout (p. 965)
  • Input with cin (p. 983)
  • How cin > > Views Input (p. 985)
  • Stream States (p. 987)
  • Other istream Class Methods (p. 991)
  • Other istream Methods (p. 999)
  • File Input and Output (p. 1003)
  • Simple File I/O (p. 1004)
  • Stream Checking and is_open() (p. 1007)
  • Opening Multiple Files (p. 1008)
  • Command-Line Processing (p. 1008)
  • File Modes (p. 1011)
  • Random Access (p. 1021)
  • Incore Formatting (p. 1030)
  • What Now? (p. 1032)
  • Summary (p. 1033)
  • Review Questions (p. 1034)
  • Programming Exercises (p. 1036)
  • Appendix A Number Bases (p. 1041)
  • Decimal Numbers (Base 10) (p. 1041)
  • Octal Integers (Base 8) (p. 1041)
  • Hexadecimal Numbers (Base 16) (p. 1042)
  • Binary Numbers (Base 2) (p. 1043)
  • Binary and Hex (p. 1043)
  • Appendix B C++ Reserved Words (p. 1047)
  • C++ Keywords (p. 1047)
  • Alternative Tokens (p. 1048)
  • C++ Library Reserved Names (p. 1048)
  • Appendix C The ASCII Character Set (p. 1051)
  • Appendix D Operator Precedence (p. 1057)
  • Appendix E Other Operators (p. 1063)
  • Bitwise Operators (p. 1063)
  • The Shift Operators (p. 1063)
  • The Logical Bitwise Operators (p. 1065)
  • Alternative Representations of Bitwise Operators (p. 1067)
  • A Few Common Bitwise Operator Techniques (p. 1068)
  • Member Dereferencing Operators (p. 1070)
  • Appendix F The string Template Class (p. 1075)
  • Thirteen Types and a Constant (p. 1076)
  • Data Information, Constructors, and Odds and Ends (p. 1077)
  • Default Constructors (p. 1079)
  • Constructors That Use Part of an Array (p. 1080)
  • Copy Constructors (p. 1080)
  • Constructors That Use n Copies of a Character (p. 1081)
  • Constructors That Use a Range (p. 1082)
  • Memory Miscellany (p. 1082)
  • String Access (p. 1083)
  • Basic Assignment (p. 1084)
  • String Searching (p. 1084)
  • The find() Family (p. 1084)
  • The rfind() Family (p. 1085)
  • The find_first_of() Family (p. 1086)
  • The find_last_of() Family (p. 1086)
  • The find_first_not_of() Family (p. 1087)
  • The find_last_not_of() Family (p. 1087)
  • Comparison Methods and Functions (p. 1088)
  • String Modifiers (p. 1089)
  • Methods for Appending and Adding (p. 1089)
  • More Assignment Methods (p. 1090)
  • Insertion Methods (p. 1091)
  • Erase Methods (p. 1091)
  • Replacement Methods (p. 1092)
  • Other Modifying Methods: copy() and swap() (p. 1093)
  • Output and Input (p. 1093)
  • Appendix G The STL Methods and Functions (p. 1095)
  • Members Common to All Containers (p. 1095)
  • Additional Members for Vectors, Lists, and Deques (p. 1098)
  • Additional Members for Sets and Maps (p. 1101)
  • STL Functions (p. 1102)
  • Nonmodifying Sequence Operations (p. 1103)
  • Mutating Sequence Operations (p. 1107)
  • Sorting and Related Operations (p. 1115)
  • Numeric Operations (p. 1126)
  • Appendix H Selected Readings and Internet Resources (p. 1129)
  • Selected Readings (p. 1129)
  • Internet Resources (p. 1131)
  • Appendix I Converting to ANSI/ISO Standard C++ (p. 1133)
  • Use Alternatives for Some Preprocessor Directives (p. 1133)
  • Use const Instead of #define to Define Constants (p. 1133)
  • Use inline Instead of #define to Define Short Functions (p. 1135)
  • Use Function Prototypes (p. 1136)
  • Use Type Casts (p. 1136)
  • Become Familiar with C++ Features (p. 1137)
  • Use the New Header Organization (p. 1137)
  • Use Namespaces (p. 1137)
  • Use the autoptr Template (p. 1138)
  • Use the string Class (p. 1139)
  • Use the STL (p. 1139)
  • Appendix J Answers to the Review Questions (p. 1141)
  • Answers to Review Questions for Chapter 2 (p. 1141)
  • Answers to Review Questions for Chapter 3 (p. 1142)
  • Answers to Review Questions for Chapter 4 (p. 1143)
  • Answers to Review Questions for Chapter 5 (p. 1144)
  • Answers to Review Questions for Chapter 6 (p. 1145)
  • Answers to Review Questions for Chapter 7 (p. 1147)
  • Answers to Review Questions for Chapter 8 (p. 1148)
  • Answers to Review Questions for Chapter 9 (p. 1150)
  • Answers to Review Questions for Chapter 10 (p. 1151)
  • Answers to Review Questions for Chapter 11 (p. 1154)
  • Answers to Review Questions for Chapter 12 (p. 1155)
  • Answers to Review Questions for Chapter 13 (p. 1157)
  • Answers to Review Questions for Chapter 14 (p. 1159)
  • Answers to Review Questions for Chapter 15 (p. 1160)
  • Answers to Review Questions for Chapter 16 (p. 1161)
  • Answers to Review Questions for Chapter 17 (p. 1162)
  • Index (p. 1165)

Excerpt provided by Syndetics

Introduction Preface to the Fifth Edition Learning C++ is an adventure of discovery, particularly because the language accommodates several programming paradigms, including object-oriented programming, generic programming, and the traditional procedural programming. C++ was a moving target as the language added new features, but now, with the ISO/ANSI C++ Standard, Second Edition (2003), in place, the language has stabilized. Contemporary compilers support most or all of the features mandated by the standard, and programmers have had time to get used to applying these features. The fifth edition of this book, C++ Primer Plus, reflects the ISO/ANSI standard and describes this matured version of C++. C++ Primer Plus discusses the basic C language and presents C++ features, making this book self-contained. It presents C++ fundamentals and illustrates them with short, to-the-point programs that are easy to copy and experiment with. You'll learn about input/output (I/O), how to make programs perform repetitive tasks and make choices, the many ways to handle data, and how to use functions. You'll learn about the many features C++ has added to C, including the following: Classes and objects Inheritance Polymorphism, virtual functions, and runtime type identification (RTTI) Function overloading Reference variables Generic, or type-independent, programming, as provided by templates and the Standard Template Library (STL) The exception mechanism for handling error conditions Namespaces for managing names of functions, classes, and variables The Primer Approach C++ Primer Plus brings several virtues to the task of presenting all this material. It builds on the primer tradition begun by C Primer Plus nearly two decades ago and embraces its successful philosophy: A primer should be an easy-to-use, friendly guide. A primer doesn't assume that you are already familiar with all relevant programming concepts. A primer emphasizes hands-on learning with brief, easily typed examples that develop your understanding, a concept or two at a time. A primer clarifies concepts with illustrations. A primer provides questions and exercises to let you test your understanding, making the book suitable for self-learning or for the classroom. Following these principles, the book helps you understand this rich language and how to use it. For example: It provides conceptual guidance about when to use particular features, such as using public inheritance to model what are known as is-a relationships. It illustrates common C++ programming idioms and techniques. It provides a variety of sidebars, including tips, cautions, things to remember, compatibility notes, and real-world notes. The author and editors of this book do our best to keep the presentation to-the-point, simple, and fun. Our goal is that by the end of the book, you'll be able to write solid, effective programs and enjoy yourself doing so. Sample Code Used in This Book This book provides an abundance of sample code, most of it in the form of complete programs. Like the previous editions, this book practices generic C++ so that it is not tied to any particular kind of computer, operating system, or compiler. Thus, the examples were tested on a Windows XP system, a Macintosh OS X system, and a Linux system. Only a few programs were affected by compiler non-conformance issues. Compiler compliance with the C++ standard has improved since the previous edition of this book first appeared. The sample code for the complete programs described in this book is available on the Sams website, at http://www.samspublishing.com . Enter this book's ISBN (without the hyphens) in the Search box and click Search. When the book's title is displayed, click the title to go to a page where you can download the code. You also can find solutions to selected programming exercises at this site. How This Book Is Organized This book is divided into 17 chapters and 10 appendixes, summarized here. Chapter 1: Getting Started Chapter 1 relates how Bjarne Stroustrup created the C++ programming language by adding object-oriented programming support to the C language. You'll learn the distinctions between procedural languages, such as C, and object-oriented languages, such as C++. You'll read about the joint ANSI/ISO work to develop a C++ standard. This chapter discusses the mechanics of creating a C++ program, outlining the approach for several current C++ compilers. Finally, it describes the conventions used in this book. Chapter 2: Setting Out to C++ Chapter 2 guides you through the process of creating simple C++ programs. You'll learn about the role of the main() function and about some of the kinds of statements that C++ programs use. You'll use the predefined cout and cin objects for program output and input, and you'll learn about creating and using variables. Finally, you'll be introduced to functions, C++'s programming modules. Chapter 3: Dealing with Data C++ provides built-in types for storing two kinds of data: integers (numbers with no fractional parts) and floating-point numbers (numbers with fractional parts). To meet the diverse requirements of programmers, C++ offers several types in each category. Chapter 3 discusses those types, including creating variables and writing constants of various types. You'll also learn how C++ handles implicit and explicit conversions from one type to another. Chapter 4: Compound Types C++ lets you construct more elaborate types from the basic built-in types. The most advanced form is the class, discussed in Chapters 9 through 13. Chapter 4 discusses other forms, including arrays, which hold several values of a single type; structures, which hold several values of unlike types; and pointers, which identify locations in memory. You'll also learn how to create and store text strings and to handle text I/O by using C-style character arrays and the C++ string class. Finally, you'll learn some of the ways C++ handles memory allocation, including using the new and delete operators for managing memory explicitly. Chapter 5: Loops and Relational Expressions Programs often must perform repetitive actions, and C++ provides three looping structures for that purpose: the for loop, the while loop, and the do while loop. Such loops must know when they should terminate, and the C++ relational operators enable you to create tests to guide such loops. In Chapter 5 you learn how to create loops that read and process input character-by-character. Finally, you'll learn how to create two-dimensional arrays and how to use nested loops to process them. Chapter 6: Branching Statements and Logical Operators Programs can behave intelligently if they can tailor their behavior to circumstances. In Chapter 6 you'll learn how to control program flow by using the if , if else , and switch statements and the conditional operator. You'll learn how to use logical operators to help express decision-making tests. Also, you'll meet the cctype library of functions for evaluating character relations, such as testing whether a character is a digit or a nonprinting character. Finally, you'll get an introductory view of file I/O. Chapter 7: Functions: C++'s Programming Modules Functions are the basic building blocks of C++ programming. Chapter 7 concentrates on features that C++ functions share with C functions. In particular, you'll review the general format of a function definition and examine how function prototypes increase the reliability of programs. Also, you'll investigate how to write functions to process arrays, character strings, and structures. Next, you'll learn about recursion, which is when a function calls itself, and see how it can be used to implement a divide-and-conquer strategy. Finally, you'll meet pointers to functions, which enable you to use a function argument to tell one function to use a second function. Chapter 8: Adventures in Functions Chapter 8 explores the new features C++ adds to functions. You'll learn about inline functions, which can speed program execution at the cost of additional program size. You'll work with reference variables, which provide an alternative way to pass information to functions. Default arguments let a function automatically supply values for function arguments that you omit from a function call. Function overloading lets you create functions having the same name but taking different argument lists. All these features have frequent use in class design. Also, you'll learn about function templates, which allow you to specify the design of a family of related functions. Chapter 9: Memory Models and Namespaces Chapter 9 discusses putting together multifile programs. It examines the choices in allocating memory, looking at different methods of managing memory and at scope, linkage, and namespaces, which determine what parts of a program know about a variable. Chapter 10: Objects and Classes A class is a user-defined type, and an object (such as a variable) is an instance of a class. Chapter 10 introduces you to object-oriented programming and to class design. A class declaration describes the information stored in a class object and also the operations (class methods) allowed for class objects. Some parts of an object are visible to the outside world (the public portion), and some are hidden (the private portion). Special class methods (constructors and destructors) come into play when objects are created and destroyed. You will learn about all this and other class details in this chapter, and you'll see how classes can be used to implement ADTs, such as a stack. Chapter 11: Working with Classes In Chapter 11 you'll further your understanding of classes. First, you'll learn about operator overloading, which lets you define how operators such as + will work with class objects. You'll learn about friend functions, which can access class data that's inaccessible to the world at large. You'll see how certain constructors and overloaded operator member functions can be used to manage conversion to and from class types. Chapter 12: Classes and Dynamic Memory Allocation Often it's useful to have a class member point to dynamically allocated memory. If you use new in a class constructor to allocate dynamic memory, you incur the responsibilities of providing an appropriate destructor, of defining an explicit copy constructor, and of defining an explicit assignment operator. Chapter 12 shows you how and discusses the behavior of the member functions generated implicitly if you fail to provide explicit definitions. You'll also expand your experience with classes by using pointers to objects and studying a queue simulation problem. Chapter 13: Class Inheritance One of the most powerful features of object-oriented programming is inheritance, by which a derived class inherits the features of a base class, enabling you to reuse the base class code. Chapter 13 discusses public inheritance, which models is-a relationships, meaning that a derived object is a special case of a base object. For example, a physicist is a special case of a scientist. Some inheritance relationships are polymorphic, meaning you can write code using a mixture of related classes for which the same method name may invoke behavior that depends on the object type. Implementing this kind of behavior necessitates using a new kind of member function called a virtual function. Sometimes using abstract base classes is the best approach to inheritance relationships. This chapter discusses these matters, pointing out when public inheritance is appropriate and when it is not. Chapter 14: Reusing Code in C++ Public inheritance is just one way to reuse code. Chapter 14 looks at several other ways. Containment is when one class contains members that are objects of another class. It can be used to model has-a relationships, in which one class has components of another class. For example, an automobile has a motor. You also can use private and protected inheritance to model such relationships. This chapter shows you how and points out the differences among the different approaches. Also, you'll learn about class templates, which let you define a class in terms of some unspecified generic type, and then use the template to create specific classes in terms of specific types. For example, a stack template enables you to create a stack of integers or a stack of strings. Finally, you'll learn about multiple public inheritance, whereby a class can derive from more than one class. Chapter 15: Friends, Exceptions, and More Chapter 15 extends the discussion of friends to include friend classes and friend member functions. Then it presents several new developments in C++, beginning with exceptions, which provide a mechanism for dealing with unusual program occurrences, such an inappropriate function argument values and running out of memory. Then you'll learn about RTTI, a mechanism for identifying object types. Finally, you'll learn about the safer alternatives to unrestricted typecasting. Chapter 16: The string Class and the Standard Template Library Chapter 16 discusses some useful class libraries recently added to the language. The string class is a convenient and powerful alternative to traditional C-style strings. The auto_ptr class helps manage dynamically allocated memory. The STL provides several generic containers, including template representations of arrays, queues, lists, sets, and maps. It also provides an efficient library of generic algorithms that can be used with STL containers and also with ordinary arrays. The valarray template class provides support for numeric arrays. Chapter 17: Input, Output, and Files Chapter 17 reviews C++ I/O and discusses how to format output. You'll learn how to use class methods to determine the state of an input or output stream and to see, for example, whether there has been a type mismatch on input or whether the end-of-file has been detected. C++ uses inheritance to derive classes for managing file input and output. You'll learn how to open files for input and output, how to append data to a file, how to use binary files, and how to get random access to a file. Finally, youlearn how to apply standard I/O methods to read from and write to strings. Appendix A: Number Bases Appendix A discusses octal, hexadecimal, and binary numbers. Appendix B: C++ Reserved Words Appendix B lists C++ keywords. Appendix C: The ASCII Character Set Appendix C lists the ASCII character set, along with decimal, octal, hexadecimal, and binary representations. Appendix D: Operator Precedence Appendix D lists the C++ operators in order of decreasing precedence. Appendix E: Other Operators Appendix E summarizes the C++ operators, such as the bitwise operators, not covered in the main body of the text. Appendix F: The string Template Class Appendix F summarizes string class methods and functions. Appendix G: The STL Methods and Functions Appendix G summarizes the STL container methods and the general STL algorithm functions. Appendix H: Selected Readings and Internet Resources Appendix H lists some books that can further your understanding of C++. Appendix I: Converting to ANSI/ISO Standard C++ Appendix I provides guidelines for moving from C and older C++ implementations to ANSI/ISO C++. Appendix J: Answers to Review Questions Appendix J contains the answers to the review questions posed at the end of each chapter. Note to Instructors One of the goals of this edition of C++ Primer Plus is to provide a book that can be used as either a teach-yourself book or as a textbook. Here are some of the features that support using C++ Primer Plus, Fifth Edition, as a textbook: This book describes generic C++, so it isn't dependent on a particular implementation. The contents track the ISO/ANSI C++ standards committee's work and include discussions of templates, the STL, the string class, exceptions, RTTI, and namespaces. It doesn't assume prior knowledge of C, so it can be used without a C prerequisite. (Some programming background is desirable, however.) Topics are arranged so that the early chapters can be covered rapidly as review chapters for courses that do have a C prerequisite. Chapters include review questions and programming exercises. Appendix J provides the answers to the review questions. Solutions to selected programming exercises can be found at the Sams website ( http://www.samspublishing.com ). The book introduces several topics that are appropriate for computer science courses, including abstract data types (ADTs), stacks, queues, simple lists, simulations, generic programming, and using recursion to implement a divide-and-conquer strategy. Most chapters are short enough to cover in a week or less. The book discusses when to use certain features as well as how to use them. For example, it links public inheritance to is-a relationships and composition and private inheritance to has-a relationships, and it discusses when to use virtual functions and when not to. Conventions Used in This Book This book uses several typographic conventions to distinguish among various kinds of text: Code lines, commands, statements, variables, filenames, and program output appear in a computer typeface : #include int main(){{ using namespace std; cout << "What's up, Doc!\ n"; return 0;}} Program input that you should type appears in bold computer typeface : Please enter your name: Plato Placeholders in syntax descriptions appear in an italic computer typeface. You should replace a placeholder with the actual filename, parameter, or whatever element it represents. Italic type is used for new terms. This book includes several elements intended to illuminate specific points: Compatibility Note - Most compilers are not yet 100% compliant with the ISO/ANSI Standard, and these notes warn you of discrepancies you may encounter. Remember - These notes highlight points that are important to remember. Real-World Note - Several professional programmers offer observations based on their experiences. Sidebar - A sidebar provides a deeper discussion or additional background to help illuminate a topic. Tip - Tips present short, helpful guides to particular programming situations. Caution - A caution alerts you to potential pitfalls. Note - The notes provide a catch-all category for comments that don't fall into one of the other categories. Systems Used to Develop This Book's Programming Examples For the record, the examples in this book were developed using Microsoft Visual C++ 7.1 (the version that comes with Microsoft Visual Studio .NET 2003) and Metrowerks CodeWarrior Development Studio 9 on a Pentium PC with a hard disk and running under Windows XP Professional. Most programs were checked using the Borland C++ 5.5 command-line compiler and GNU gpp 3.3.3 on the same system, using Comeau 4.3.3 and GNU g++ 3.3.1 on an IBM-compatible Pentium running SuSE 9.0 Linux, and using Metrowerks Development Studio 9 on a Macintosh G4 under OS 10.3. This book reports discrepancies stemming from lagging behind the standard generically, as in "older implementations use ios::fixed instead of ios_base::fixed ." This book reports some bugs and idiosyncrasies in older compilers that would prove troublesome or confusing; most of these have been fixed in current releases. C++ offers a lot to the programmer; learn and enjoy! (c) Copyright Pearson Education. All rights reserved. Excerpted from C++ Primer Plus by Stephen Prata All rights reserved by the original copyright owners. Excerpts are provided for display purposes only and may not be reproduced, reprinted or distributed without the written permission of the publisher.

Author notes provided by Syndetics

Stephen Prata teaches astronomy, physics, and computer science at the College of Marin in Kentfield, California.

Powered by Koha