C++17 By Example
Practical projects to get you up and running with C++17
Stefan Bjrnander
BIRMINGHAM - MUMBAI
C++17 By Example
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Merint Mathew
Acquisition Editor: Chaitanya Nair
Content Development Editor: Lawrence Veigas
Technical Editor: Adhithya Haridas
Copy Editor: Safis Editing
Project Coordinator: Prajakta Naik
Proofreader: Safis Editing
Indexer: Aishwarya Gangawane
Graphics: Jisha Chirayil
Production Coordinator: Deepika Naik
First published: February 2018
Production reference: 1220218
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78839-181-8
www.packtpub.com
I dedicate this book to my parents, Ralf and Gunilla, my sister, Catharina, her husband, Magnus, and their sons, Emil and Rasmus.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Stefan Bjrnander is the author of the books Microsoft Windows C++ and C++ Windows Programming. He holds a Master of Engineering and a Licentiate in Computer Science. He has worked as a software developer and as a teacher in computer science and mathematics for many years.
About the reviewer
Mark Elston is a software architect for an automated test equipment company working primarily in the IC and mobile device test world. However, his 30 years of experience includes developing aircraft and missile simulations for the Air Force and Navy, hardware control systems for NASA, and tester operating systems for commercial products. He has also developed several Android applications for fun. His latest passion is delving into the world of functional programming and design.
I would like to thank my wife for her understanding when I had a chapter to finish reviewing. I would also like to thank the Pack team for giving me the opportunity to work with them on this project. It has been enlightening and entertaining. Finally, I would like to thank the author for taking even my smallest comments into account. It is a pleasure to be part of a project where your input is valued.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
C++ is a general-purpose programming language built with a bias towards embedded programming and systems programming. Over the years, C++ has evolved and is used to develop software for many different sectors. Given its versatility and robustness, C++ is a wonderful language to start your coding journey with. This book covers exciting projects built in C++ that show how to implement the language in different scenarios. While developing these projects, you will not only learn the language constructs but also how you can use C++ to meet your software requirements.
In this book, you will study a set of applications written in C++, ranging from abstract datatypes to library management systems, graphical applications, games, and a Domain-Specific Language (DSL).
Who this book is for
This book is for developers who would like to develop software in C++. Basic programming experience would be an added advantage.
What this book covers
, Getting Started with C++, introduces you to Object-Oriented Programming (OOP) in C++. We start by looking into a simple program that rolls a dice. We write the code, compile, link, and execute the program. We then continue by constructing a simple object-oriented hierarchy, with pointers and dynamic binding. Finally, we create two simple abstract data types: stack and queue. The stack is a set of values ordered in a bottom-to-top manner, where only the top-most value is accessible, while the queue is a traditional queue where we inspect values at the front and add values at the rear.
, Data Structures and Algorithms, builds on what was learned in the previous chapter, especially the list and set abstract datatypes. We also introduce templates and operator overloading, and we look into linear and binary search algorithms and the insert, select, bubble, merge, and quicksort algorithms.
, Building a Library Management System, will help you develop a real-world system: a library management system that is made up of books and customers. The books keep track of the customers that have borrowed and reserved them, and the customers keep track of the books they have borrowed and reserved.
, Library Management System with Pointers, further develops the library management system. In the previous chapter, each book and customer were identified by integer numbers. In this chapter, however, we work with pointers. Each book holds pointers to the customers that have borrowed or reserved it, and each customer holds pointers to the books they have borrowed or reserved.