I am pleased to announce that my new book on modern C++ has been published at PacktPub. The book is called The Modern C++ Challenge and can be ordered at Packtpub and Amazon (the ISBN of the book is 9781788993869).
This book is intended as a companion book for people learning the C++ programming language. It proposes a series of 100 problems of various difficulties to help you practice your newly acquired skills, as you are learning C++. However, the book is not teaching you C++; instead, it challenges you to use C++ to solve real-world problems utilizing a variety of language and library features that you learned from other resources. These problems are grouped into 12 chapters, ranging from fun math problems to algorithms and data structures, from template programming to concurrency, from networking to design patterns and many others. Along the way, you will be working with many 3rd party libraries for data serialization, networking, cryptography, images, databases, and others. All these libraries are open source and cross-platform; their list includes Asio, Crypto++, Curl, Date, NLohmann/json, PDF-Writer, PNGWriter, SQLite, ZipLib. Complete solutions are provided in the book for all the problems; the entire code, together with CMake scripts, is available to download together with the book. Nevertheless, since most of the problems are not C++ specific, you can use the book as a reference for exercises when you’re learning other programming languages (although, in this case, you won’t be benefitting from the solutions here).
Here are some of the things that you will learn in the book:
- Serialize and deserialize JSON and XML data
- Perform encryption and signing to facilitate secure communication between parties
- Embed and use SQLite databases in your applications
- Use threads and asynchronous functions to implement generic purpose algorithms
- Compress and decompress files to/from a ZIP archive
- Implement data structures such as circular buffer and priority queue
- Implement general purpose algorithms as well as algorithms that solve specific problems
- Create client-server applications that communicate over TCP/IP
- Consume HTTP REST services
- Use design patterns to solve real-world problems
- Generate barcodes and Catcha-like codes PNG images
- Find the shortest path between two nodes in a network
- Implement quicksort recursively, iteratively, and in parallel
- Work with C++20 calendars and time zones
- Create and utilize type traits
- Work with regular expressions
- Create your own user-defined literals to convert temperature values between different scales
- Solve fun math problems
The solutions to the proposed problems have been developed and tested with Visual Studio 2017 v15.6/15.7 on Windows, and with Xcode 9.3 on Mac OS 10.13.x. Regardless the compiler you use, it has to support C++17. There are various C++17 features used throughout the book, such as std::string_view, std::optional, or the filesystem library. There are also several problems related to the C++20 extensions with calendars and time zones to the chrono library; for the time being, these could be solved with the date library. Your compiler might not support all these features. Visual C++ 15.7 is C++17 complete, but if you’re compiling for instance with Xcode, filesytem and std::optional are not available. However, you can simply replace them with the Boost.Filesystem and Boost.Optional libraries, based on which the standard libraries were developed. The code provided with the book can be compiled to work with either one or the other. Detailed instructions for generating projects from the sources using CMake scripts and building are available both in the preface to the book and in the source code. You can try many of the solutions in the book using an online compiler, such as those available at https://wandbox.org/.
Here is in more details how the book is structured, on chapters:
- Math Problems: contains a series of fun and interesting math problems to solve.
- Language Features: touches on operator overloading, move semantics, user-defined literals, variadic functions, fold expressions, type traits.
- Strings and Regular Expressions: includes exercises for string manipulation (converting between strings and other data types, splitting and joining strings) and regular expressions.
- Streams and Filesystems: output stream manipulation and working with files and directories using the C++17 filesystem library.
- Date and Time: calendar and time zones problems (for the upcoming C++20 chrono extensions).
- Algorithms and Data Structures: proposes several data structure that you have to design and implement (such as priority queue and circular buffer), as well as using standard and implementing user-defined general purpose algorithms. You also find here Dawkins’ Weasel program and Conway’s Game of Life program, where you can learn about evolutionary algorithms and cellular automata.
- Concurrency: general-purpose parallel algorithms to be implemented using threads and asynchronous functions, but also some real-world problems involving concurrency.
- Design Patterns: various problems to be solved with design patterns such as decorator, composite, chain of responsibility, template method, and others.
- Data Serialization: where you work with JSON and XML, but also with PDF files, using 3rd party open-source, and cross-platform libraries.
- Archives, Images, and Databases: contains problems for working with zip archives, creating PNG files for real-world problems (such as Captcha-like systems and barcodes) and utilizing SQLite databases in your applications.
- Cryptography: proposes various problems on data encryption and signing, but also challenges you to implement your own Base64 encoding and decoding utilities.
- Networking and Services: contains problems on client-server applications communicating on TCP/IP, and consuming various REST services (such as bitcoin exchange rates or text translation APIs).
I hope you will enjoy the reading and find it helpful for learning and mastering C++.