Mark As Completed Discussion

C++ is an imperative, language with a strong emphasis on performance and efficiency--qualities that certainly resonate with engineers. It is widely known for being a middle-level language, as it encapsulates both high-level and low-level language features.

Its background dates back to 1979 when it was created as an extension to the C language, defined as 'C with Classes'. It was later renamed to C++ in 1983. The ++ is a reference to the increment operator in C (and C++), implying that C++ is an incremental improvement of C.

Overview of C++ Programming

Developed by Bjarne Stroustrup at Bell Labs, C++ introduces features essential for the simulation of systems such as classes, inheritance, strong type checking, and more that are absent from C. Its development was driven by an ethos of 'trust the programmer', favoring programmer freedom and efficiency over rigid enforcement of safety, which leads to its popularity in performance-critical environments like game development and system software.

Overview of C++ Programming

Let's take a look at a simple football-related code snippet in C++. We'll be creating a variable player and assigning it a popular player's name—Cristiano Ronaldo.

CPP
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Try this exercise. Click the correct answer from the options.

What distinctive advancement did C++ add to the C language?

Click the option that best answers the question.

  • Enhanced compiler performance
  • Introduction of object-oriented features
  • Improvements in error handling
  • Implemented a built-in Garbage Collector

Installing a C++ compiler

As a senior engineer coming from a web development background, you are assuredly familiar with the importance of a good development environment. The good news is that setting up a C++ environment is simpler than erecting a daunting tech stack on the web development side.

C++ programs are typically compiled using g++ or clang, part of the GNU Compiler Collection (GCC) or the LLVM project, respectively. For Windows users, the MinGW-w64 project provides a suitable compiler. Let's go through a step-by-step guide on how to set up a C++ compiler.

  1. Windows:
  • Download MinGW-w64 from here. Follow the setup instructions, ensuring to add the compiler's bin directory to your PATH.
  • Verify by opening a command prompt and running g++ --version. You should see output indicating the installed version of g++.
  1. Linux:
  • Most Linux distributions include GCC by default. However, if not installed, use the package manager for your distribution to install GCC. For example, on Ubuntu, use sudo apt-get install build-essential.
  • Verify the installation by running g++ --version in a terminal.
  1. Mac:
  • Apple's macOS comes with the clang compiler by default which is sufficient. However, if you prefer g++, it can be installed using the Homebrew package manager with brew install gcc.
  • Verification is similar to the previous platforms by running g++ --version in a terminal.

With the compiler installed, we're ready to dive into creating a simple C++ program in the next module!

Are you sure you're getting this? Is this statement true or false?

The GCC compiler is not included by default in most Linux distributions.

Press true if you believe the statement is correct, or false otherwise.

Creating a Hello World program

After setting up your C++ development environment, let's dive straight into the basic syntax of C++ by creating, compiling, and running a simple 'Hello World' program. This initial step will provide you with a practical understanding of the workflow you'll use for all your C++ developments.

Creating a Hello World program

In many software languages like JavaScript or Python, you're used to writing a script and directly running the program. In contrast, with C++, we'll be compiling our script into runnable code.

Creating your first C++ program involves these steps:

  1. Writing the program: You first write your script (the 'Hello World' program we'll create) using a text editor or Integrated Development Environment (IDE).
  2. Compiling the program: You then use your C++ compiler (g++ or clang) to turn the script into a machine language file (also known as a binary file).
  3. Running the program: Finally, you execute the binary file from your terminal or command prompt.

A simple 'Hello World' program in C++ looks like this:

CPP
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Are you sure you're getting this? Fill in the missing part by typing it in.

In many software languages like Python, you're used to writing a script and directly running the program. In contrast, with C++, we'll be ____ our script into runnable code.

A simple 'Hello World' program in C++ looks like this:

TEXT/X-C++SRC
1#include <iostream>
2
3int main() {
4 std::cout << "Hello, World!";
5 return 0;
6}

Write the missing line below.