Sams Teach Yourself C++ in One Hour a Day, 9th Edition

Book description

In just one hour a day, you will have all the skills you need to begin programming in C++. With this complete tutorial, you will quickly master the basics, and then move on to more advanced features and concepts. Completely updated for the latest C++ standard, this book presents the language from a practical point of view, helping you learn how to use C++ to create faster, simpler, and more efficient C++ applications.

Master the fundamentals of C++ and object-oriented programming

Understand how C++ features help you write compact and efficient code using concepts such as lambda expressions, move constructors, and assignment operators

Learn best practices and avoid pitfalls

Learn the Standard Template Library, including containers and algorithms used in most real-world C++ applications

Test your knowledge and expertise with exercises at the end of every lesson

Learn on your own time, at your own pace:

  • No previous programming experience required

  • Write fast and powerful C++ programs, compile the source code, and create executable files

  • Learn object-oriented programming concepts such as encapsulation, abstraction, inheritance, and polymorphism

  • Use algorithms and containers from the Standard Template Library to write feature-rich yet stable C++ applications

  • Learn how automatic type deduction helps simplify C++ code

  • Develop sophisticated programming techniques using lambda expressions, smart pointers, and move constructors

  • Master the features of C++ by learning from programming experts

  • Learn C++ features that allow you to program compact and high-performance C++ applications

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Contents at a Glance
  5. Table of Contents
  6. Introduction
    1. Who Should Read This Book?
    2. Organization of This Book
    3. Conventions Used in This Book
    4. Sample Code for This Book
  7. About the Author
  8. Acknowledgments
  9. We Want to Hear from You!
  10. Reader Services
  11. Part I: The Basics
    1. Lesson 1. Getting Started
      1. A Brief History of C++
      2. Programming a C++ Application
      3. What’s New in C++20?
      4. Summary
      5. Q&A
      6. Workshop
    2. Lesson 2. The Anatomy of a C++ Program
      1. Parts of the Hello World Program
      2. Preprocessor Directive #include
      3. The Body of Your Program: main()
      4. The Concept of Namespaces
      5. Comments in C++ Code
      6. Functions in C++
      7. Basic Input Using std::cin and Output Using std::cout
      8. Summary
      9. Q&A
      10. Workshop
    3. Lesson 3. Using Variables, Declaring Constants
      1. What Is a Variable?
      2. Common Compiler-Supported C++ Variable Types
      3. Determining the Size of a Variable by Using sizeof()
      4. Automatic Type Inference Using auto
      5. Using typedef to Substitute a Variable’s Type
      6. What Is a Constant?
      7. Keywords You Cannot Use as Variable or Constant Names
      8. Summary
      9. Q&A
      10. Workshop
    4. Lesson 4. Managing Arrays and Strings
      1. What Is an Array?
      2. Multidimensional Arrays
      3. Dynamic Arrays
      4. C-Style Character Strings
      5. C++ Strings: Using std::string
      6. Summary
      7. Q&A
      8. Workshop
    5. Lesson 5. Working with Expressions, Statements, and Operators
      1. Statements
      2. Compound Statements, or Blocks
      3. Using Operators
      4. Summary
      5. Q&A
      6. Workshop
    6. Lesson 6. Controlling Program Flow
      1. Conditional Execution Using if...else
      2. Getting Code to Execute in Loops
      3. Modifying Loop Behavior Using continue and break
      4. Programming Nested Loops
      5. Summary
      6. Q&A
      7. Workshop
    7. Lesson 7. Organizing Code with Functions
      1. The Need for Functions
      2. Using Functions to Work with Different Forms of Data
      3. How Function Calls Are Handled by the Microprocessor
      4. Summary
      5. Q&A
      6. Workshop
    8. Lesson 8. Pointers and References Explained
      1. What Is a Pointer?
      2. Dynamic Memory Allocation
      3. Common Programming Mistakes When Using Pointers
      4. Pointer Programming Best Practices
      5. What Is a Reference?
      6. Summary
      7. Q&A
      8. Workshop
  12. Part II: Fundamentals of Object-Oriented C++ Programming
    1. Lesson 9. Classes and Objects
      1. The Concept of Classes and Objects
      2. The Keywords public and private
      3. Constructors
      4. Destructor
      5. The Copy Constructor
      6. Different Uses of Constructors and the Destructor
      7. The this Pointer
      8. Using sizeof() with a Class
      9. The Keyword struct and Its Differences from class
      10. Declaring a friend of a class
      11. Union: A Special Data Storage Mechanism
      12. Using Aggregate Initialization on Classes and structs
      13. Summary
      14. Q&A
      15. Workshop
    2. Lesson 10. Implementing Inheritance
      1. Basics of Inheritance
      2. Private Inheritance
      3. Protected Inheritance
      4. The Problem of Slicing
      5. Multiple Inheritance
      6. Avoiding Inheritance Using final
      7. Summary
      8. Q&A
      9. Workshop
    3. Lesson 11. Polymorphism
      1. Basics of Polymorphism
      2. Using Virtual Inheritance to Solve the Diamond Problem
      3. Using the Specifier override to Indicate the Intention to Override
      4. Using final to Prevent Function Overriding
      5. Virtual Copy Constructors?
      6. Summary
      7. Q&A
      8. Workshop
    4. Lesson 12. Operator Types and Operator Overloading
      1. What Are Operators in C++?
      2. Unary Operators
      3. Binary Operators
      4. The Function Operator (())
      5. The Move Constructor and Move Assignment Operator for High-Performance Programming
      6. User-Defined Literals
      7. Operators That Cannot Be Overloaded
      8. Summary
      9. Q&A
      10. Workshop
    5. Lesson 13. Casting Operators
      1. The Need for Casting
      2. Why C-Style Casts Are Not Popular with Some C++ Programmers
      3. The C++ Casting Operators
      4. Problems with the C++ Casting Operators
      5. Summary
      6. Q&A
      7. Workshop
    6. Lesson 14. An Introduction to Macros and Templates
      1. The Preprocessor and the Compiler
      2. Using the Macro #define to Define Constants
      3. Using #define to Write Macro Functions
      4. An Introduction to Templates
      5. Summary
      6. Q&A
      7. Workshop
  13. Part III: Learning the Standard Template Library (STL)
    1. Lesson 15. An Introduction to the Standard Template Library
      1. STL Containers
      2. STL Iterators
      3. STL Algorithms
      4. Interaction Between Containers and Algorithms Using Iterators
      5. Choosing the Right Container
      6. STL String Classes
      7. Summary
      8. Q&A
      9. Workshop
    2. Lesson 16. The STL String Class
      1. The Need for String Manipulation Classes
      2. Working with the STL String Class
      3. Template-Based Implementation of an STL String
      4. operator “"s in std::string
      5. Using std::string_view (Amended in C++20)
      6. Summary
      7. Q&A
      8. Workshop
    3. Lesson 17. STL Dynamic Array Classes
      1. The Characteristics of std::vector
      2. Typical Vector Operations
      3. Understanding the Concepts of Size and Capacity
      4. The STL deque Class
      5. Summary
      6. Q&A
      7. Workshop
    4. Lesson 18. STL list and forward_list
      1. The Characteristics of std::list
      2. Basic list Operations
      3. Reversing and Sorting Elements in a List
      4. Summary
      5. Q&A
      6. Workshop
    5. Lesson 19. STL set and multiset
      1. An Introduction to STL Set Classes
      2. Basic STL set and multiset Operations
      3. Pros and Cons of Using STL set and multiset
      4. Summary
      5. Q&A
      6. Workshop
    6. Lesson 20. STL map and multimap
      1. An Introduction to STL Map Classes
      2. Basic std::map and std::multimap Operations
      3. Supplying a Custom Sort Predicate
      4. STL’s Hash Table–Based Key/Value Container
      5. Summary
      6. Q&A
      7. Workshop
  14. Part IV: Lambda Expressions and STL Algorithms
    1. Lesson 21. Understanding Function Objects
      1. Function Objects and Predicates
      2. Typical Applications of Function Objects
      3. Summary
      4. Q&A
      5. Workshop
    2. Lesson 22. Lambda Expressions
      1. What Is a Lambda Expression?
      2. How to Define a Lambda Expression
      3. A Lambda Expression for a Unary Function
      4. A Lambda Expression for a Unary Predicate
      5. A Lambda Expression with State via Capture Lists ([...])
      6. A Lambda Expression for a Binary Function
      7. A Lambda Expression for a Binary Predicate
      8. Summary
      9. Q&A
      10. Workshop
    3. Lesson 23. STL Algorithms
      1. What Are STL Algorithms?
      2. Classification of STL Algorithms
      3. Usage of STL Algorithms
      4. C++20 Constrained Algorithms
      5. Summary
      6. Q&A
      7. Workshop
    4. Lesson 24. Adaptive Containers: Stack and Queue
      1. The Behavioral Characteristics of Stacks and Queues
      2. Using the STL stack Class
      3. Using the STL queue Class
      4. Using the STL Priority Queue
      5. Summary
      6. Q&A
      7. Workshop
    5. Lesson 25. Working with Bit Flags Using the STL
      1. The bitset Class
      2. Using std::bitset and Its Members
      3. The vector<bool> Class
      4. Summary
      5. Q&A
      6. Workshop
  15. Part V: Advanced C++ Concepts
    1. Lesson 26. Understanding Smart Pointers
      1. What Are Smart Pointers?
      2. How Are Smart Pointers Implemented?
      3. Types of Smart Pointers
      4. Popular Smart Pointer Libraries
      5. Summary
      6. Q&A
      7. Workshop
    2. Lesson 27. Using Streams for Input and Output
      1. The Concept of Streams
      2. Important C++ Stream Classes and Objects
      3. Using std::cout for Writing Formatted Data to the Console
      4. Using std::cin for Input
      5. Using std::fstream for File Handling
      6. Using std::stringstream for String Conversions
      7. Summary
      8. Q&A
      9. Workshop
    3. Lesson 28. Exception Handling
      1. What Is an Exception?
      2. What Causes Exceptions?
      3. Implementing Exception Safety via try and catch
      4. Throwing Exceptions of a Type by Using throw
      5. How Exception Handling Works
      6. Class std::exception
      7. A Custom Exception Class Derived from std::exception
      8. Summary
      9. Q&A
      10. Workshop
    4. Lesson 29. C++20 Concepts, Ranges, Views, and Adaptors
      1. Concepts
      2. The Ranges Library, Views, and Adaptors
      3. Summary
      4. Q&A
      5. Workshop
    5. Lesson 30. C++20 Threads
      1. Multithreading
      2. Summary
      3. Q&A
      4. Workshop
    6. Lesson 31. C++20 Modules and C++23
      1. Modules
      2. C++23 Expected Features
      3. Learning C++ Doesn’t Stop Here!
      4. Summary
      5. Q&A
      6. Workshop
  16. Part VI: Appendixes
    1. Appendix A. Working with Numbers: Binary and Hexadecimal
      1. Decimal Numeral System
      2. Binary Numeral System
      3. Hexadecimal Numeral System
      4. Converting to a Different Base
    2. Appendix B. C++ Keywords
    3. Appendix C. Writing Great C++ Code
    4. Appendix D. ASCII Codes
      1. ASCII Table of Printable Characters
    5. Appendix E. Answers
      1. Answers for Lesson 1
      2. Answers for Lesson 2
      3. Answers for Lesson 3
      4. Answers for Lesson 4
      5. Answers for Lesson 5
      6. Answers for Lesson 6
      7. Answers for Lesson 7
      8. Answers for Lesson 8
      9. Answers for Lesson 9
      10. Answers for Lesson 10
      11. Answers for Lesson 11
      12. Answers for Lesson 12
      13. Answers for Lesson 13
      14. Answers for Lesson 14
      15. Answers for Lesson 15
      16. Answers for Lesson 16
      17. Answers for Lesson 17
      18. Answers for Lesson 18
      19. Answers for Lesson 19
      20. Answers for Lesson 20
      21. Answers for Lesson 21
      22. Answers for Lesson 22
      23. Answers for Lesson 23
      24. Answers for Lesson 24
      25. Answers for Lesson 25
      26. Answers for Lesson 26
      27. Answers for Lesson 27
      28. Answers for Lesson 28
      29. Answers for Lesson 29
      30. Answers for Lesson 30
      31. Answers for Lesson 31

Product information

  • Title: Sams Teach Yourself C++ in One Hour a Day, 9th Edition
  • Author(s): Siddhartha Rao
  • Release date: February 2022
  • Publisher(s): Sams
  • ISBN: 9780137334674