Learn C++ by Example: Covers Versions 11 to 23 (Final Release)

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"

Build your skills with essential modern C++ features hands-on by completing eight interesting coding projects. In C++ Bookcamp you’ll: Learn how to write modern C++ using new features from C++ 11 to 20 Think about testing as you code Learn what happens “under the hood” of your C++ code Choose the most efficient algorithm or data structure C++ Bookcamp introduces you to the most important features of modern C++ coding by guiding you through eight hands-on projects. The book carefully coaches you through all the major language changes since C++ 11. Each new feature you learn comes with a fun project or minigame, from writing a Guess The Number game to racing your way out of a paper bag. It’s a great way to build effective skills, whether you’re a C++ beginner or you’re just upgrading to the newer versions of the language. About the technology C++ is used for everything from financial modeling to video games. C++ 11, 17, and 20 have all introduced exciting features that can increase your coding efficiency. This book introduces these features by putting them to use in real projects. Along the way, you’ll get up to speed with frequently used data structures, algorithms, and various parts of the standard library. About the book C++ Bookcamp develops your skills with modern C++ through small projects and games. You’ll put each new feature into action by building something fun. Learn about vectors and ranges by generating Pascal’s triangle, use the C++ random library to write a Number Guess game, create a countdown timer with the chrono library, and much much more! The Bookcamp won’t keep you waiting around with unnecessary details of dozens of new standards. You’ll go at a rapid pace throughout, discovering the helpful resources you need to be a best-in-class C++ programmer. About the reader For readers who know the basics of C++, whether they’re beginners or out-of-practice veterans. About the author Frances Buontempo has many years of C++ experience. She has given talks on C++ and is an editor of ACCU’s Overload magazine.

Author(s): Buontempo, Frances
Publisher: Manning Publications Co.
Year: 2024

Language: English
Pages: 248

inside front cover
Learn C++ by Example
Copyright
dedication
contents
Front matter
foreword
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A road map
About the code
liveBook discussion forum
Other resources
about the author
about the cover illustration
1 Hello again, C++!
1.1 Why does C++ matter?
1.2 When should you use C++?
1.3 Why read this book?
1.4 How does this book teach C++?
1.4.1 Who this book is for
1.4.2 Hello, again, C++!
1.4.3 What you’ll learn from reading this book
1.5 Some pro tips
Summary
2 Containers, iterators, and ranges
2.1 Creating and displaying a vector
2.2 Creating and displaying Pascal’s triangle
2.2.1 A reminder of Pascal’s triangle
2.2.2 Coding Pascal’s triangle
2.2.3 Move semantics and perfect forwarding
2.2.4 Using ranges to display the vector
2.2.5 Using format to display output
2.3 Properties of the triangle
2.3.1 Checking the first and last elements of each row
2.3.2 Checking the number of elements in each row
2.3.3 Checking the sum of the elements in a row
2.3.4 How many rows can we generate correctly?
2.3.5 Checking whether each row is symmetric
2.3.6 Highlighting odd numbers in a row
Summary
3 Input of strings and numbers
3.1 Guessing a predetermined number
3.1.1 Accepting user input the hard way
3.1.2 Accepting optional numeric input
3.1.3 Validation and feedback using std::function and lambdas
3.2 Guessing a random number
3.2.1 Setting up a random number generator
3.2.2 Using the random number generator
3.3 Guessing a prime number
3.3.1 Checking whether the number is prime
3.3.2 Checking properties with static_assert
3.3.3 Generating a random prime number
3.3.4 Deciding which digits are correct
3.3.5 Providing different clues using std::function
Summary
4 Time points, duration, and literals
4.1 How long until the last day of the year?
4.2 Understanding durations in detail
4.2.1 Ratios
4.2.2 Durations
4.2.3 Literal suffixes and operator / for readable code
4.2.4 Requirements and concepts
4.2.5 How many days until the last day of the year?
4.2.6 Using last to find how long to payday
4.2.7 Writing testable code
4.3 Input, output, and formatting
4.3.1 Parsing a date
4.3.2 Formatting time points and durations
4.4 Time zones
Summary
5 Creating and using objects and arrays
5.1 Creating a deck of playing cards
5.1.1 Defining a card type using a scoped enum for the suit
5.1.2 Defining a card type using a strong type for the face value
5.1.3 Constructors and default values
5.1.4 Displaying playing cards
5.1.5 Using an array to make a deck of cards
5.1.6 Using generate to fill the array
5.1.7 Comparison operators and defaults
5.2 Higher-or-lower card game
5.2.1 Shuffling the deck
5.2.2 Building the game
5.2.3 Using std::variant to support cards or jokers
5.2.4 Building the game with an extended deck of cards
Summary
6 Smart pointers and polymorphism
6.1 A class hierarchy
6.1.1 An abstract base class
6.1.2 A concrete class
6.1.3 Warming up for a race
6.1.4 Using type traits to check for special member functions
6.2 Writing and using derived classes in a vector
6.2.1 A blob moving randomly
6.2.2 Smart pointers
6.2.3 Race!
6.2.4 Some design considerations
Summary
7 Associative containers and files
7.1 Hardcoded answer smash
7.1.1 Creating and using an std::map
7.1.2 Pairs, tuples, and structured bindings
7.1.3 A simple answer smash game
7.2 Associative containers
7.2.1 The map type in more detail
7.2.2 Using lower and upper bound to find a key more efficiently
7.2.3 Multimaps
7.3 File-based answer smash
7.3.1 Loading data from a file
7.3.2 Picking a word randomly using std::sample
7.3.3 Answer smash
Summary
8 Unordered maps and coroutines
8.1 Randomly generated matching pennies
8.2 Matching pennies using an unordered_map
8.2.1 Unordered containers and std::hash
8.2.2 Using an unordered_map to make a prediction
8.2.3 The mind reader game
8.3 Coroutines
8.3.1 How to make a coroutine
8.3.2 A coroutine function
8.3.3 The coroutine’s return object
8.3.4 RAII and the rule of zero
8.3.5 Filling in the promise_type
8.3.6 Filling in the Task type
8.3.7 A coroutine mind reader
Summary
9 Parameter packs and std::visit
9.1 The triangle numbers
9.1.1 Testing our triangle numbers with algorithms
9.1.2 Execution policies for algorithms
9.1.3 Mutable lambdas
9.1.4 More properties of the triangle numbers
9.2 A simple slot machine
9.2.1 Revision of constexpr and std::format
9.2.2 Using std::rotate to spin the reels
9.2.3 The simple slot machine
9.3 A better slot machine
9.3.1 Parameter packs and fold expressions
9.3.2 Using a parameter pack to find frequencies
9.3.3 A fairer payout
9.3.4 Allowing holds, nudges, or spins
9.3.5 Spinning reels with std::visit and std::views::zip
Summary
appendix. Further resources
index