C++17 By Example

Book description

Discover the impressive capabilities of C++ and learn the skills you need to implement it in real life

About This Book

  • Leverage the power of C++ language constructs to build effective software
  • Learn about file handling and pointers
  • Build visually appealing GUI by using the power of Qt5
  • Get a deeper understanding of how to program C++ for a specific purpose by implementing a Domain Specific Language

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 You Will Learn

  • Create object-oriented hierarchies and how to compile, link, and execute a simple program
  • Implement classes with linked lists, templates, inheritance, operator overloading, and exception handling
  • Efficient file handling and pointer structures
  • Dynamic allocation and deallocation along with marshmallowing
  • Qt features, including menus, toolbars, caret handling, and more
  • Implement a Domain Specific Language in C++

In Detail

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.

The book starts with a brief introduction to C++ language constructs where you will learn essential concepts that are required to understand the projects covered in the book. The first module will build a library management system that will teach you how to perform efficient file handling and use pointers in your software. To give you a taste of GUI programming, the next module will build graphical applications using Qt 5. You will then be introduced to game design in C++ and build two interesting games. The final module will teach you how C++ can be used to create a Domain Specific Language.

After reading this book, you will have mastered core programming concepts in C++, and how to implement them effectively.

Style and approach

Core concepts are covered with the help of examples that promote learning by coding.

Publisher resources

Download Example Code

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. C++17 By Example
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Getting Started with C++
    1. Rolling the dice
    2. Understanding classes – the Car class
      1. Extending the Car class
    3. A class hierarchy – the Person, Student, and Employee classes
    4. A simple data type – the stack
    5. A more advanced data type – the queue
    6. Summary
  8. Data Structures and Algorithms
    1. The List class
      1. The Cell class
      2. The Iterator class
      3. The List class
      4. Adding a list to an existing list
      5. Erasing a value from the list
    2. The Set class
      1. Union, intersection, and difference operations
    3. Basic searching and sorting
      1. The select sort algorithm
      2. The insert sort algorithm
      3. The bubble sort algorithm
    4. The extended List class
      1. The ReverseIterator class
    5. The extended Set class
      1. Union, intersection, and difference
    6. Advanced searching and sorting
      1. The merge sort algorithm
      2. The quick sort algorithm
    7. Summary
  9. Building a Library Management System
    1. The Book class
      1. Writing the book
      2. Reading the book
      3. Borrowing and reserving the book
      4. Displaying the book
    2. The Customer class
      1. Reading the customer from a file
      2. Writing the customer to a file
      3. Borrowing and reserving a book
      4. Displaying the customer
    3. The Library class
      1. Looking up books and customers
      2. Adding a book
      3. Deleting a book
      4. Listing the books
      5. Adding a customer
      6. Deleting a customer
      7. Listing the customers
      8. Borrowing a book
      9. Reserving a book
      10. Returning a Book
      11. Saving the library information to a file
      12. Loading the library information from a file
    4. The main function
    5. Summary
  10. Library Management System with Pointers
    1. The Book class
      1. Reading and writing the book
      2. Borrowing and reserving the book
      3. Displaying the book
    2. The Customer class
      1. Reading and writing the customer
      2. Borrowing and reserving a book
      3. Displaying the customer
    3. The Library class
      1. Looking up books and customers
      2. Adding a book
      3. Deleting a book
      4. Listing the books
      5. Adding a customer
      6. Deleting a customer
      7. Listing the customers
      8. Borrowing a book
      9. Reserving a book
      10. Returning a book
      11. Looking up books and customers
      12. Marshmallowing
      13. Saving the library information to a file
        1. Writing the book objects
        2. Writing the customer objects
        3. Writing the borrower index
        4. Writing the reservation indexes
        5. Writing the loan book indexes
        6. Writing the reservation book indexes
      14. Loading the library information from a file
        1. Reading the book objects
        2. Reading the customer objects
        3. Reading the borrower index
        4. Reading the reservation indexes
        5. Reading the loan book indexes
        6. Reading the reservation book indexes
      15. Deallocating memory
      16. The main function
    4. Summary
  11. Qt Graphical Applications
    1. Creating the clock application
      1. Setting up the environment
      2. The Clock class
      3. The main function
    2. Setting up reusable classes for windows and widgets
      1. Adding a listener
      2. The base window class
      3. The base widget class
    3. Building the drawing program
      1. The Figure base class
      2. The Line sub class
      3. The Rectangle sub class
      4. The Ellipse sub class
      5. Drawing the window
      6. Drawing the widget
      7. The main function
    4. Building an editor
      1. The Caret class
      2. Drawing the editor window
      3. Drawing the editor widget
      4. The main function
    5. Summary
  12. Enhancing the Qt Graphical Applications
    1. Improving the clock
      1. The Clock class
      2. The main function
    2. Improving the drawing program
      1. The Figure class
      2. The Line class
      3. The Rectangle class
      4. The Ellipse class
      5. The DrawingWindow class
      6. The DrawingWidget class
      7. The main function
    3. Improving the editor
      1. The EditorWindow class
      2. The EditorWidget class
      3. The main function
    4. Summary
  13. The Games
    1. Othello
      1. The game widget
        1. The OthelloWindow class
        2. The OthelloWidget class
        3. The main function
    2. Noughts and crosses
      1. The NaCWindow class
        1. The NaCWidget class
        2. The main function
    3. Summary
  14. The Computer Plays
    1. Othello
      1. The OthelloWindow class
        1. The OthelloWidget Class
        2. The main function
    2. Noughts and Crosses
      1. The NaCWindow class
        1. The NaCWidget class
        2. The main function
    3. Summary
  15. Domain-Specific Language
    1. Introducing the source language – a simple example
      1. The grammar of the source language
      2. The target language
      3. The colors
      4. Error handling
      5. The value
    2. The scanner
    3. Building the parser
      1. Parsing the instructions of the language
      2. Parsing the expressions of the language
      3. Type checking the expression
      4. Evaluating the values of the expressions
    4. The viewer
    5. The main function
    6. Summary
  16. Advanced Domain-Specific Language
    1. Improving the source language – an example
    2. Improving the grammar
    3. The Token and the Scanner
    4. The parser
    5. The evaluator
    6. The main function
    7. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: C++17 By Example
  • Author(s): Stefan Bjornander
  • Release date: February 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788391818