Friday 24 May 2024

Learn C++ by Example: chapters 1 and 2

I thought I'd share some details about my latest book "Learn C++ by Example".




You can buy it directly here: http://mng.bz/AdAQ - or just go look at the table of contents. You can also buy it from Amazon: https://amzn.to/4dMJ0aG

People were asking for samples/a sneak peak at some contents, so I have been sharing on social media but thought I'd collate these into some blog posts.

The first chapter is an overview of C++ and there's a video summary from Manning here: https://www.youtube.com/watch?v=sl-HCDP4tws 


The 2nd chapter puts some numbers in a vector, which lets us talk about containers more generally, remind ourselves about iterators and learn about ranges. We cover more besides:

1. Filling and using containers, with a focus on a
vector of numbers
2. Range-based for loops and auto
3. Using a container with standard algorithms
4. Using format to display output
5. Ranges, views, and lambdas

The driving example through the chapter is generating Pascal's triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
...

We display it, and thin of various properties to check, like symmetry, which is useful for testing.

Some questions for you:
  • How would you generate the first few rows of Pascal's triangle?
  • How would you store it?
  • What would you do to test your numbers?

No comments:

Post a Comment