The C++ Workshop
eBook - ePub

The C++ Workshop

A New, Interactive Approach to Learning C++

Dale Green, Kurt Guntheroth, Shaun Ross Mitchell

  1. 606 p√°ginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

The C++ Workshop

A New, Interactive Approach to Learning C++

Dale Green, Kurt Guntheroth, Shaun Ross Mitchell

Detalles del libro
Vista previa del libro
√ćndice
Citas

Información del libro

Learn to create high-performance, error-free programs by understanding the core principles and techniques behind programming in C++

Key Features

  • Gain a solid understanding of the syntax and anatomy of C++
  • Implement best practices when building high-performance C++ programs
  • Prepare for real-world development tasks by tackling engaging activities

Book Description

C++ is the backbone of many games, GUI-based applications, and operating systems. Learning C++ effectively is more than a matter of simply reading through theory, as the real challenge is understanding the fundamentals in depth and being able to use them in the real world. If you're looking to learn C++ programming efficiently, this Workshop is a comprehensive guide that covers all the core features of C++ and how to apply them. It will help you take the next big step toward writing efficient, reliable C++ programs.

The C++ Workshop begins by explaining the basic structure of a C++ application, showing you how to write and run your first program to understand data types, operators, variables and the flow of control structures. You'll also see how to make smarter decisions when it comes to using storage space by declaring dynamic variables during program runtime.

Moving ahead, you'll use object-oriented programming (OOP) techniques such as inheritance, polymorphism, and class hierarchies to make your code structure organized and efficient. Finally, you'll use the C++ standard library?s built-in functions and templates to speed up different programming tasks.

By the end of this C++ book, you will have the knowledge and skills to confidently tackle your own ambitious projects and advance your career as a C++ developer.

What you will learn

  • Understand how a C++ program is written, executed, and compiled
  • Efficiently work with the essential C++ data types and variables
  • Build your own C++ applications by writing clear and error-free code
  • Grasp the core principles behind object-oriented programming
  • Simplify your code by using templates and the standard library
  • Debug logical errors and handle exceptions in your program

Who this book is for

This Workshop is for anyone who is new to C++ who wants to build a strong foundation for C++ game programming or application development. Basic prior knowledge of data structures and OOP concepts, as well as experience in any other programming language, will help you grasp the concepts covered in this book more easily.

Preguntas frecuentes

¬ŅC√≥mo cancelo mi suscripci√≥n?
Simplemente, dir√≠gete a la secci√≥n ajustes de la cuenta y haz clic en ¬ęCancelar suscripci√≥n¬Ľ. As√≠ de sencillo. Despu√©s de cancelar tu suscripci√≥n, esta permanecer√° activa el tiempo restante que hayas pagado. Obt√©n m√°s informaci√≥n aqu√≠.
¬ŅC√≥mo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¬ŅEn qu√© se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las √ļnicas diferencias son el precio y el per√≠odo de suscripci√≥n: con el plan anual ahorrar√°s en torno a un 30¬†% en comparaci√≥n con 12 meses de un plan mensual.
¬ŅQu√© es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¬ŅPerlego ofrece la funci√≥n de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¬ŅEs The C++ Workshop un PDF/ePUB en l√≠nea?
Sí, puedes acceder a The C++ Workshop de Dale Green, Kurt Guntheroth, Shaun Ross Mitchell en formato PDF o ePUB, así como a otros libros populares de Computer Science y Open Source Programming. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

A√Īo
2020
ISBN
9781838988364
Edición
1
Categoría
Computer Science

1. Your First C++ Application

Overview
This chapter equips you with the fundamental tools and techniques required to get started building basic C++ applications. We'll start by breaking a C++ application into its core components, identifying each by their role(s). We'll then take a look at the core language that defines C++, including pre-processor directives‚ÄĒstatements that let us perform actions before our code is compiled. Finally, we'll look at how we get information in and out of our applications (I/O) before putting this all together in a final exercise in which you will write and run your own C++ application in an online compiler.

Introduction

As the world becomes smarter, so do our devices. Everything from watches to our refrigerators now have the capacity to run code, a large portion of which is C++. Between 1972 and 1973 Dennis Richie authored the C programming language while working at Bell Labs. While great for efficiency, thanks to features such as low-level memory access, C is a procedural language and so does not provide object-orientated features. In response to this, Bjarne Stroustup, also while working at Bell Labs, began working on "C with classes" in 1979. In 1983, the language was renamed C++, and it saw its first commercial release two years later in 1985. Since then, it has gone through many standardizations, the last in December 2017, and continues to be governed by the International Organization for Standardization.
Utilized in everything from operating systems to cutting-edge 3D game engines, C++ is the backbone of countless systems and industries, not least because of its high-performance capabilities, flexibility, and portability. C++ puts you close to the hardware, so it is often the tool of choice for performance-critical applications.
The goal of this course is to demystify the C++ programming language, and to get you writing quality code as quickly as possible through a very pragmatic approach. While theory is certainly required, and will be covered where necessary, we'll mainly be focusing on practical application‚ÄĒlearning by tackling real-world exercises and activities.
To start our journey, we looked at a brief history of the language. While this alone won't make you a better programmer, it's always good to have context for what we're doing and why. By learning the origins of the language and how it's used in industry, we will set ourselves up with an informed starting point for the journey ahead.
We're then going to jump right into dissecting a basic C++ application. By breaking an application down into its constituent parts, we can gain an understanding of the main pieces that it comprises. We'll then expand on this basic understanding by looking at each part in more detail throughout the rest of this introductory chapter.
When we've concluded this chapter, we'll not only have an understanding of the origin of the language; we'll also be familiar with the different core parts of an application. We'll be able to look at an example C++ application with a sense of meaning and understanding. We'll then use this basic understanding to springboard into the next chapter, where we'll look deeper into the language at specific features and functionality.

Advantages of C++

Before we dive into the structure of a C++ program, let's have a look at a few key benefits of the language:
  • Performance: By putting the programmer close to the hardware, C++ allows us to write very efficient programs. Along with low-level memory access, the abstraction between code and what the machine will do is smaller than in most other languages, meaning you can manipulate the system better.
  • Portability: C++ can be cross-compiled to a wide array of platforms, and runs on everything from watches to televisions. If you're writing an application or library for more than one platform, C++ shines.
  • General purpose: C++ is a general-purpose programming language, and is used in everything from video games to enterprise. With a rich feature set spanning everything from direct memory management to classes and other Object-Oriented Programming (OOP) principles, you can make C++ work for you.
  • Large libraries: Since the language is used in so many applications, there's an abundance of libraries to choose from. With hundreds of open source repositories, the wealth of information (and the support systems that come with it) is vast.
C++ is a double-edged sword, however, and as the famous saying goes, "With great power comes great responsibility". C++ gives you enough room to do great things, but also to get yourself into trouble if used incorrectly. Bjarne himself once said of the language, "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." That's not to say by any means that C++ should be avoided, just that it should be used deliberately and with consideration‚ÄĒsomething the following chapter will impart.

Anatomy of a C++ Application

With a brief understanding of the history of the language, we're going to start our journey by delving into a basic C++ program to see what we're working with. There's no more fitting a start than Hello World!. This famous program prints the words Hello World! to the console, and has served as the starting point for scores of programmers before you. While basic, it contains all the key components of a C++ application, so will prove a great example for us to de-construct and learn from.
Let's start by taking a look at the program in its entirety:
// Hello world example.
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}
Consisting of just seven lines of code, this small program contains everything we need to look at the basic anatomy of a C++ program. We're going to cover each aspect of this program in more detail over the coming chapters, so don't worry if not everything makes perfect sense as we break this program down. The aim here is simply to familiarize ourselves with some core concepts before covering them in more detail as we progress.
Starting from the top, we have a preprocessor directive:
#include <iostream>
Preprocessor directives are statements that allow us to perform certain operations before the program is built. The include directive is a very common directive that you'll see in most C++ files, and it means "copy here." So, in this case, we're going to copy the contents of the iostream header file into our application, and in doing so, allow ourselves to use input/output functionality it provides.
Next, we have our entry point, main():
int main()
The main() function is where your C++ application will kick-off. All applications will have this function ...

√ćndice

  1. Preface
  2. 1. Your First C++ Application
  3. 2. Control Flow
  4. 3. Built-In Data Types
  5. 4. Operators
  6. 5. Pointers and References
  7. 6. Dynamic Variables
  8. 7. Ownership and Lifetime of Dynamic Variables
  9. 8. Classes and Structs
  10. 9. Object-Oriented Principles
  11. 10. Advanced Object-Oriented Principles
  12. 11. Templates
  13. 12. Containers and Iterators
  14. 13. Exception Handling in C++
  15. Appendix
Estilos de citas para The C++ Workshop

APA 6 Citation

Green, D., Guntheroth, K., & Mitchell, S. R. (2020). The C++  Workshop (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/1365854/the-c-workshop-a-new-interactive-approach-to-learning-c-pdf (Original work published 2020)

Chicago Citation

Green, Dale, Kurt Guntheroth, and Shaun Ross Mitchell. (2020) 2020. The C++  Workshop. 1st ed. Packt Publishing. https://www.perlego.com/book/1365854/the-c-workshop-a-new-interactive-approach-to-learning-c-pdf.

Harvard Citation

Green, D., Guntheroth, K. and Mitchell, S. R. (2020) The C++  Workshop. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/1365854/the-c-workshop-a-new-interactive-approach-to-learning-c-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Green, Dale, Kurt Guntheroth, and Shaun Ross Mitchell. The C++  Workshop. 1st ed. Packt Publishing, 2020. Web. 14 Oct. 2022.