Product Cover Image

C++ for Programmers, Safari

By Paul J. Deitel, Harvey M. Deitel

Published by Prentice Hall

Published Date: Jan 23, 2009

More Product Info

Description

&>

A Video Enhanced book which contains embedded links to instructional videos
from: C++ Fundamentals I and II LiveLessons (Video Training) by Paul J. Deitel. https://ssl.safaribooksonline.com/9780137045150

 

PRACTICAL, EXAMPLE-RICH COVERAGE OF:

  • Classes, Objects, Encapsulation, Inheritance, Polymorphism
  • Integrated OOP Case Studies: Time, GradeBook, Employee
  • Industrial-Strength, 95-Page OOD/UML® 2 ATM Case Study
  • Standard Template Library (STL): Containers, Iterators and Algorithms
  • I/O, Types, Control Statements, Functions
  • Arrays, Vectors, Pointers, References
  • String Class, C-Style Strings
  • Operator Overloading, Templates
  • Exception Handling, Files
  • Bit and Character Manipulation
  • Boost Libraries and the Future of C++
  • GNU™ and Visual C++® Debuggers
  • And more…
VISIT WWW.DEITEL.COM
  • For information on Deitel® Dive-Into® Series corporate training courses offered at customer sites worldwide (or write to deitel@deitel.com)
  • Download code examples
  • Check out the growing list of programming, Web 2.0 and software-related Resource Centers
  • To receive updates for this book, subscribe to the free DEITEL® BUZZ ONLINE e-mail newsletter at www.deitel.com/newsletter/subscribe.html
  • Read archived issues of the DEITEL® BUZZ ONLINE
The professional programmer’s DEITEL® guide to C++ and object-oriented application development

Written for programmers with a background in high-level language programming, this book applies the Deitel signature live-code approach to teaching programming and explores the C++ language and C++ Standard Libraries in depth. The book presents the concepts in the context of fully tested programs, complete with syntax shading, code highlighting, code walkthroughs and program outputs. The book features 240 C++ applications with over 15,000 lines of proven C++ code, and hundreds of tips that will help you build robust applications.

Start with an introduction to C++ using an early classes and objects approach, then rapidly move on to more advanced topics, including templates, exception handling, the Standard Template Library (STL) and selected features from the Boost libraries. You’ll enjoy the Deitels’ classic treatment of object-oriented programming and the OOD/UML® 2 ATM case study, including a complete C++ implementation. When you’re finished, you’ll have everything you need to build object-oriented C++ applications.

The DEITEL® Developer Series is designed for practicing programmers. The series presents focused treatments of emerging technologies, including C++, .NET, Java™, web services, Internet and web development and more. 
  
PRE-PUBLICATION REVIEWER TESTIMONIALS
“An excellent ‘objects first’ coverage of C++. The example-driven presentation is enriched by the optional UML case study that contextualizes the material in an ongoing software engineering project.” –Gavin Osborne, Saskatchewan Institute of Applied Science and Technology

“Introducing the UML early on is a great idea.” –Raymond Stephenson, Microsoft

“Good use of diagrams, especially of the activation call stack and recursive functions.” –Amar Raheja, California State Polytechnic University, Pomona

“Terrific discussion of pointers–probably the best I have seen.” –Anne B. Horton, Lockheed Martin

“Great coverage of polymorphism and how the compiler implements polymorphism ‘under the hood.’” –Ed James-Beckham, Borland

“The Boost/C++0x chapter will get you up and running quickly with the memory management and regular expression libraries, plus whet your appetite for new C++ features being standardized.” –Ed Brey, Kohler Co.

“Excellent introduction to the Standard Template Library (STL). The best book on C++ programming!”  –Richard Albright, Goldey-Beacom College

“Just when you think you are focused on learning one topic, suddenly you discover you’ve learned more than you expected.” –Chad Willwerth, University of Washington, Tacoma

“The most thorough C++ treatment I’ve seen. Replete with real-world case studies covering the full software development lifecycle. Code examples are extraordinary!” –Terrell Hull, Logicalis Integration Solutions/

Table of Contents

Preface      xxi
Before You Begin      xli


Chapter 1: Introduction      1
1.1   Introduction 2
1.2   History of C and C++ 3
1.3   C++ Standard Library 4
1.4   Key Software Trend: Object Technology 5
1.5   Typical C++ Development Environment 6
1.6   Notes About C++ and C++ for Programmers 8
1.7   Test-Driving a C++ Application 9
1.8   Software Technologies 15
1.9   Future of C++: Open Source Boost Libraries, TR1 and C++0x 16
1.10  Software Engineering Case Study: Introduction to Object Technology and the UML 16
1.11  Wrap-Up 21
1.12  Web Resources 22

Chapter 2: Introduction to C++ Programming      24
2.1   Introduction 25
2.2   First Program in C++: Printing a Line of Text 25
2.3   Modifying Our First C++ Program 28
2.4   Another C++ Program: Adding Integers 29
2.5   Arithmetic 33
2.6   Decision Making: Equality and Relational Operators 35
2.7   (Optional) Software Engineering Case Study: Examining the ATM Requirements Specification 38
2.8   Wrap-Up 47

Chapter 3: Introduction to Classes and Objects      48
3.1   Introduction 49
3.2   Classes, Objects, Member Functions and Data Members 49
3.3   Overview of the Chapter Examples 51
3.4   Defining a Class with a Member Function 52
3.5   Defining a Member Function with a Parameter 55
3.6   Data Members, set Functions and get Functions 58
3.7   Initializing Objects with Constructors 65
3.8   Placing a Class in a Separate File for Reusability 69
3.9   Separating Interface from Implementation 73
3.10  Validating Data with set Functions 79
3.11  (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Specification 84
3.12  Wrap-Up 92

Chapter 4: Control Statements: Part 1      93
4.1   Introduction 94
4.2   Control Structures 94
4.3   if Selection Statement 97
4.4   if…else Double-Selection Statement 98
4.5   while Repetition Statement 102
4.6   Counter-Controlled Repetition 104
4.7   Sentinel-Controlled Repetition 108
4.8   Nested Control Statements 115
4.9    Assignment Operators 118
4.10  Increment and Decrement Operators 119
4.11  (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System 122
4.12  Wrap-Up 127

Chapter 5: Control Statements: Part 2      128
5.1   Introduction 129
5.2   Essentials of Counter-Controlled Repetition 129
5.3   for Repetition Statement 131
5.4   Examples Using the for Statement 134
5.5   do…while Repetition Statement 139
5.6   switch Multiple-Selection Statement 141
5.7   break and continue Statements 151
5.8   Logical Operators 153
5.9   Confusing the Equality (==) and Assignment (=) Operators 158
5.10 (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities in the ATM System 159
5.11 Wrap-Up 163

Chapter 6: Functions and an Introduction to Recursion      165
6.1   Introduction 166
6.2   Program Components in C++ 167
6.3   Math Library Functions 167
6.4   Function Definitions with Multiple Parameters 168
6.5   Function Prototypes and Argument Coercion 173
6.6   C++ Standard Library Header Files 176
6.7   Case Study: Random Number Generation 178
6.8   Case Study: Game of Chance; Introducing enum 184
6.9   Storage Classes 187
6.10  Scope Rules 190
6.11  Function Call Stack and Activation Records 193
6.12  Functions with Empty Parameter Lists 197
6.13  Inline Functions 198
6.14  References and Reference Parameters 200
6.15  Default Arguments 205
6.16  Unary Scope Resolution Operator 207
6.17  Function Overloading 208
6.18  Function Templates 211
6.19  Recursion 213
6.20  Example Using Recursion: Fibonacci Series 217
6.21  Recursion vs. Iteration 220
6.22  (Optional) Software Engineering Case Study: Identifying Class Operations in the ATM System 222
6.23  Wrap-Up 229

Chapter 7: Arrays and Vectors      230
7.1   Introduction 231
7.2   Arrays 232
7.3   Declaring Arrays 234
7.4   Examples Using Arrays 234
7.5   Passing Arrays to Functions 250
7.6   Case Study: Class GradeBook Using an Array to Store Grades 255
7.7   Searching Arrays with Linear Search 262
7.8   Sorting Arrays with Insertion Sort 263
7.9   Multidimensional Arrays 265
7.10  Case Study: Class GradeBook Using a Two-Dimensional Array 268
7.11  Introduction to C++ Standard Library Class Template vector 275
7.12  (Optional) Software Engineering Case Study: Collaboration Among Objects in the ATM System 281
7.13 Wrap-Up 288

Chapter 8: Pointers and Pointer-Based Strings       289
8.1   Introduction 290
8.2   Pointer Variable Declarations and Initialization 290
8.3   Pointer Operators 292
8.4   Passing Arguments to Functions by Reference with Pointers 295
8.5   Using const with Pointers 299
8.6   Selection Sort Using Pass-by-Reference 306
8.7   sizeof Operator 309
8.8   Pointer Expressions and Pointer Arithmetic 312
8.9   Relationship Between Pointers and Arrays 315
8.10  Arrays of Pointers 319
8.11  Case Study: Card Shuffling and Dealing Simulation 320
8.12  Function Pointers 324
8.13  Introduction to Pointer-Based String Processing 330
8.14  Wrap-Up 340

Chapter 9: Classes: A Deeper Look, Part 1       342
9.1   Introduction 343
9.2   Time Class Case Study 344
9.3   Class Scope and Accessing Class Members 350
9.4   Separating Interface from Implementation 352
9.5   Access Functions and Utility Functions 353
9.6   Time Class Case Study: Constructors with Default Arguments 356
9.7   Destructors 361
9.8   When Constructors and Destructors Are Called 362
9.9   Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member 366
9.10  Default Memberwise Assignment 368
9.11  (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System 371
9.12  Wrap-Up 378

Chapter 10: Classes: A Deeper Look, Part 2      380
10.1   Introduction 381
10.2   const (Constant) Objects and const Member Functions 381
10.3   Composition: Objects as Members of Classes 391
10.4   friend Functions and friend Classes 398
10.5   Using the this Pointer 402
10.6   Dynamic Memory Management with Operators new and delete 407
10.7   static Class Members 409
10.8   Data Abstraction and Information Hiding 415
10.9   Container Classes and Iterators 418
10.10  Proxy Classes 418
10.11  Wrap-Up 422

Chapter 11: Operator Overloading; String and Array Objects       423
11.1   Introduction 424
11.2   Fundamentals of Operator Overloading 425
11.3   Restrictions on Operator Overloading 426
11.4   Operator Functions as Class Members vs. Global Functions 428
11.5   Overloading Stream Insertion and Stream Extraction Operators 429
11.6   Overloading Unary Operators 433
11.7   Overloading Binary Operators 433
11.8   Case Study: Array Class 434
11.9   Converting between Types 446
11.10  Case Study: String Class 447
11.11  Overloading ++ and -- 459
11.12  Case Study: A Date Class 461
11.13  Standard Library Class string 465
11.14  explicit Constructors 469
11.15  Wrap-Up 473

Chapter 12: Object-Oriented Programming: Inheritance       474
12.1  Introduction 475
12.2  Base Classes and Derived Classes 476
12.3  protected Members 479
12.4  Relationship between Base Classes and Derived Classes 479
12.5  Constructors and Destructors in Derived Classes 511
12.6  public, protected and private Inheritance 519
12.7  Software Engineering with Inheritance 519
12.8  Wrap-Up 521

Chapter 13: Object-Oriented Programming: Polymorphism      522
13.1   Introduction 523
13.2   Polymorphism Examples 525
13.3   Relationships Among Objects in an Inheritance Hierarchy 526
13.4   Type Fields and switch Statements 544
13.5   Abstract Classes and Pure virtual Functions 544
13.6   Case Study: Payroll System Using Polymorphism 546
13.7   (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood” 564
13.8   Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info 568
13.9   Virtual Destructors 571
13.10  (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System 572
13.11  Wrap-Up 580

Chapter 14 Templates       581
14.1  Introduction 582
14.2  Function Templates 583
14.3  Overloading Function Templates 586
14.4  Class Templates 586
14.5  Nontype Parameters and Default Types for Class Templates 593
14.6  Notes on Templates and Inheritance 594
14.7  Notes on Templates and Friends 594
14.8  Notes on Templates and static Members 595
14.9  Wrap-Up 596

Chapter 15: Stream Input/Output        597
15.1   Introduction 598
15.2   Streams 599
15.3   Stream Output 603
15.4   Stream Input 604
15.5   Unformatted I/O Using read, write and gcount 608
15.6   Introduction to Stream Manipulators 609
15.7   Stream Format States and Stream Manipulators 615
15.8   Stream Error States 625
15.9   Tying an Output Stream to an Input Stream 628
15.10  Wrap-Up 628

Chapter 16: Exception Handling      629
16.1   Introduction 630
16.2   Exception-Handling Overview 631
16.3   Example: Handling an Attempt to Divide by Zero 631
16.4   When to Use Exception Handling 637
16.5   Rethrowing an Exception 638
16.6   Exception Specifications 640
16.7   Processing Unexpected Exceptions 641
16.8   Stack Unwinding 641
16.9   Constructors, Destructors and Exception Handling 643
16.10  Exceptions and Inheritance 644
16.11  Processing new Failures 644
16.12  Class auto_ptr and Dynamic Memory Allocation 648
16.13  Standard Library Exception Hierarchy 651
16.14  Other Error-Handling Techniques 652
16.15  Wrap-Up 653

Chapter 17: File Processing      654
17.1   Introduction 655
17.2   Data Hierarchy 655
17.3   Files and Streams 657
17.4   Creating a Sequential File 658
17.5   Reading Data from a Sequential File 662
17.6   Updating Sequential Files 669
17.7   Random-Access Files 669
17.8   Creating a Random-Access File 670
17.9   Writing Data Randomly to a Random-Access File 675
17.10  Reading from a Random-Access File Sequentially 677
17.11  Case Study: A Transaction-Processing Program 680
17.12  Overview of Object Serialization 687
17.13  Wrap-Up 687

Chapter 18: Class string and String Stream Processing      688
18.1   Introduction 689
18.2   string Assignment and Concatenation 690
18.3   Comparing strings 692
18.4   Substrings 695
18.5   Swapping strings 696
18.6   string Characteristics 697
18.7   Finding Substrings and Characters in a string 699
18.8   Replacing Characters in a string 701
18.9   Inserting Characters into a string 703
18.10  Conversion to C-Style Pointer-Based char * Strings 704
18.11  Iterators 706
18.12  String Stream Processing 707
18.13  Wrap-Up 710

Chapter 19: Bits, Characters, C Strings and structs      711
19.1   Introduction 712
19.2   Structure Definitions 712
19.3   Initializing Structures 715
19.4   Using Structures with Functions 715
19.5   typedef 715
19.6   Example: High-Performance Card Shuffling and Dealing Simulation 716
19.7   Bitwise Operators 719
19.8   Bit Fields 728
19.9   Character-Handling Library 732
19.10  Pointer-Based String-Conversion Functions 738
19.11  Search Functions of the Pointer-Based String-Handling Library 743
19.12  Memory Functions of the Pointer-Based String-Handling Library 748
19.13  Wrap-Up 753

Chapter 20: Standard Template Library (STL)      754
20.1  Introduction to the Standard Template Library (STL) 756
20.2  Sequence Containers 768
20.3  Associative Containers 782
20.4  Container Adapters 791
20.5  Algorithms 796
20.6  Class bitset 827
20.7  Function Objects 831
20.8  Wrap-Up 834
20.9  STL Web Resources 835

Chapter 21: Boost Libraries, Technical Report 1 and C++0x       836
21.1   Introduction 837
21.2   Deitel Online C++ and Related Resource Centers 837
21.3   Boost Libraries 838
21.4   Adding a New Library to Boost 838
21.5   Installing the Boost Libraries 839
21.6   Boost Libraries in Technical Report 1 (TR1) 839
21.7   Regular Expressions with the Boost.Regex Library 842
21.8   Smart Pointers with Boost.Smart_ptr 851
21.9   Technical Report 1 862
21.10  C++0x 863
21.11  Core Language Changes 863
21.12  Wrap-Up 868

Chapter 22: Other Topics       869
22.1  Introduction 870
22.2  const_cast Operator 870
22.3  namespaces 872
22.4 Operator Keywords 876
22.5  mutable Class Members 878
22.6  Pointers to Class Members (.* and ->*) 880
22.7  Multiple Inheritance 882
22.8  Multiple Inheritance and virtual Base Classes 887
22.9  Wrap-Up 891

Appendix A: Operator Precedence and Associativity Chart      892
A.1  Operator Precedence 892

Appendix B: ASCII Character Set      895

Appendix C: Fundamental Types      896

Appendix D: Preprocessor      898
D.1   Introduction 899
D.2   The #include Preprocessor Directive 899
D.3   The #define Preprocessor Directive: Symbolic Constants 900
D.4   The #define Preprocessor Directive: Macros 900
D.5   Conditional Compilation 902
D.6   The #error and #pragma Preprocessor Directives 903
D.7   Operators # and ## 904
D.8   Predefined Symbolic Constants 904
D.9   Assertions 905
D.10  Wrap-Up 905

Appendix E: ATM Case Study Code      906
E.1   ATM Case Study Implementation 906
E.2   Class ATM 907
E.3   Class Screen 914
E.4   Class Keypad 915
E.5   Class CashDispenser 916
E.6   Class DepositSlot 918
E.7   Class Account 919
E.8   Class BankDatabase 921
E.9   Class Transaction 925
E.10  Class BalanceInquiry 927
E.11  Class Withdrawal 929
E.12  Class Deposit 934
E.13  Test Program ATMCaseStudy.cpp 937
E.14  Wrap-Up 937

Appendix F: UML 2: Additional Diagram Types      938
F.1  Introduction 938
F.2  Additional Diagram Types 938

Appendix G: Using the Visual Studio Debugger       940
G.1  Introduction 941
G.2  Breakpoints and the Continue Command 941
G.3  Locals and Watch Windows 946
G.4  Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands 949
G.5  Autos Window 952
G.6  Wrap-Up 953

Appendix H: Using the GNU C++ Debugger       954
H.1  Introduction 955
H.2  Breakpoints and the run, stop, continue and print Commands 955
H.3  print and set Commands 962
H.4  Controlling Execution Using the step, finish and next Commands 964
H.5  watch Command 966
H.6  Wrap-Up 968

Bibliography      970
Index       976


Purchase Info

ISBN-10: 0-13-701849-5

ISBN-13: 978-0-13-701849-9

Format: Safari PTG

This publication is not currently for sale.