Sams Teach Yourself C++ in One Hour a Day

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Learn C++ in Just One Hour a Day Completely updated for the C++11 standard, Sams Teach Yourself C++ in One Hour a Day presents the language from a practical point of view, helping you learn how to use C++11 to create faster, simpler, and more efficient C++ applications. Master the fundamentals of C++ and object-oriented programming Understand how C++11 features help you write compact and efficient code using concepts such as lambda expressions, move constructors, and assignment operators Learn the Standard Template Library, including containers and algorithms used in most real-world C++ applications Test your knowledge and expertise using exercises at the end of every lesson Learn on your own time, at your own pace: No previous programming experience required Learn C++11, object-oriented programming, and analysis Write fast and powerful C++ programs, compile the source code with a gcc compiler, and create executable files Use the Standard Template Library’s (STL) algorithms and containers to write feature-rich yet stable C++ applications Develop sophisticated programming techniques using lambda expressions, smart pointers, and move constructors Learn to expand your program’s power with inheritance and polymorphism Master the features of C++ by learning from programming experts Learn C++11 features that allow you to program compact and high-performance C++ applications TABLE OF CONTENTS PART I: THE BASICS LESSON 1: Getting Started with C++11 LESSON 2: The Anatomy of a C++ Program LESSON 3: Using Variables, Declaring Constants LESSON 4: Managing Arrays and Strings LESSON 5: Working with Expressions, Statements, and Operators LESSON 6: Controlling Program Flow LESSON 7: Organizing Code with Functions LESSON 8: Pointers and References Explained PART II: FUNDAMENTALS OF OBJECT-ORIENTED C++ PROGRAMMING LESSON 9: Classes and Objects LESSON 10: Implementing Inheritance LESSON 11: Polymorphism LESSON 12: Operator Types and Operator Overloading LESSON 13: Casting Operators LESSON 14: An Introduction to Macros and Templates PART III: LEARNING THE STANDARD TEMPLATE LIBRARY (STL) LESSON 15: An Introduction to the Standard Template LibraryLESSON 16: The STL String ClassLESSON 17: STL Dynamic Array ClassesLESSON 18: STL list and forward_listLESSON 19: STL Set ClassesLESSON 20: STL Map Classes PART IV: MORE STL LESSON 21: Understanding Function ObjectsLESSON 22: C++11 Lambda ExpressionsLESSON 23: STL AlgorithmsLESSON 24: Adaptive Containers: Stack and QueueLESSON 25: Working with Bit Flags Using STL PART V: ADVANCED C++ CONCEPTS LESSON 26: Understanding Smart PointersLESSON 27: Using Streams for Input and OutputLESSON 28: Exception HandlingLESSON 29: Going Forward APPENDIXES A: Working with Numbers: Binary and Hexadecimal B: C++ Keywords C: Operator Precedence D: Answers E: ASCII Codes

Author(s): Siddhartha Rao
Edition: 7th Edition
Publisher: Sams Publishing
Year: 2012

Language: English
Pages: 768

Table of Contents......Page 6
Introduction......Page 24
LESSON 1: Getting Started......Page 28
A Brief History of C++......Page 29
Programming a C++ Application......Page 30
What’s New in C++11......Page 35
Q&A......Page 36
Workshop......Page 37
LESSON 2: The Anatomy of a C++ Program......Page 38
Part of the Hello World Program......Page 39
The Concept of Namespaces......Page 42
Comments in C++ Code......Page 43
Functions in C++......Page 44
Basic Input Using std::cin and Output Using std::cout......Page 47
Q&A......Page 49
Workshop......Page 50
LESSON 3: Using Variables, Declaring Constants......Page 52
What Is a Variable?......Page 53
Common Compiler-Supported C++ Variable Types......Page 59
Determining the Size of a Variable Using sizeof......Page 63
Using typedef to Substitute a Variable’s Type......Page 67
What Is a Constant?......Page 68
Naming Variables and Constants......Page 74
Keywords You Cannot Use as Variable or Constant Names......Page 75
Q&A......Page 76
Workshop......Page 78
LESSON 4: Managing Arrays and Strings......Page 80
What Is an Array?......Page 81
Multidimensional Arrays......Page 88
Dynamic Arrays......Page 91
C-style Strings......Page 93
C++ Strings: Using std::string......Page 95
Q&A......Page 98
Workshop......Page 99
LESSON 5: Working with Expressions, Statements, and Operators......Page 100
Statements......Page 101
Using Operators......Page 102
Summary......Page 124
Workshop......Page 125
LESSON 6: Controlling Program Flow......Page 128
Conditional Execution Using if … else......Page 129
Getting Code to Execute in Loops......Page 142
Modifying Loop Behavior Using continue and break......Page 151
Programming Nested Loops......Page 156
Summary......Page 160
Workshop......Page 161
LESSON 7: Organizing Code with Functions......Page 164
The Need for Functions......Page 165
Using Functions to Work with Different Forms of Data......Page 175
How Function Calls Are Handled by the Microprocessor......Page 181
Summary......Page 185
Workshop......Page 186
LESSON 8: Pointers and References Explained......Page 188
What Is a Pointer?......Page 189
Dynamic Memory Allocation......Page 198
Common Programming Mistakes When Using Pointers......Page 209
Pointer Programming Best-Practices......Page 212
What Is a Reference?......Page 216
Q&A......Page 221
Workshop......Page 223
LESSON 9: Classes and Objects......Page 226
The Concept of Classes and Objects......Page 227
Keywords public and private......Page 231
Constructors......Page 235
Destructor......Page 245
Copy Constructor......Page 248
Different Uses of Constructors and Destructor......Page 258
This Pointer......Page 264
Sizeof() a Class......Page 265
How struct Differs from class......Page 267
Declaring a friend of a class......Page 268
Summary......Page 270
Q&A......Page 271
Workshop......Page 272
LESSON 10: Implementing Inheritance......Page 274
Basics of Inheritance......Page 275
Private Inheritance......Page 294
Protected Inheritance......Page 296
Multiple Inheritance......Page 300
Workshop......Page 304
LESSON 11: Polymorphism......Page 306
Basics of Polymorphism......Page 307
Using virtual Inheritance to Solve the Diamond Problem......Page 322
Virtual Copy Constructors?......Page 327
Q&A......Page 330
Workshop......Page 331
LESSON 12: Operator Types and Operator Overloading......Page 334
What Are Operators in C++?......Page 335
Unary Operators......Page 336
Binary Operators......Page 346
Function Operator ()......Page 365
Operators That Cannot Be Overloaded......Page 372
Summary......Page 373
Workshop......Page 374
LESSON 13: Casting Operators......Page 376
The Need for Casting......Page 377
The C++ Casting Operators......Page 378
Problems with the C++ Casting Operators......Page 385
Summary......Page 386
Workshop......Page 387
LESSON 14: An Introduction to Macros and Templates......Page 390
Using #define Macros to Define Constants......Page 391
Using #define To Write Macro Functions......Page 395
An Introduction to Templates......Page 401
Q&A......Page 413
Workshop......Page 414
LESSON 15: An Introduction to the Standard Template Library......Page 416
STL Containers......Page 417
STL Iterators......Page 422
The Interaction Between Containers and Algorithms Using Iterators......Page 423
Q&A......Page 426
Workshop......Page 427
LESSON 16: The STL String Class......Page 428
The Need for String Manipulation Classes......Page 429
Working with the STL String Class......Page 430
Summary......Page 443
Workshop......Page 444
LESSON 17: STL Dynamic Array Classes......Page 446
Typical Vector Operations......Page 447
Understanding the Concepts of Size and Capacity......Page 459
The STL deque Class......Page 461
Q&A......Page 464
Workshop......Page 465
LESSON 18: STL list and forward_list......Page 468
Basic list Operations......Page 469
Reversing and Sorting Elements in a List......Page 478
Workshop......Page 488
LESSON 19: STL Set Classes......Page 490
Basic STL set and multiset Operations......Page 491
Pros and Cons of Using STL set and multiset......Page 503
Q&A......Page 507
Workshop......Page 508
LESSON 20: STL Map Classes......Page 510
An Introduction to STL Map Classes......Page 511
Basic std::map and std::multimap Operations......Page 512
Supplying a Custom Sort Predicate......Page 522
Summary......Page 531
Q&A......Page 532
Workshop......Page 533
LESSON 21: Understanding Function Objects......Page 534
Typical Applications of Function Objects......Page 535
Q&A......Page 547
Workshop......Page 548
LESSON 22: C++11 Lambda Expressions......Page 550
What Is a Lambda Expression?......Page 551
Lambda Expression for a Unary Function......Page 552
Lambda Expression for a Unary Predicate......Page 554
Lambda Expression with State via Capture Lists [...]......Page 555
The Generic Syntax of Lambda Expressions......Page 557
Lambda Expression for a Binary Function......Page 558
Lambda Expression for a Binary Predicate......Page 560
Summary......Page 563
Workshop......Page 564
LESSON 23: STL Algorithms......Page 566
Classification of STL Algorithms......Page 567
Usage of STL Algorithms......Page 570
Q&A......Page 598
Workshop......Page 599
LESSON 24: Adaptive Containers: Stack and Queue......Page 602
The Behavioral Characteristics of Stacks and Queues......Page 603
Using the STL stack Class......Page 604
Using the STL queue Class......Page 608
Using the STL Priority Queue......Page 612
Workshop......Page 617
LESSON 25: Working with Bit Flags Using STL......Page 620
The bitset Class......Page 621
Using std::bitset and Its Members......Page 622
The vector......Page 626
Q&A......Page 628
Workshop......Page 629
LESSON 26: Understanding Smart Pointers......Page 630
What Are Smart Pointers?......Page 631
How Are Smart Pointers Implemented?......Page 632
Types of Smart Pointers......Page 633
Popular Smart Pointer Libraries......Page 641
Q&A......Page 642
Workshop......Page 643
LESSON 27: Using Streams for Input and Output......Page 644
Concept of Streams......Page 645
Important C++ Stream Classes and Objects......Page 646
Using std::cout for Writing Formatted Data to Console......Page 647
Using std::cin for Input......Page 651
Using std::fstream for File Handling......Page 655
Using std::stringstream for String Conversions......Page 661
Q&A......Page 663
Workshop......Page 664
LESSON 28: Exception Handling......Page 666
What Causes Exceptions?......Page 667
Implementing Exception Safety via try and catch......Page 668
How Exception Handling Works......Page 673
Summary......Page 678
Workshop......Page 679
LESSON 29: Going Forward......Page 682
What’s Different in Today’s Processors?......Page 683
How to Better Use Multiple Cores......Page 684
Writing Great C++ Code......Page 688
Learning C++ Doesn’t Stop Here!......Page 690
Q&A......Page 691
Workshop......Page 692
APPENDIX A: Working with Numbers: Binary and Hexadecimal......Page 694
Binary Numeral System......Page 695
Hexadecimal Numeral System......Page 697
Converting to a Different Base......Page 698
APPENDIX B: C++ Keywords......Page 700
APPENDIX C: Operator Precedence......Page 702
APPENDIX D: Answers......Page 704
APPENDIX E: ASCII Codes......Page 746
ASCII Table of Printable Characters......Page 747
A......Page 750
B......Page 751
C......Page 752
D......Page 755
F......Page 756
I......Page 757
L......Page 758
N......Page 759
P......Page 760
Q-R......Page 761
S......Page 762
T......Page 764
V......Page 765
X-Y-Z......Page 766