Practical C++: Learn C++ Basics Step by Step | Edouard Renard | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Practical C++: Learn C++ Basics Step by Step

teacher avatar Edouard Renard, Software Engineer and Entrepreneur

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

50 Lessons (4h 50m)
    • 1. Welcome!

      2:39
    • 2. How to follow this course

      1:22
    • 3. Install VS Code on Windows/Linux/MacOS

      12:04
    • 4. Configure VS Code

      5:04
    • 5. Create a C++ project for the course

      2:00
    • 6. C++ Basics - Level 1

      1:16
    • 7. Your First C++ Program

      10:23
    • 8. Variables

      9:52
    • 9. Variables - Data Types

      4:57
    • 10. Variables - Constants

      3:48
    • 11. Arrays

      6:58
    • 12. Arrays with std::vector

      6:27
    • 13. Get User Input

      4:51
    • 14. C++ Level 1: Exercises

      2:32
    • 15. C++ Level 1: Exercises - Solution

      11:36
    • 16. C++ Basics - Level 2

      1:34
    • 17. Functions

      5:33
    • 18. Functions - Parameters

      4:18
    • 19. Functions - Return Statement

      5:59
    • 20. Variable Scope

      6:24
    • 21. Comments

      3:19
    • 22. Using namespace std

      5:46
    • 23. C++ Level 2: Exercises

      2:09
    • 24. C++ Level 2: Exercises - Solution

      11:44
    • 25. C++ Basics - Level 3

      1:18
    • 26. Conditional Statements with Booleans

      5:50
    • 27. Combining Conditional Statements

      3:38
    • 28. Conditions with If

      5:31
    • 29. Else, else if

      5:54
    • 30. For Loop

      6:53
    • 31. While Loop

      6:36
    • 32. Loops and Arrays

      6:12
    • 33. C++ Level 3: Exercises

      2:06
    • 34. C++ Level 3: Exercises - Solution

      13:36
    • 35. C++ Basics - Level 4

      1:17
    • 36. Functions - Pass Parameters by Copy or by Reference?

      10:40
    • 37. Functions - Prototypes

      4:56
    • 38. Organize your Code (.hpp and .cpp files)

      7:53
    • 39. Compile and Run a C++ Program in the Terminal

      6:22
    • 40. C++ Level 4: Exercises

      2:48
    • 41. C++ Level 4: Exercises - Solution

      18:37
    • 42. Extra: C++ OOP

      1:11
    • 43. What is OOP, What are Classes?

      2:54
    • 44. Create a C++ Class - Attributes, Constructor

      8:40
    • 45. Add Methods to the Class

      4:28
    • 46. Create an Object (Instance) from your Class

      7:11
    • 47. Organize your C++ OOP Code

      7:47
    • 48. Intro to Inheritance

      10:05
    • 49. Best Practices when Writing C++ Code

      3:29
    • 50. What to do next

      1:09
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

50

Students

--

Projects

About This Class

You are new to programming and you want to learn C++ Basics fast?

Or… You’re already a C++ developer and want a quick and to-the-point refresher of the basics?

And, you prefer to learn by doing? → This C++ class is for you.

No prerequisite needed for this class: just a computer and a strong will to learn.

→ Why this class?

C++ is a quite particular language: it’s one of the oldest one in the market (many other languages are in fact based on C++), and it’s used in every possible industry in the world.

C++ is considered as “hard to learn”. Well, it’s maybe harder to learn than other languages such as Python or JavaScript, but in return, you get some huge advantages: you can code with one of the most powerful languages in the world - which opens many possibilities that are not available with other “less powerful” languages. Also, and this can be an important factor for you: if you’re looking for a job, having C++ knowledge will help you stand out, and maybe get a better salary. The reasoning here is quite simple: as C++ is harder, you have less competition, and companies are willing to pay more.

And now, “harder” doesn’t mean “impossible”, if you have the right resources to start with.

I’ve created this class with one thing in mind: to give you, as fast as possible, the knowledge and practice you really need to master C++ basics. No more, no less. 

And I’ve made the explanations as simple and easy as possible so you can get started and get motivated to learn more about C++.

This is not a complete 50h class where you learn everything about everything. No, this class is about going to the point and getting the basics.

With this practical C++ class you will get what you really need to start. Then you will be able to efficiently use this C++ foundation to learn and work in many different fields:

  • Video games
  • Embedded software
  • Robotics (my favorite!)
  • Artificial intelligence
  • Operating systems
  • And many more.

→  How do I teach

  • Step by step: each section, each lesson, is built on top of the previous one. 1 lesson = 1 small step towards your mastery of C++ Basics.
  • Hands-on: no complicated theoretical explanations, I directly write the code and explain at the same time. And I encourage you to write the code too!
  • No copy and paste: I won’t make some code magically appear on the screen without any explanation. I write all the code that I explain, and explain all the code that I write.
  • To the point: if I can explain something in 5 minutes, I don’t produce a 15 minutes video to make the class look longer.
  • Practical: I teach you what you really need in order to do useful things with C++. This means focusing on what can give you the greatest value now.
  • Additional Practice: with each key concept you get some exercises to practice on exactly what you need to understand, so the learning is much more efficient.

So, if you like to learn by doing, and want to really understand what you do, you will love this class.

→ What will you do and learn in this class?

First, you will install the development tools (compiler, VS Code) you need to comfortably write C++ code - installation instructions for Windows, Linux, and MacOS. Yes, you can follow the class with any operating system you want!

Then you will learn C++ with 4 different levels.

For each level you get:

  • A quick introduction video to make the relation between different levels and explain what we are going to do.
  • Hands-on lessons (5-10 minutes long) to introduce new key concepts.
  • At the end of the level (section), some exercises to practice on the key points of the section, and also combine the concepts together.

Each level builds directly on top of the previous levels. Here’s a quick overview of the concepts you will discover (and practice on):

  • Level 1: Write a program, variables, arrays, vectors, user input.
  • Level 2: Functions, scope, comments, namespaces.
  • Level 3: Conditions (if), for loops, while loops.
  • Level 4: References, prototypes, compilation from the terminal.

Extra: you also get a bonus section at the end of the class, on C++ OOP (Object Oriented Programming). OOP is everywhere nowadays, and this is a nice addition to add to your skill set.

See you in the class! :)

-----------------------------------

This class is for:

  • Programming beginners who want to start learning C++ with a comprehensive and to-the-point class.
  • Programming beginners who learnt another language before and want to switch to C++.
  • C++ developers who want to refresh their basics without wasting time.
  • Anyone interested in working on video games, embedded software, robotics, artificial intelligence, operating systems, etc.

Meet Your Teacher

Teacher Profile Image

Edouard Renard

Software Engineer and Entrepreneur

Teacher

Hi, I'm Edouard. I’m a software engineer and entrepreneur.

I’ve been working on programming robots for years. When I first started I really had a lot of trouble trying to properly learn. I found what works and what doesn’t work, what I needed, and what I didn’t need. So now I’m sharing that with you, so you can save the precious time you have.

Also I have co founded a robotics startup and programmed an entire robotic arm from scratch, with ROS, Raspberry Pi and Arduino. My view on software and robotics is very practical: I’m interested in how to best use a language/framework to build useful applications. 

And thus the approach I have in my online courses is really down to earth and practical.

I like to make complex stu... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Welcome!: Welcome to this practical and hands-on. C plus plus goes first. Why should you learn C plus plus? Well, we've C plus plus. You get the opportunity to work in many different fields. Video games. And BUT IT software, robotics, artificial intelligence, operating systems, and many more. Cplusplus is maybe a little bit more difficult to learn than other languages, such as Python or JavaScript. But the reward is huge. You get to program with one of the most powerful languages. And you also get much into this to find a higher-paid job. All the top tech companies are hiring C plus plus developers. If you know cplusplus, you are going to stand out. And if they hire you for a similar position, you will usually get a better salary. And now whether you have never used C plus plus before and want to learn the basics fast in an easy way are if you're already a cplusplus developer and water quick refresher. Well, this course is what you need. My teaching method focuses on learning by doing and going to the point. I will show you exactly what you need to learn in a practical way, step by step. You will start by installing the tools to program with civil space on your computer, for Windows, Linux, and macOS. Then you will learn similar stress through four different levels that are built on top of each other so you can easily make progress. Everything is covered for each level. You will learn with me through hands-on listens only in practice on the key concepts with additional exercises. I have also included an extra bonus section on object oriented programming with C plus plus. Now of course, I don't claim to teach you everything there is to know what C plus plus. Instead, I've chosen to make the course as short as possible and focus on the main concepts you are already going to need first. So at the end of the course, you will master the C plus plus basics. You will be able to use the strong foundation to start learning and working on any other kind of project. And now just a few words about me. My name is Ed. Well, I'm a software engineer, an entrepreneur. I have a similar space to build many different things. For example, a few years ago, I co-founded a robotic start-up. And thanks to civil hospice, I could write a powerful and complex software for a robotic arm, which was running on an embedded computer with very limited resources. Today, I am focusing on sharing my knowledge in the easiest possible way for anyone to understand. All right, so if you want to learn siblings passed fast by directly going to the point, wait no more, and let's get started. 2. How to follow this course: Here is how I suggest you to follow the cool so you can get the most out of it and be able to program with siblings plus on your owl. So the course is divided into four levels plus 1 bonus section on object oriented programming. For each simplest plus level, you get a set of hands-on listens and then some exercises to practice on what you have just seen. And to get the most out of the first four siblings plus levels for each level, do the following. First, watch the complete section without stopping until you reach the exercises. And then come back to the beginning of this section and re-watch the lessons one by one using the pose and the rewind buttons so you can better understand. And after that, do the exercises. Make sure to take enough time to walk by yourself before you watch the solution. And some general tips for the whole cuz watch in the order. Don't skip any lesson because each lesson is built on top of what you have just seen before. And finally, don't hesitate to experiment on your own outside of the scope of this course. The more curious you are, the more you practice, the faster you will progress. Alright, now enough talking and let's install what we need to write, compile and run C plus plus code. 3. Install VS Code on Windows/Linux/MacOS: The first thing we need is to have a tool to be able to write C plus plus code. So you could totally open any text editor you want and start writing any code. However, that's not going to be very practical. Here we will install an IDE, which means integrated development environment. Very basic IPO'd. This software will allow you to write code, use features that jazz auto-completion, compile your code, run your programs, organize your projects, etc, etc. And there are many different ideas. The one I have chosen here is Visual Studio Code are also named VS Code. This is an open-source and multi-platform ID. So you can use it for free on Windows, Linux, and macOS. The interface is quite nice to begin with, and this software is actually used by many developers all over the world. So what I advise you to do is to follow the course using Visual Studio Code. So you have the exact same setup as me. And then of course, as you progress more and work on different projects, feel free to test other development tools and choose the one you prefer. So let's start the installation. I will provide the instructions for Windows, Linux, and macOS. And here you can see on the screen the time for each installation. And so this video is for the installation specific to each operating system. And in the next video we will configure the ID. And let's start with windows. So you can just go on Google and type Visual Studio Code. Again, you will get to that page here, code dot Visual Studio.com. And you should be able to directly download here Visual Studio Code for Windows. You don't have windows here, you just click here you choose Windows and stable. Okay, so I'm just going to download that. And it's going to open a new page. And you can just save the file and wait until it's downloading. Okay? And once you have the executable here, you can just click to execute. Okay, you have to accept new agreement. Next. You can click on Next, okay? Next, you can keep the options here with add to path next, and then install a new just wait until the software is installed. Okay, and that's it for the installation. So very quick and easy. I'm just not going to launch Visual Studio Code now. I'm going to click on finish painting. I'm going to go to this tab. Okay? And the thing is that if you want to run the simplest code on Windows, you need to install a compiler, because when you have C plus plus code, you can just execute that code. You will need a tool which is called the compiler. It is going to take this code and transform it into an executable binary stuff in. Well, you don't need to know all the details about that for now, but it's going to create an executable. And then you can run that executable to run your program. And so if you want to check if you already have a compiler for C plus plus, just go here and type CMD or terminal. You can just open a command prompt, as you can see here on Windows. And you do g plus plus and then space dash, dash version. You press Enter and you can see here I have g plus. Plus is not recognized as an internal or external comment. Which means simply that g plus plus, which is going to be the compiler for C plus plus, is not installed. So we can't compile, we can write C plus plus code, but we can't compile the code. So I am going to install a compiler for Windows. And for that you can just type here VS code run cyberspace and you will get here documentation. That is very helpful on the Visual Studio documentation page. So we're going to ignore that for now, and we're just going to install a compiler. And the compiler we're going to use w X 64. So we have here, you can click on that link, okay? So just search for that page and then go on that link. And then you have to wait, okay, five seconds here on sourceforge.net. So you are going to wait and save the file. So I don't give you exact links because any day they might change the URL for the documentation, for the installer. So if you just follow the steps idea, you are going to find the compiler every time and now where you can just click here to install it. So if you have a pop-up, you click on Yes. And then. You have the installer, click on next version. You can choose whatever is the latest. For the architecture, you're going to choose x 86, 64, okay, make sure to choose that one. And then the rest is okay Next. Okay, this, so you're going to keep that, but this is important. Make sure to know where is it because you are going to need to check that just later. So it should be in program files or something similar. And then Ming, etcetera. Click on Next, going to install it. So that can take a few minutes. Okay, and once it down, you just click on Next and Finish. So the compiler is installed, but you need to do another step in order to complete the installation. And this is you need to add the compiler to your path. So what you can do is simply search here. So you just search on the Windows search, edit environment variables or can you just type that editing environment variables? And you just click here. And you will get to that window. And you're going to find here you will find a variable named bath on the top part of the window. So you choose path, you click on Edit. This is going to open a new window. And you have different path here. And you're going to click on New, going to add a new one. And here, what are you going to bet? Well, from the documentation you can see this is going to be that one. So this is the path to the compiler, and as you can see here, this is a program files, w, et cetera. So that's what we had when we installed the compiler. If you had something else, you would need to find yourself what is the path? Okay? So for example, you can go Here, program phi's, and then meaning where is it here, okay? And then that one, you are going to find this folder. And then the bin folder. And you can just click here on the windows bar, and that should be here. That should be the bath. So you can just copy that path, okay, on the bin folder and copy that path and put it in this new line here. Okay? So make sure you end with mean GW 64 slash backslash b. You click. Okay. No, well, you can see you have a new line here. So okay. Okay. And that should be it. Now if you go back to the terminal with cmd and you do g plus plus ration. You will see g plus plus. So this is a recognized and is going to give you the version you have. So whatever version, it doesn't really matter here. And finally, so the installation is complete. You can just start Visual Studio code by typing Visual Studio Code here. Choose the app. And you can start Visual Studio Code. And in the next video we're going to configure the IDE. And now here are the instructions for how to install Visual Studio code on Linux. And as you will see, it's much easier than on Windows. So the first thing is that on Linux, by default, you will have G plus plus installed for you. So if you g plus plus dash, dash version, you will already have something walking here. So you don't need to install g plus plus. It's already here for you. And then while to install VS Code, you can search here in application. So you have the graphical way to do that, or you have the terminal ways I'm going to show you both. You can just search here for programs, okay? And so will, for example, here I have into software, okay? And if you explore new search for Visual Studio Code, well, you can see you will find Visual Studio Code and you can just install it or remove it. So here I already installed it before, but you can just simply remove it or install it like that. And then if you want to use the terminal, because, well, we are Linux, so let's use the terminal. If you are actually on, you're going to, you can use the snap package manager. And so you can just install VS Code with just one command line. You do sudo snap installed code. So that is an encoder, not VS Code. And then dash, dash classic and press enter. You provide your password. And well, actually it's already installed for me, but it's going to download, so it's going to take a few seconds and then installed for you. And it will be installed. Then if you unwilling to go on this page here, you can see the URL here. So Code visual Studio.com slash docs slash setup slash Linux. And this is going to be the help for how to install Visual Studio code on Linux. So you can see here the snap installation for you will do. And you can see if you want to install with directly the dot deb package, okay, so you have bit more instructions in four different OS's. So if you have a specific Linux installation and you know what you're doing well you can follow the tutorials here. And then when, once it is installed to run Visual Studio code, you just do code on the terminal. And that's going to start Visual Studio Code. You can also here on the application, search for Visual Studio Code and you just run it from there. And well, the instructions for Mac OS are also super-simple. So on MacOS you will have also installed for you. So you have a C plus plus compiler. And then you can just go back to the Visual Studio Code webpage. And here instead of Windows, you will have a MAC address table. You can also scroll down the page and find different downloads, okay, universal Intel chip, apple silicon, so just download whatever you need. And then you can see here also the help for the setup on Mac. So you just download basically what you found here. And then you just get the Visual Studio Code dot that you place on your applications folder. And then you just run it, and that's pretty much it. Alright, so now you have Visual Studio Code installed on your computer, as well as a C plus plus compiler. 4. Configure VS Code: Great, So now you have Visual Studio Code installed on your computer, okay, for any operating system. And now I'm going to show you how you can configure it so you can easily follow the course and develop with C plus plus. And the instructions here are going to be valid for any operating system. So I'm going to do something is to go on view here, the theropods and zoom in. You can see you have the shortcuts. Shortcuts may vary depending on your OS. Okay. And I'm going to basically zoom in a few times, okay? Because, well, It's quite small and it's going to be easier for you to read with the size. Okay, and now what I'm going to do, I'm going to install some extension. Okay, so here on the left you can see we have the explorer with our files that we're going to see later. And then a bunch of stuff and you can see these extensions. So one of the powerful functionality of this code is you can install plugins or extensions to improve the capabilities of the ID. And I'm going to search for C plus plus. And you can see here. So the first one is that one, see siblings plus by Microsoft. So that's the one we want. Okay, So I'm going to click on install. It's installing and noise installed. This will allow you to have stuff like auto-completion for C plus plus, which is super, super useful. Okay? So I'm going to close that. And then I'm going to search for code runner. And we're going to check co-learners. So you should see that. So doctrine for the image. And you're going to also install that one. So basically you can't just run C plus plus code from your IDE, Okay, you can write code, but then you need to compile it and run it outside, are using the terminal with the code runner extension. We have a very simple tool that allows us to, as you can see here, we have a Play button. So with the playButton, we can run the code. So that's the two extensions we are going to use, CC plus plus and then code runner. That's pretty much it. And then what I'm going to do, I'm going to go on settings, file and preferences settings. Okay, I'm going here to search for so on the left extensions and then scroll and find run code configuration. So run code configuration is the configuration for the code runner extension we have just installed there. We need just to check a few things here so you can scroll down. And well, okay, actually it's already checked for me, but it will be like this for you. It's because I had on previous configuration on my computer. So you want to check Run in Terminal and you want to check save all files before run. Okay? So those are the two options we are going to need for this course. And now you can close the settings so as you can see, everything you open is kind of a new tab on top. You just close that. And now we are going to mean to go back to explorer and we are going to clean a few things, okay, so you can go on View, appearance, and then you can see show, bar, etc. So you have different bars that you can hide if you want to. And I'm going to unclick the show activity bar. So as you can see, this is gone. And then we also do show status bar. Okay, you can see this is the one on the bottom, so show status bar, okay, so we have more space, at least for you to read on my screen, but you can, you can keep the status bar on your computer. And then one important tip is, you can see this is the menu bar, okay? Thing is that if you click on Show menu bar, and if you unclick that one, well the menu bar is gone. Well, you can just click on it anymore. So if you have done that, you can use the shortcut Control Shift and p are maybe Command Shift and P and macOS. And search for toggle menu bar. And you can click on that. And that's going to put the menu bar back in the screen. And then finally I'm going to go full screen. So you can go to Appearance full screen or just press F 11. And you are full screen. And the menu bar here, if you just want to show it in full screen, you just press on the Alt and you have the menu bar to show it or just hide. Okay, so that's the interface I'm personally going to use for this course. So far you check the different view option in appearance to just be comfortable with what you're right on your computer. Okay, and now we have everything ready to start writing C plus plus code with the setup and configuration, everything should work correctly. So you can focus 100% on learning siblings plus efficiently. 5. Create a C++ project for the course: And before we dive in, actually let's just create a project on VS Code for our C plus plus 5s. So to do that, I'm first going to create a folder directly from a file manager. So you open a file manager on Windows or Linux or MacOS. And we'll, I'm just going to go to my home directory here. So choose any place you want, any folder you want. And from my home directory here on Windows, I'm going to create a new folder named, for example VS Code underscore project. So in that folder, I'm going to put all my VS Code Projects. Here in my VS code project folder. I'm going to create a new folder that I'm going to use as a project. I'm going to simply name it cause project for this course. And I'm going to use this folder as a project for the complete cools. And then I'm going to organize the code inside that project. So now I can close this and here I can click on Open Folder. Here are also File Open Folder. That's the same thing. And I'm going to search for, so I'm in my home directory. You just search for the folder you have created. Select folder. And you can click on yes, I trust the authors. Okay, quit the welcome screen. We don't need that. And then you can see you have cuz project here. So that's a new folder. And in that folder we are going to be able to right-click and to do new file, new folder, and to create and to organize C plus plus 5s. Okay? And now let's say you want to reopen that from somewhere else. So if you want to close, you can just do close folder. Okay? And if you want to open it, you just go back to Open Folder. You just search for it, cause projects. And you make sure it's here, Select Folder and you're back to the course project. 6. C++ Basics - Level 1: In the following lessons, you're going to write your first C plus plus program and learn some of the most important programming concepts. We will start directly with the code and we've practice no fancy theoretical explanation. First, you will discover what is the minimal called structural unit to write in order to run a C plus plus program. I will introduce the concept of variables in through an example. You will understand why you need them and how to use them. You will also get to know the different types of variables you can use to represent different kinds of numbers and data. We will also practice with lists, are arrays to store a collection of vials. At the end of the section, you will be able to write short C plus plus programs and in which you are going to interact with the user and install the values you got with variables. And now, as I previously said in the introduction, I encourage you to first watch the entire section. Even if you don't understand everything, then you might try to do the exercises are to watch the lessons again, this time using the pose and rewind buttons. All right, let's get started. 7. Your First C++ Program: In this lesson, you are going to write your very first C plus plus program. You will see what is the minimum code structure you need and how to make your program bringing something as a result. So make sure you have the correct C plus plus compiler, the correct setup, and also the course project folder here. If not, go back to the introduction section to install and set up everything. So first of all, to write as C plus plus program, we need to create a C plus plus file. So inside my cost projects here I'm going to right-click New Folder and we are in the basics. So underscore, level, underscore one. So basic level 1 of this course. Inside this new folder, I'm going to right-click and do new file. I'm going to name it hello dot c. So that's our first C plus plus file. You can see we have a new tab here and the file in the text editor. So first important thing when you create a simplest plus file, use the dot CPP extension. Very important. And then to name the file, don't put any space, okay, if you want to put some spaces between words, you can use, for example, here, underscores, okay, as I did for the folders names, Let's write some C plus plus code. And actually we can just write C plus plus instructions like that. We first need to write a minimal code structure. So let's do this. So you can type int this space, main, open close parenthesis, then go back to a new line and open close curly brackets. And you can see, for example, that this is a feature of a good IDE, is going to, when you open a curly bracket, it's going to close it automatically. So then you can press Enter. And you can see now the cursor has an indentation of four spaces here, okay, this is the notation in C plus plus is not mandatory, but this is so when you write code, this is going to be much clearer and much more readable. So int main, open, close parentheses, open close curly brackets, and then you can do return space 0 and then semicolon. This is the minimal code structure unit for C plus plus program. So that's not be. And well, what is this? Int main is basically a function that is going to return an integer number. So in that function we have then nothing and return 0, which means it's going to return 0, which is an integer number. And we finish the statement with a semicolon. So I'm going to explain everything about functions later in this course. For now, you just need to know you have to write this. And then where are you going to write your instructions? Where you are going to write your instructions inside the curly brackets here and before return 0. And where it's very important to have exactly this, okay, this function should be named main exactly and not something else. Now if I compile and run this program, nothing will happen. The prime would just run an exit directly because we don't have any other instructions. So what I'm going to add is an instruction to print something on the terminal. And to do that, I am first going to need to add hashtag include. And as you can see, we have auto-completion. So on VSCode with the cplusplus extension, you have auto-completion, so you can see some suggestions of what you could write in if you have a suggestion, the first one is going to be automatically completed issue price tab. So I press tab and you can see include. And then I'm going to put some angled bracket and type I O stream. And as you can see when I start to type IO stream, I have this. I press Tab again. It's going to finish the world and also close the angle bracket. So this instruction include with angle bracket is going to include a C Plus Plus Library. And we will need this library to actually be able to print something, so nothing to rinse then here is just like that. And then to print something you have a function, So functionality which is std, column, column C out, and you can see the auto-completion again. Okay? You can just browse the different functionality and choose the one with the Rockies and we've tapped. And then we will need angled bracket twice. Then I'm going to put double quotes. As you can see when you put double quotes, once is going to put 2 and I can write some texts, Let's say hello. And then space angled brackets twice again. And then std colon, colon and L for end line. Okay? So if I just print hello, it's going to print hello and then everything else is going to be printed. Just after hollowness, the same line of the terminal. If I want to go back to a new line, which is usually what you want to do when you print something, you are going to add and L, which is basically n line. And then if you want to finish a statement in C plus plus, you have to add a semicolon. The semicolon is super, super useful, as you can see, we have one here and one here. This means that the statement here is finished. You can know processed the next statement, okay? And here, well, what do we have? So what's going to happen is that when you run your program, the main function here is going to be called first thing. And everything in the main is going to be executed simply the other of the code. Okay, So this line, this instruction is going to be executed semicolon N of instruction, and then whatever is after that. Then we go to the new line and we have another instruction. So of course, best practices to print just one instruction per line. Okay, I could just do this. This would be correct. Okay, that's one instruction semicolon, one instruction semicolon, but that's not readable, so I'm going to do that. Okay, So line five is going to be executed. Line six is going to be executed, and then we go out of the main and that's it. So it's pretty easy to see the other of execution. And now, well, how can we execute that code? Because this is just some code. How can we make sure it's going to be executed? Well, we will need to compile the code because C plus plus is a compiled language. So very basically, but you have your C plus plus code that we have just written with the main function. You are going to use a compiler. And the compiler is going to create an executable file. And then from that executable file, you will be able to run the executable file, and this is going to execute the program that you have written. So you can see we have two steps here, a compilation and then runtime. And so back to our program. Well, with the code Renault extension, I have installed on Visual Studio code. What's going to happen is exactly that. So I click on Run. What's going to happen is going to first compile the code. So you can see here, okay, this might be quite, this might look quite complicated, but you don't need to understand everything. And I'm going to show you the important parts. So first you can see what is going to execute when you press on right? So CD is basically go to that folder. So basically go to the folder where the file is. And then you have g plus plus. If you remember, g plus plus is actually in the terminal, the command to compile a C plus plus file. So it's going to compile the hello dot cpp that is here into hello executable. As you can see, when we do this, when we press Run on the left, we have a new file, hello dot exit. So exit is going to be maybe specific to Windows. If you're on a Linux system, you're just going to see hello, which is an executable. And then this is simply run the executable. So compile and run, this is what's going to happen with the button here. So we're going to see how to do that manually later in this course. But for now you can see that basically that's what going to happen. And then after that, you have whatever you print from your program is going to be printed on the terminal, here, on the terminal window. And you can see hello because we have printed hello here. So the program is working. All right, and now let's say I want to modify this program. I want to add another line that second. Just copy this with Control C and Control V on a new line. And let's put test and taste ABC. So I'm going to click on that. It's going to save and run the file. Hey, so it's going to save and then of course compile and run the file. And you can see Hello tests, ABC. Okay, now I'm just going to show you what's going to happen. For example, if you have an arrow, Let's see, I forgot the semicolon here. So you will see first that on Visual Studio Code you will have some help, okay? You will see something red, expected a semicolon. So that's something you can already spot on Visual Studio Code. But then if you try to compile and run, and you can see here we have an error, okay, that's not the same output as before. We have an arrow saying in function main, which is that one. On line six, you can see 96 and then colon 41, expected semicolon before written. Okay? You can see here the error is quite explicit, okay? So here it tells you that you have to put a semicolon here. Sometimes the arrow will be explicit, sometimes not gay, but here you can see it's super easy to spot it and solve it. And now it's running when I put the semicolon. Okay, great. Now you know how to write a minimal civil space program, how to print something on the terminal, and how to use VS Code to save the program, run the program, check arrows, and use auto-completion. 8. Variables: Let's now see what variables are. This concept is the most basic and maybe the most important when programming in actually, before you learn what variables are, let's first understand why you need to use variables with an example. So I'm going to write some code. I'm going to just use this program and I'm going to write some code so I can print here what is called heroes train, which is a chain of characters. I can just print also numbers, okay? For example 2. And I can also put a computation, for example, 2 plus 1. So let's say we want to put two and then two plus one to plus 22 plus three. So I want to bring 2345, for example, with this syntax, a number, the number plus one, number two, number three. So if I run that code, you can see I have 2345, which is what we expected. Now the thing is that let's say I want to start from the number three. For example. If I want to start from the number three, I need to change to here. I need to change here, a change here, and change here. If I run it, it's working. We have 3, 4, 5, 6. Now let's say we have to change this value in many more places because this program is super, super short. It's only 10 lines. Okay, let's say we have a program with many hundreds lines. You can see that's going to be quite inconvenient to change that value every time we want to change the number. Another example is, let's say you are programming a video game and you have a character who has a life which starts at 100. And then let's say the life will go at 1765 every time it takes damages and the value will be changed and it will be changed by outside events. So for stuff like life, also character is going to be impossible to just hard code a value like this. You will need something like a sort of container for that value. So you can store that value. You can also modify it and you can reuse it later. And well, that's exactly what is a variable. So now I'm coming back to this program and when to create a variable. So instead of just hard-coding value, for example, 3, 5, etc, I can just use a variable. I'm going to create a variable int number is equal to three and then semicolon. Okay, so I'm just going to use it and then come back to it to explain more about this. So now I have a variable named number, which contains three. So what I can do, I can just put a number here. And when I put number is going to be replaced by its value which is three. Okay? And I can put number actually here, but also here, also here, and also here. Okay, now if I run this code, you can see we still have the same output, 3, 4, 5, 6. If I put, let's say 10. I just need to change it wants here. And it's going to be changed every time. Run the code. And you can see 10, 11, 12, 13. So with this variable, we have something to store a value and then we can retrieve it later in the program. So now that you have a better overview of why you need variables, I'm going to just remove everything and I'm going to create a new variable and explain to you exactly how to use them correctly. So I'm going to create int a. So to create a viable, you first need to provide a datatype. The datatype is what kind of value you are going to put inside the variable. So I'm going to come back to this later. For now use int, okay, which is integer around them. After this, you need to provide a name for the variable. So here I can just name it a, okay, that is a valid name. And after that here I have a semicolon. So this is going to declare a variable. This is the most basic thing you can do is to declare a variable after you have declared a variable, so it doesn't contain any value. After you have declared a variable, you can assign a value to it. So I can do a is equal to 2. And of course, as you can see, every time I use a statement, I use a semicolon. So he, I declare a variable and I initialize the variable to different steps. What I can also do is I can declare the variable and initialize the value directly in the same line. And then we'll, I can print that variable with std, cout, std. And lying in this semicolon. I've just thrown play. And you can see we have two, okay, which is what's inside the variable. What I can also do, for example, here, I declared a variable and I initialize it here. I can also declare it here, int a. For example, I can declare and initialize it here. And I can also declare it here and initialize it in the main. That's also going to walk. As you can see here. We also have to. And so the value you put inside, you can actually put direct value like this too. You can also put the combination of value for computation like 2 plus 3. And you can see a is going to be equal to 5 or 2 multiplied by 3 is going to be equal to 6, okay? You can use this operator divided by minus 2, minus 3. You can see a is going to be minus one. You can use any computation you want, okay, to put a value inside a variable, and then I can create other variables. For example, int b is equal to a different value. What I can also do is create a variable from another variable. Let's say put int b is equal to a plus two. Like this. I run the code. So let's actually print B here instead of a. I run the code and you can see no b is equal to one because a was minus1 plus 2 is equal to 1. So what's going to happen is that at this time, this is going to be evaluated to its current value, which is going to be minus one. And then this is going to be evaluated to one, and this is going to be assigned to the variable b. I can create another variable. Let's say c is equal to a plus b, for example. And I run the code and you can see, well no, if a print c, we can see that C is equal to 0, okay? Because this is minus one, this is one. Now let's say that I modify a. Let's say I put a equal to 10 after creating c. So what's going to happen? Do you think that C is going to be modify? Our C is going to be the same. Well, let's check. Let's run that. And you can see that C is still equal to 0. Okay? Why is that? Because here we have modified a2 ten that remember that each line is going to be executed one by one in the other. So here, at this time on line 9, c is going to be assigned the value of a plus B at this time of the program. So at this time of the program, a is equal to minus one. So minus one plus one is equal to 0, which is assigned to variable c. After that, we go to line ten and then we change the variable a. We assigned a new value to the variable a, but C is not going to be changed because it was already assigned an a was evaluated here before line 10. Okay, So the other is very important. If I put this line before creating the variable C, You can see that now the variable c is equal to 11 because at this time of the program a is equal to 10, not minus1. Okay, so that's very important when you modify variables and when you assign values to variables. The other of your code is very important for that. So well, That's the basics of vials. And know whether to do tests. It's quite useful to use a, B, C, D, etc. But when we program in real life, the best practice is to use meaningful names for variables. So by meaningful names, I mean, for example, let's say that you have a temperature. Then for a temperature you are going to use int temperature. You're not going to name it T, RTP, whatever you are going to name it temperature because that's what the temperature is. Okay. If you have, let's say user age, then you can use int, user age. And as you can see here, if you have space, you can put spaces, but you are not going to use spaces, you are going to use underscores. For example, whenever we program, we are going to try to use meaningful names for our variables so that the variable represents what's inside and whenever he reads it. So that can be new in the future or someone else can easily understand what you have written. All right, now to recap on variable. So a variable is a container that you can use to store a value and reduce that value later in the program. To create a variable, you first need to declare it with a data type and a name. And then on the same line are in a different line, you can assign a value to it. 9. Variables - Data Types: You can now declare, initialize, and modify variables. So far we have only seen the integer datatype int. But actually there are more types you can use. Here. I'm going to show you the most important ones that you are really going to use in your future C plus plus programs. So what kind of data type do we need? We already have integer numbers. Okay, so I'm going to remove this and this and just print user. I'm going to put a value in user age, let's say 34. So we have integer numbers for run number. So random errors can be 0, 1, 2, 3, etc, and can also be negative numbers. Now, we also need to have float numbers. Okay, so let's say you have something that is 10.5. With integer, you can't store 10.5. So you have what we call float numbers. And for the float numbers, the datatype for civil space is you can see double. It should turn blue. So double. And let's say, let's say we have the temperature and the temperature is 20.6 Celsius degrees. And I can use, so I'm going to copy this and paste it here. And I can use temperature. As you can see, I have the auto-completion also because I create a variable, I can use the auto-completion for the variable here by pressing Tab or by clicking on the suggestion. So here I have double, which means that I can use numbers with decimals. So that can be any positive or negative number. So with that, we are pretty good with numbers. Now, there is another data type, which is the Boolean data type, and the Boolean is bull. And this is very particular. This Boolean data type only contains two possible values, true or false. So for example, is alive if you have, let's say a video game character or if you are doing robotics. And you have, for example, a motto and you want to check if the motor is alive, okay? Which means that it's, for example, running and connected. And so you have two possible values can be true. As you can see here, it should turn blue, are false and then semicolon. So true and false are recognized keyword in C plus plus, okay, that you can use for Boolean values. And this, we are going to come back later to gut for example, on conditions and loops. This is going to be super useful. And then well, we have numbers, booleans. What if we want to print some text or use some text in our program, we can use the std colon, colon, string datatype, Let's say user name equal to Bob. We just weren't eat. So std colon, colon, string. So that is the same thing as to create other variables. Okay, you just put the type first, name and an equal if you want to assign also value. And then you can use double-quotes and the string you want to put inside that variable, let's print. So let's do this two more times. And let's print instead of temperature is alive and user name, you can see I just start the wall and then I press tab. Usually. Also note that any line that has nothing in it will just not be executed, but that can be nice, as you can see here, to add more reliability to the code. And let's run that. Okay, you can see we have the different values here, 3420.6. We have 0, okay? Because when you actually print a Boolean, you are not going to see false or true. You are going to see 0 or one. So 0 for false and one for true. That's what you're going to see, but that's actually in the code, a boolean. And then bob for the string. All right, so here you have, I will say the four main data types that you're going to need to use when you begin with C plus plus. And as you can see, we have used meaningful names directly here. We don't use a, b, or C anymore. And so to recap, when you declare a variable in C plus, plus, the first thing you need to do is to give it a type. Once the type is chosen, this is going to be the type for the entire life of the vial. And so to know which type you should choose, you can ask yourself, what kind of data am I trying to store here for the specific variable? 10. Variables - Constants: So you have seen that after that you create a viable, then you can modify it at anytime and any number of times. What if you want now to create a variable that counts be modified in the future, this variable will be called a constant viable. For example, you want to create a variable to keep the number of seconds per hour. Let's say here, int seconds per hour, which is equal to 3,600. And that, I mean, this can't be changed. Okay? That's how it is. That value can't be changed. Or let's say you want to create a variable to hold the maximum possible temperature that your computer can reach before your program shuts it down. So let's say double max. Let's say a load temperature is equal to, and let's say 76.8 degrees also on talking about Celsius degrees here. So you may want to block that maximum load temperature because if it's modified later on in your program to an bigger value, you have the risk that your computer is going to die because of heat. So for those two scenarios here, you can create a constant, variable which will make sure that this value will not be modified in the future. And to do that, It's very simple. You just add before you create the variable, before the type, you add const. So the const keyword, which is for constant. So now let's say I'm going to, I'm going to remove this and I'm going to print here silicons per hour, and I'm going to bring here max. So once again, I use the auto-completion max load temperature. Okay, so let's print the edge. You can see we have the two values here. And now I'm going to try to modify seconds per hour is equal to, let's say three. So this is an integer, I'm just trying to modify the integer. Now if I run that, actually we have an arrow at compilation because you can see era assignment of read only viable seconds per hour. So read-only means you can only read it. So you can only get access to it, but you can't modify it, okay, Because of the const keyword. So here, because you have put const, you make sure that this line is not going to pass compilation time. This line is not going to be valid, so we can't modify those two variables. We can still modify user age, temperature, etcetera. Okay, that's going to work, but not those two here. And a specific rule also to constant, variable is that you have to declare the variable and initialize it on the same line. Okay? I can't do this. Signals per hour. So this, we have seen it's valid for any other variable, which is to declare a variable and then initialize it. This is not going to work as you can see here. We have arrows. And when I run the program, you can see an initialized constant. And of course the assignment of read-only variable. So you have to initialize a constant when you declare it. And we can do this and just remove that line. And everything is okay. So to recap, use the const keyword before declaring a variable. If you want to make sure that the value inside the variable won't be modified. In other parts of the program. 11. Arrays: You can know stall different kinds of values into vials. Now, imagine that you have to read some temperatures from a temperature sensor and store all the temperatures so you can process them. If you have 10 temperatures, you will have to create 10 variables, for example, temperature, one, temperature to etc. As you can see, that's not really practical. And no, Imagine that you have to store not ten, but 10 thousand values. That's just going to be impossible. So how are you going to solve that problem? Well, this is where you can use what we call arrays. What is an array? An array is simply a collection of values that are related to each other and share the same datatype. For example, you could have an array to store all students name for a classroom. Here we are going to create one to store temperatures using the double datatype. So for this, I'm going to create a new file here for example. And so in the basic level one, new files, arrays dot CPP. Ok. And I'm going to add include iostream so we can print stuff and then int main, curly brackets return 0. So I just create the minimal structure, wants more, okay, which is super-fast to do. And so let's create an array with a few values for the temperature. So to create an array, I'm going to create an array of double. Here is the syntax. First, the datatype for the elements. So all elements of the array are going to be of the same datatype. Then the name of the array. I'm going to name it temperature list. Okay? Because, well, this is quite explicit. We are creating a list or an array so you could name it, for example, temperature array. I'm going to name it temperature list. Are you can also use tempera. Choose for example, in the, in the plural. I'm going to name it temperature is because that's super explicit. So use explicit name. That's better. And then you are going to open and close brackets, okay, So brackets like this. And you're going to put the size of the array. So you need to put a site, for example, let's say four, which means that this array will have four values in it. And then I can just put a semicolon to declare the array. What I can also do is I can directly initialize. So that's a specific feature for arrays. Again, just initialize the array on the same line by using curly brackets this time and putting all the elements of the array. So for example, they have 34.5 and then 27.826.8, and then 22. Here, I have initialized my array with four elements. I can't put more elements than these because we have just four slots or the array, okay? And then what I can do with this array, what I can do is for example, if I want to access one element, well to access one element, I'm going to do std cout to be able to print. And I'm going to let here and, and so STD and lighter. And if I want to access, for example, an element of the array, I'm going to put the name of the array, temperature list, and then open and close brackets. And I'm going to put the index of the element. Let's try with index number one. But this is going to print the index number 1. So the element which corresponds to the index number one in the temperature list. Let's run that. Okay, so here you can see G plus plus with Arrays.sort DVDs time. And then we run the executable that was creating here. And you can see 27.8, which corresponds actually to the second element of the array. Why is that simply because when programming, when we start to count, we don't start to count at one, we start to count at 0. So if I use 0, I'm going to add the first element, 34.5, okay, So 0 and then 1 and then 2, which is going to be the third element, 26 for eight. And then three, which is going to be the last element here, the fourth one, 22. And then the thing is that if you try to access an element that is outside, okay? This array, well, the behavior of osteoblast might be quite, we'd basically undefined. So you want to make sure that you stay inside this array, okay, So here if you have four elements, you can use index 0, 1, 2, and 3. If you have five elements, you can access to the index number 4, etc. So very important to stay inside of the array and start to count at 0 and not one. Now, you have seen how to get access to an element y. If I want to modify an element, what do I want to modify? Actually this element with the index number 3, which is going to be 22. What I can do is simply do temperature list and then brackets the index of the element. And then put the equal sign and just put any old overweight, say 15.4. So this is similar as when you actually modify a variable. On the left, you have the, so the variable which is basically the element here with the index 3. And on the right, so equals sign on the right, the value you want to put in this. So here we create an array and then we modify the value with index three, and then we print the value with index three. Let's see what we have here. Actually going to print it before and after we modify the value. Well, let's run that. You can see that first we have 22 and then I modify the value, and then we have 15.4. Alright, so that's pretty much it about arrays. How to create an initialized them, how to modify them in, how to get access to an element. So to recap, an array is a collection of related variables sharing the same datatype. To create an array, you first need to declare it and give it a size which cannot be changed afterwards. Then you can access and modify any value from the array using an index. 12. Arrays with std::vector: The array you have just seen before is actually something quite basic, which already existed in C. In C plus plus, you can use this kind of array, of course, no problem with that, but you can also take advantage of the std library. So we have already used estimate here, which is the standard library for C plus plus. And in this std library, you have emerged better functionality for arrays named vector, and let's say that now. So first, one of the main issues of standard arrays in C and C plus plus like along those ones, is that they are not dynamic at all. You choose a size at the beginning and then that's it. But what if you don't know in advance how many elements you want in the array. What if you want to add new elements after you have created the array? And this is something you can actually solve, but it's really quite complicated. With the STD vectors. You don't have this problem anymore. So let's use vectors in. Let's see how we can create an array with this new functionality to use that we need to include the hashtag include and then open angle bracket vector, close angled bracket. I'm going to put this actually if first and I'm going to create the same thing but with vector. So I'm going to do std, colon, colon vector. And I need to open and close angled brackets and put the data type I want for the list. And I'm going to put double. Okay, so here the data type is going to be inside std vector brackets, not just at the beginning. Then I can put a name temperature. So actually I'm not going to name it temperature list because there is something else here named temperature list. So we can have some conflicts are error in our code. I'm just going to put temperatures like this with an S and semicolon to declare the victory. As you can see here, I didn't precise any size because the size is going to be dynamic. So I can create the vector like this which is going to be empty. I can add new elements after that, which we are going to see. What I can also do is just like we did with arrays. I can also, I'm going to do that and booklets, but just three elements. I can initialize some values. So if I do this, what's going to happen is that this is going to create a vector with three elements here, here and here. So this is going to be index 0, 1, and 2. Now what if I want to access an element? So I'm going to do STD C out. Again, do temperatures. And then I'm going to do dot at, okay? And I'm going to give it the index. Let's say I want the first element. I'm going to put 0. This is going simply to return the first element of the vector. The vector name dot at 0 for the first element. And then STD and liner. Now if I want to modify an element, that's also super easy. I'm proud shoes. Dot at, let's say want to modify with the index 1 is equal to, and let's put 30.7. Okay, so that is going to modify the element here because index one is the second element. I put the semicolon. And then I'm going to do this to print to see actually what happened with the element on index number 1. So let's run that. So you can see we have the first two prints for the first array. And then we have so the first payment, 34.5. And then we modify the single element. And then when we print the second element, we are actually the value 30.7, which was not the first value in the array. So that was modified. And you have many more functionalities. Actually, I'm going to just do a C out. Again. You have many more functionalities with vectors. So I can do, you can see here when I do dot, I have all the possible functions I can use with vectors. Okay? You have many, many, many functionalities. One of them is, for example, size, like Andrew say's open, close parenthesis. This is going to return the size of the vector. And so I save the file. And if I run this, you can see that the last line will be three. Okay? Because the size of the vector 3, we have three elements. I'm going to show you also another useful function and g, which is to add, if you want to, new element to the end of the vector, you can do the name of the vector, soil temperatures, dot push back, open, close parentheses and the value you want to put. So let's say 17.4 and then semicolon. So don't forget the semicolon at the end of any statement. So here what I do is I add an element to the victory, to the array, and then I print the size of the array. Let's run this. You can see now the size is four, okay? Here we have three elements. We add a new element, and we have the size. So that is super, super useful. So to recap, vectors are much more powerful way to create arrays in C plus plus. So you've got the introductions to array, which is super useful to understand that at the beginning. But now what I recommend is that whenever you need to manage a collection of values of variables, I recommend that you use vectors instead of just standard arrays. And we're going to continue to work on vectors in the following of this course, as well as discovering new functionalities related to them. 13. Get User Input: You have seen that with the C-out function, the SDC out, you can print some things so the user of the program, so actually the user for now is me, or you can get info from the program. But we can also ask the user to write something which we can then use and store it inside a variable. This will add more interactivity to the program and makes it more dynamic. And it's going to be great for your C Plus, Plus learning paths. So let's see how to do this. I'm just going to create a new hear, new file. Let's say user input that CVP. Just one key. And very quickly include iostream. Iostream contains the cout function, but also the cbind function we are going to use right now. Its main written as 0. So how to get the value from the user? Well, first, you're going to need to create a viable so you can store that. So I'm going to create, for example, an STD string. Let's say username. I'm not going to define the variable, I'm just going to declare it. And we're going to put a viable from what the user gives us when we run the program. And I'm going to use std C. Okay, you have c out and you have seen out to print in to ask on information. And I'm going to use angle brackets, but this time not like this on the opposite side. And I'm going to put username and semicolon. So here you can see it's like this is going to the right, okay, so what you get from seeking from the terminal is going to go inside username. So now if we just run, Let's run the program, actually save and let's run the program. You can see now what's happening is that while the program hangs here, okay, you can see hanks. If I press, I can put some text. If I press Enter, you can see now the program has exited. So this will wait for you to give a user input. Now, once we have this user input, we don't do anything with it. So let's just print it. Let's do STD, C out, and then username. And then STD and lighter. As you can see here, the angle brackets are on the opposite direction. And let's run that. So I'm going to put BUN and I press Enter and you can see we have Bob. So this, we'll put the string Bob inside username, and then we print the username. And so we have never written any Bob, any information in the program is just going to take the information that we give when we actually run the program now. So let's run it again. Let's say you want to quit the program, you don't want to put anything. What you can also do is press Control C inside the terminal, okay, when you press Control C or Command C, maybe that's going to try to terminate the program, okay, because here the program is not just going to execute n written, it's going to wait for user input. So if you don't want to give a user input, you just price Control C. And while that's pretty much it about how to get a user input. But as you can see, when we ask the user input, we don't have any information. So what we can do is add just before seen. We can do STD C out and say what we are expecting from the user, okay, For example, what is your name? I'm going to put that, I'm going to put a space and a semicolon here. I don't put any line. Okay, so then we're going to put the username directly on the same line as what is your name after the space. So I can dress run that. And you can see what is your name. I'm going to put Bob, press Enter and you can see Bob. So as you can see to recap, to get the user input, you're going to use the STD see in function. And just before that, you may use SDC out to say what you are expecting from the user. And then you put the value inside a variable. And after that, you can use this variable in your program as you want. And of course he, I'm using a string, but you can also use an integer, a boolean, float number with double. Okay, that's going to put the value in the variable accordingly. 14. C++ Level 1: Exercises: It's now time to practice on what you have seen before in this section, especially on vials. So he, in this video, I'm going to give you a few exercises to do. And in the next video, I'm going to give you the solution for those exercises. And before you start, the exercises are when doing them. If something is not clear, feel free to go back to the previous lessons, okay, to watch them again and better understand different concepts. So here are the three exercises I'm going to give you now. The first one, you are going to create a program. So for each exercise you can create a new C plus plus program. And in this program you are going to ask for the name and the age of a user and then print the info. For example, Hello, username, you are user age. The second exercise, you are going to ask the user for two integer numbers. You're going to add those numbers and then print the result. And for the third exercise, you are going to create an array, or I would say a vector r for float numbers. So for that you can use the double type. You are going to compute the average inside the array and print the average. So for this exercise, you may have to think a little bit more and also come back to the previous lessons. So as a reminder, for a list, the average is the sum of all the elements divided by the number of elements. So for the number of elements, I already gave you a function that does that for Victor, okay? And for the sum of all the elements, I'm going to give you now a new function. And this function is named accumulate, okay? And to use accumulates while you have to use accumulate with parenthesis and with three parameter inside the parentheses. The first one is list.pop begin. So list is going to be the name of the vector you have, okay, that I named list here. So you are going to use the name of the vector dot, begin with parentheses and then comma, the least, that end with parentheses, and then comma and then 0. So you don't need to understand that for now. Okay, that's just the function and giving it to you now so you can do the exercise. And if you want to use accumulate, you will also need to add include numeric at the beginning of your program. All right, so now take the time to do the exercises and I will see you in the next. Listen for the solution. 15. C++ Level 1: Exercises - Solution: This is the solution for the three exercises I gave you in the previous listen for the level 1 on this course. So let's start with the first exercise. I'm going to create a new file in the basic level 1 folder named, let's say 1. And it's called one username, age dot CPP. So I have my include iostream and then I have int main. We return 0. So in this program, I need to ask the user for its name and for its age. So I'm going to start with the name and I'm going to create first a variable which will be of type string for the name. So std colon, colon string, username. And then I'm going to do STD C. We've angled brackets in this direction, username. And before I do this, I'm also going to do STD C out with what is your name like this and a space. So I can have a prompt for the cbind function. And then I'm going to ask for the user age. So I'm going to create another variable. And what I'm going to do, I'm going to put the variables here together, int user page. And I'm going to do after this instructions, STD C out. How old are you? Space? And I'm going to STD C. And I'm going to put that inside user age. So I create two variables and then I have two sets of c out, C in instructions to ask for the user to put a value inside this variable and this variable. And now that I have this, what I can do is the conclusion of this exercise, std, cout, market bracket. And to say for example, hello space, another set of brackets, username, another set of brackets. So if you want to add stuff, you just use double brackets every time. Okay? So here I have just a hard-coded string. Here I have a variable. So I use the string bracket, bracket, the other string, et cetera. And then let's put our space two angled brackets. Let's put user age. And then two angle brackets. Let's put a dot at the end. As you can see now the line starts to be quite long. Again, it's still not finished. So what I'm going to do, I'm going to cut it here, for example. I'm going to put space and just a few tabs for readability. This is not a product MOOC. You can start a statement and when you have an operation, for example, this, or if you do an operation with numbers can be, for example, plus, minus, et cetera. Here it's going to be double brackets. You can go back to a new line, okay? And that's going to be the same instruction. So I do this and then STD and light and hear the instruction will be finished when I use the semicolon. So hello, username, New, User dot. I'm going to save and run that. And it's going to ask, what is your name? How old are you? 34. Hello Bob. You are 34. Okay, that's it for the first exercise. Now, the second exercise, so let's create a new file named one. To it. We need to add two ints. I'm going to put add two ints that CPP. And I'm going to include iostream, create a main. So you can see that can be quite fast. And I have my minimal coating. And so the first thing I need to do is to ask the user for two different members. I'm going to choose to use integer numbers. So int, let's say number one. It never took it. And now I'm going to give you a tip here is that when you, for example, if you want to create different integer variables like that, just for the declaration, what you can do is you can just put int number one, comma two, and then semicolon. And that's going to create and declare two integer variables. Okay, So that's what I'm going to do. And then std, cout, Let's say enter number one. Okay, std cn, I'm going to put that in number one. And then std cout Enter number 2, st. Inside. After I got the two numbers, I can create, for example, another variable, int sum is equal to number one plus number two semicolon. So this will be the sum of the two variables of the two numbers we have given to the program. And finally, I can print the same. I'm not just going to print the same. I'm going to print number one plus number two is equal to sum. So STD C out, I'm going to start with number 1 and then plus. And then number two. Then put the equal sign in quotes and some. And finally, let's put std inline because this line is quite long. I'm going to cut it here, for example, like this. The tab he is just so it's more readable but it's not needed. Alright, let's run this. And ten number 1, let's put six and 10 number 2, Let's put eight. You can see six plus eight is equal to 14. So it's working. Great. So that's it for exercise 2. And now let's go to the third exercise where you need to compute the average of a list of numbers. And I'm going to create a new file here, 1, 3, and let's say compute average dot CPP. And so as you can see for each C plus plus file that we create, we have an executable file. Then when we run the file, and I'm going to include iostream because we are going to use c out and then int main return 0. And let's write the program. So the first thing you need to do is to create a vector containing four elements. So that's what I'm going to std vector. We use double here. And let's put the name number list. Okay? Number list is equal to, I'm going to initialize them here. Let's say 4.45.56.67.7, okay? Just like that. And of course, key I have an error because I need to include vector. So as you can see, every include line, you are going to put them at the very top of your program before any function, before the main, okay? Now, I need to compute first the son of the list. Then I need to compute the other age using the sum n, the size, or the length list. So I'm going to do double sum. So why the long while? Because I'm going to add some double numbers. So I can expect the sum to be a double and I'm going to use double as well. And this is going to be, I'm going to use the accumulate function. And to use accumulate, I need to include numeric. So as I, this one, I gave it to you in the exercise. You need to include numeric to be able to use, accumulate. So accumulate. And then I'm going to put number lists that begin. We've parenthesis, number list that end parenthesis and 0. And then they put a semicolon at the very end of the instruction. So once again, no need to understand that. That's a bit more complex. Okay, for now I just gave you the function here so you can do the exercise. So you have the sum of the vector here and then double. Let's compute the average is equal to 7 divided by the length of the array, the number of elements, and how to get that? Well, if you remember, we have a number list dot size function. So the size, you can see here returns the number of elements in the electron. And once we have that, we can just print the result STD C out. Let's say average value in the list. And then either age and then estimator N layer. Okay, and just one thing before I run, just one thing I'm going to fix. It's just that for the accumulated function here instead of 0, I'm going to put 0. So 0 here you can see the integer 0 is a double number, okay? And so that's internal behavior of the accumulator, okay? If you put an integer number here, it's going to add them as integers. If you put double number here is going to add them as dogs. And what's going to happen also is if you use an integer for float number, what's going to happen is that the number will be truncated. So here, instead of 4.4, you will get For, okay, instead of 5.5, you will get 567. So you lose the decimal. Here. We don't want to lose the DCO. And well, I'm just going to run that. You can see average value in novelist 6.05. And so you have the average number of that list. And now you can put any element you want here. This code is going to be the same, okay? And you can compute the average of any vector you want. Alright? And that's the end of the level 1 of this course for C plus plus programming. 16. C++ Basics - Level 2: You can now create your own C plus plus programs with variables, lists of variables. And you can interact with the user of your program by printing information and asking for input. You also have seen how to take advantage of some of the most useful features of an IDE using Visual Studio Code. Now is the time to get to the next level of C plus plus and learn how to create more complete programs, as well as re-usable and re-enabled blocks of code. Writing all the instructions of your program in the main function is fine if you just have a few instructions. But as soon as you want to implement bigger and more complex functionalities, you're going to hit a wall. So in the following lessons, the main focus will be on functions. You will understand what a function is and we will build different ones for different purposes. You will see how to reuse functions, how to pass parameters to them, make them written a value, et cetera. I will also talk about variable scope, which is a super important concept to understand at the beginning. So you won't get weird arrows that you don't understand in the following. And I will show you some useful tips to increase the readability of your programs using, for example, the comments and namespaces. So at the end of this section, you will be able to write re-usable C plus plus code and to keep your programs easy to read as you make them bigger. And let's get started. 17. Functions: Now is the time to start working with functions. And for this new section, I'm going to create a new folder here. And then also to right-click here and do close all. And right-click here and do new folder named basics level 2. And in that folder, Right-click New File, let's say function's dot CPP. And also I'm going to put the minimum structures. So int main and return 0 also will include iostream because we are going to use the C out functionality. Okay, great. So what is a function? A function is basically a block of code that you can reuse later in your program as many times as you want. And why do you need functions? Well, this will help you create building blocks in your program that you can use and reuse on top of each other. So you can increase the complexity of the program without increasing the complexity of your code. Your code will stay clean and will be easy to modify and to maintain. And now, instead of giving you many theoretical explanations, let's dive in and write our first function. And actually the function we're going to write is not the first function because the first function we wrote is the int main function, but I'm going to come back to that later. So I'm going to write a function, a very simple function that will do one simple thing. It will just say hello. So I'm going to start with void. And then so that is the return type of the function. For now I'm going to put void, which means no return type. And then I'm going to name it, say hello. So you need to give it name. And then open and close the parentheses. Come back to a new line. I'll just put brackets here. So you can choose to put brackets like this. Okay, Our to come back to a new line and usually what I do, I just go back to a new line. And then inside those brackets, you are going to write the code for the function. As you can see, this is very similar to what we have with the main. And here we don't have any written statements because this is void datatype, which means no written. And so what I can do here is just for example, do std cout hello and then STD inline. So this function say hello, we'll just say one thing about the name of the function. So of course you can't put spaces, all right? If you want to put different words, you can use, for example, underscore. You can also use camelCase, which means that every new world we'll start with an uppercase. Just for this course, I'm going to use this. This is just a convention I'm using here. Maybe for different projects in the future, you are going to use different conventions. All right? And now what's going to happen if I run this program? So you can see here, well, we don't have anything printed here on the terminal. Why is that? Because we have a C alkaline. But while this is a function, this is the definition of a function. It's not going to do anything by itself. You need to call the function in order to execute the code inside the function. So in the main, the main, here, the main function will be called directly when you start the program, okay, That's the rule for C plus plus programs. You need to have a main function that going to be cold, but other functions are not going to be called. So if I want to execute the code inside, say Hello, I need to call say hello. And you can see I can also use the auto-completion know, say Hello from the main. So to call a function, you just put the name of the function and then open close parentheses. And of course, the semicolon. Now if I run the code, you can see I have Hello. So you can call it function one time but also multiple times, okay, if I call, say hello three times, well, that's going to say hello three times. Okay, you can see hello, hello, hello. And now let's say I add a new line, std, cout, test STD and line. Let's try with that. You can see that we have hello test, hello test, hello test. Okay. So as you can see here, that's very useful. We want to print this three times. Well, I just need to write the instructions once. Then I can call it anytime I want in my program, Okay, and one last thing is that if you remember when we used variables, I told you that you have to use meaningful names for variables. So it's going to be much easier for you to read your code later and for other people or so to read your code. Well, that's the same thing for functions. If your function is going to say hello, then just name it, say hello. If your function is going to initiate a motto, then call it, for example, in its motto, okay, try to make the name of the function as explicit as you can. 18. Functions - Parameters : The function you have seen in the previous lesson is very simple, and it will do the same thing every time you call it. You call it three times, is going to say hello, test three times. Now, you can add parameters to a function to make it more dynamic. But parameter is simply a variable. You're going to pass to the function when you call it. And then inside the function you can use that variable to do anything you want. So let's add a parameter, let's say for example. So I'm going to remove that. Let's say we want to greet the user. Let's say Hello, username. So I'm going to add a parameter. And where do we add parameters here? The parenthesis. So for example, std, string, username. So to add a parameter to a function, you first need to put here the data type of the parameter and the name of the parameter. And so what's going to happen here is that when you call say hello, you are going to provide a string which is username, which is going to be a variable username in that function. And then you can use username. So for example, I can say hello, and then username, and then endline. So I can use the username here that I got from the parameters. And so now as you can see, I have some arrows here. Let's run actually the code to see it. We have an error, for example, here, too few arguments to functions say hello. Because now the say hello has one argument. You need to provide one argument which is going to be the parameter. If you just call, say hello without any arguments, without any parameter, that's not going to work. So you need to provide one argument which is of type string. So I'm going to say Bob. Okay? And this is going to, kind of course, I need also to put it here. Let's say John. And let's remove that. And let's run that code. You can see now it's working. And I have Hello Bob, Hello John. So the function, as you can see, as the same code for running two different things, okay? Because of the parameters you pass, you can customize the behavior of the function, okay? So that's very useful and you're going to use parameters all the time. You can also add multiple parameters as you want. There is no limit to that. For example, int, user age. So now it's going to require a string and an integer. So for example, hello username, and then you are. And then maybe I can go back to a new line here. And but the user age. So hello username, you are user age. Okay, I forgot, this is better. And now you can see I also have an error, too few arguments in function call because now I need to provide a string and a need to provide a integer, which I'm going to. So I'm going to run the code and you can see Hello Bob, you are 34. Hello John, you are 36. So that's how you can add parameters to make your functions more dynamic. One very important thing now also is that you need, so when you call the function, you need to provide the parameters in the exact same order, Okay, As when you define the function. So the first parameter is going to be the string username. The second parameter is going to be the integer user age, okay? For example, here, if I do 34 and then Bob, well, we are going to have a problem first because here it's waiting for, and you can see here it's waiting for a string here. And we are giving an int in here while it's waiting for int and we're giving a string. So if you have the two same datatypes, maybe that's going to work. But then you're going to have some weird behaviors in your code. So make sure that you always respect and you know, what is the order of the parameters for our function. So Bob, 34. 19. Functions - Return Statement: Great. You can now create functions called them and add parameters to make them more dynamic. Now what you can also do is to make a function return a value. And we already have one example here. It's the main function. You can see int. Here we have int, which means that the main function we return an int value and then it returns at the end. So let's create another function here. For another example, I want to create a function that will return the triple of any number you give it. And that's going to be also it. So int, let's say triple number and int number. So this function here, when you read the declaration of the function, you see int, which means that this function will return an integer. So in the function you should have written. And then an integer, then the name of the function. And we have here one parameter which is a number we pass to the function when we call it. So what I'm going to do here, I'm going for example, to create int. Result is equal to number times three, okay, to triple the number. And then I do written result, wave, a semicolon. So when you call triple number, is going to triple that number and return the result. Now as a small improvement here, the thing is that we create a result variable and we just return it and we don't really use it. So what I can do instead of creating a result viable and returning that variable, I can directly return the result which is number times three. And I don't need this line anymore. So as you can see, this function is quite minimalist. And now I'm going to call that function. So let's say we have say hello. And now I'm going to do for example, triple number of four. And the thing is that, well, this function is going to return some value which is of type integer. So what I can do is, let's say int result is equal to triple number four. And then, so this variable is going to receive what you written with the written statement in the function. And then I can use this. I can, for example, do STD C out results and then STD endline. Okay, Let's run that. And you can see, so we have the hello lines and then we have 12, which is the triple of four. And so, well, here we have used int. You can also use double, you can use Boolean. You can return a string, you can return a vector of anything. You can return anything you want. Just make sure that what you written corresponds to the return type that you have chosen for the function. And as you can see here, we have a very specific written type is void. In void function, you don't have written when you could have written like this, okay, if you want to just exit from the function, we use return, it's going to exit from the function. So at some point you may want to use this just to exit from the function, but this void is not going to return anything. And well, to go a bit further, one thing you can also do is you can call a function inside another function. So let's say create a function void, print triple number, int number. So this function, the goal of this function is to print the triple of the number that you pass to the function. So what I'm going to do, I'm going to do STD C out. And then from this function I'm going to call triple triple number. And I'm going to pass the number with STD endline. So as you can see here, when you call print triple number, I'm going to do that. Here. I'm going to remove that prints tripled number of four. This is going to call print triple number, which returns nothing because void. So four is going to go to the int number, so do the parameter, and this is going to create a variable inside the function so we can use number. What I do here is I call triple number, which is another function. And I pass number, I got here to the triple number. So this is going to go inside this parameter of viable. And then this is going to return number multiplied by 3. So this at the end will be evaluated to 4 times 3 will be evaluated to 12. And then we print with c out, we print 12 and a new line. So if I run the code, you can see we have 12. And so this using function inside other functions is going to allow you to create building blocks that you use on top of other building blocks, etc, etc. Alright, so that's pretty much it about functions for now. So datatype, you want to return the name of the function, different parameters, and then you do whatever you want in the function. And nice, you have two written something, you use the written statement. And here as you can see, you have two kinds of functions. Mainly those function who are just doing an action and don't return anything. And the functions which are going to compute r gets a value and then return that value. 20. Variable Scope: There is one important thing I want to talk to you about before we continue. And this is the scope of a variable. So depending on where you create a variable, it may or may not be accessible from other parts of the program. This is what the scope is about, the visibility of a viable. And let's just be something with an example. Let's just say that here. In print triple number, I create a variable a, so I just declare it. Okay, you don't initialize it. And now in the main function, and doing a is equal to two. So I declare it here, I initialize it here, or I just modify the value in the main. Now what is going to happen? You can see a was not declared in the scope. Okay. Again, see the scope here. So we have an error because a was not declared in the scope and we can't access a. So from what you have seen before, well, you have seen that you can use a variable in any line after the line where you've declared it. But as you can see here, when you declare a variable inside a function, well, this variable will not be available from outside of the function of other functions. And the rule is actually more general than that. So now let me explain how the scope works. So in C plus plus, it's quite easy to see that. You can see we have many blocks of code, okay? By a block of code, I referred to a block using curly brackets, okay, So this is a block of code. This is a block of code. This also, and this also inside a function you can also create. For example, here I could create another block of code. And that's something that we're going to see later on when we work with conditions and loops, this is going to create new blocks of code, wavy, curly brackets. And now the rule is that, well, when you declare a variable, so I'm, I'm talking about here, declaration of the variable. This variable will be accessible from the current scope, which is the current block, okay, this is the scope of the variable. And from any scope inside the scope. But it is not going to be available from any scope that is outside of before the scope. So if you want to go from this scope to this to that scope, you need to go out of the first scope and then you lose the visibility of the variable a. So now for example, let's say that instead of declaring the variable a here, I declare it here. This, when you declare a variable outside of any function just like that, this is called a global variable, which means that it's going to be available globally. And then I can do, for example, a is equal to 3, a is equal to two. As you can see, I can get access to a because here it is declared here. This is a scope that is more nested than this one. So the scope here is basically the scope 0. And then this one also is a scope inside the main global scope. So we can get access to a here and here, and also in that new scope, okay? A is equal to four and I can modify a inside this group, which is inside this one, which is inside this one. All right, For example, let's say I create a variable beak here. I can use B in this scope, so I can use the afterlife. They can do b is equal to four, and I can also use B here. B is equal to 5. Okay, that's going to work. And now if I do int c, As you can see, it does the same thing here. C is not going to work. Why? Here you can see we will have an error. C is undefined. If I run this, you can see C was not declared in this scope. Because here we have a more honest in scope. We declared a variable c, and then we try to access the variable C in a less nested scope. Alright, so that's the rule about the scope and that's a very important rule. And know where, as you can see here, something that you can see when we create parameters for functions. Actually, what's going to happen is that this parameter int number. This is just like if you create a number of viable int number variable inside the triple number function. So any parameter here will be a variable, and this is going to be what we call a local variable inside the triple number function. So the number, for example here viable is going to be created here, is going to be used inside the scope of this function. And after that is going to be destroyed. And it's only going to be available between this curly bracket and this curly bracket. So as you can see, we have two functions. Both of them have a int number variable, but this is not a problem because this is actually different than this, okay? You can have two different variables with the same name in two different scopes, okay? As you can see the number here, it's that one. Number here. It's that one. If I create another int number in the main function, that's going to be yet a different variable because this is one scope. This is another scope, and this is another scope. So three different scopes, three variables with the same name that were declared and created in the three scopes while those three different variables. So to recap, when you create a variable, pay attention to the scope. Variable is only accessible in its own scope or in any nested scope inside its scope. Thus, you could have different variables with the same name in different scopes. So a very important question to ask yourself when you create a new variable is, where does this variable exists? And in the current scope, I'm writing code in. Can I access this variable? Knowing this will help you understand some errors when you get started and later on, avoid those errors. 21. Comments: One important thing in programming is to make your code easier to read and easy to understand. It shouldn't take long for someone else to get what your code is about and what it does. So of course, the first thing to do is to write clean code. But what you can also do on top of that is to add what we call comments in order to add some notes to your code so you can explain some parts are simply tell what you're going to do next in your program. And so to create a comment, you can create a comment anywhere. To create a comment, for example, here you are going to use double slash in anything you write. So this is a and you can see here the color is different in a commented line will basically not be executed. So this is just like a node in your code. Again, for example, here, while we have a say hello, we could add comments before say hello to say what this is going to do. For example, say hello to user with a username and age. So here that's pretty explicit. Okay? But we can add a comment to say what this function is going to do. And so you can add comments anywhere you want, and you will see many comments if you browse some other codes you find on the Internet are indifferent. Project. For example, this, we could say compute triple of given number and print it. Okay? So you can add some comments here for functions, you can add comments inside. This is a comment. You can add a comment inside a function, you can add a command. You can also add a comment after a line. Just need to do slash slash and everything after the line here you can see will be commented. You can start by writing instruction and then add a comment. And comments can also be super useful. So for example, if I run this, okay, I have Hello Bob, hello John, and 12. Let's say I just want to try the print triple number. In this case, I would have to just remove those lines of code. What I can do instead is just comment this line and comment this line. As you can see here, this line is now a comment and also that one. So when I run the code, I just have 12. Okay? And if I want to run this, I just need to remove the commands. We're going to add it here. And you can see now we just have Hello Bob and 12. So adding comments can be very useful when you want to test some parts of your code. Okay, you don't need to write and remove the code every time you can just put comments and then change the comments. So quick recap about when to use comments. Well, if it is hard to get what a part of the code dose, then you can add comments to clarify it. You can add some warning for any other developer would like to modify specific coding the future are really anything you want. You can also test different parts of your code. And if it can make your code easier to read and to understand, use comments. 22. Using namespace std: As you can see, anytime we want to use something from the standard library, we need to add std and two columns. So for example, std cout, std endline. If I go back to level one, for example, in arrays, we have so std cout or the time std vector, et cetera in STD seen well std, string, std all the time everywhere. And this, the name std is actually called a namespace. So very basically put a namespace is useful, for example, to group several functionalities of a library together. So for std string, std vector c out C, etc, everything is under the same namespace. And this can help you, for example, avoid getting naming collisions when you develop, let's say you want to implement another C-out function, but right here, which is not the STD C out function, which is another C-out function. Well, if you do so in the same namespace, that's not going to be possible. If you do so in a different namespace, then you have two different functions in two different namespaces and there is no problem, no collision. So you can easily create a new namespace and let's just create one here for an example. So namespace, Let's say ABC for test. And then you're going to put curly brackets. So open and close curly brackets and at the end, but a semicolon. And well that's it. You have a namespace, so everything you put inside is going to be in the namespace ABC. So for example, let's say put triple number. So I'm going to cut this and put this here. Actually what I can do is I can select everything and press Tab to add an indentation because now this is inside a namespace. Okay? So that's going to be better like this. Now triple number doesn't exist in the global scope, so you can't just call, as you can see, triple number here, undefined. What I need to do, I need to do a, B, C, and then colon, colon triple never. Triple number is now in the namespace, ABC, so ABC triple number. So you can see that basically how the std namespace was created just like that. And if I create, for example, let's say just void C out, okay, which is going to do nothing. Here. I can do, for example, let's do ABC C out, and I can call ABC C out, our STD C out. Those are two different functions because two different namespaces. Okay? And now that you understand the basics of namespaces, well, the thing is that I'm getting to the point of this video is we don't want to use std colon, colon every time we want to use the standard library. Because what? We are going to use that library a lot, and that's going to add a lot of additional code. For example, if I go to basic level 1, Let's go to user input. Well, you can see we have a lot of STD or STI, STD all the time for arrays. Well, STD, STD all the time. So that's going to bloat the code a bit and make it less reliable. So when you're using the standard library or std, what you can do is you can add one line at the beginning here, so you don't need to put std before, and this is simply, so I'm going to put it here using namespace, std. And by doing this using namespace and then the name of the namespace, it's like you kind of included the namespace here and you don't need to put std. So I can remove that C out and just endline like this. I can remove STD and that's going to work. You're going to know that it comes from std because I have using namespace std. So I can do this. Okay, I can do this, but you can see I can't remove ABC here. Triple number is not going to work because I still need to use namespace ABC. If not, I can do using namespace ABC. And That's going to walk here. But then you can see if I put using namespace, ABC and STD, The problem is we have a naming collision because you can see C out is ambiguous. Because we have a BCC out and we have STD C out. So you can see the problem you can have when doing this using namespace is that you can add some collision problems between different names. So what I advise you to do is not using this using namespace unless you have a very common. For example, the std, which is the standard library, which will allow you just to remove that std here. I'm going to add this here. So that's going to allow you to make your code much lighter. And for other namespaces for your important, the one I've created here. Well, in this case, I use ABC, we've tripled number. So to recap, you can see how a C plus plus program can be organized into namespaces here because we're just getting started. I'm not going to give you a huge amount of namespaces out around the place in the following of this course, this lesson was mainly here so you can understand what is this std colon, colon for the standard library and why and how we can write using namespace std to simplify our code a little bit. 23. C++ Level 2: Exercises: And let's now practice with what we have seen in this section, specifically wave functions. So the first set of exercises is actually to rewrite the previous exercises. So from level 1 you had three exercises using this time functions and also using the namespace std. So you don't need to write std everytime. Okay, so let's have a look at those exercises once more. So the first one is to ask for the name and age of the user. So you're going to create a function that takes the name as a string and age as an integer and print the info. Actually, that's what we have just done when explaining the functions. But as an additional practice, you can do it one more time then for the exercise number 2, when we ask the user for two integer numbers. So you can do that in the main function. Then to add the two integer numbers, you can create a function, for example, add two ints or something like that, and then print the result in the main for the exercise 3, where you're going to create a function that will compute the average of a vector. And you are going to pass a vector as a parameter to the function. And then, well, whatever code that was used to compute the average, you're going to put that inside the function and return the average. And then, well, those are the 31st exercises and have new exercise for you, which is exercise number 4. You're going to create a function to convert from Celsius to Fahrenheit degrees. Okay, So I'll let you think about what name you could give to the function, what datatype you could return, what parameters you need. And here is the formula. So if you want to go from Celsius to Fahrenheit, you need to multiply by 1.8 and then add 32 to the result. And you have the Fahrenheit degrees. All right, so for each exercise, I'm going to create a new file. So you can do the same file number 1, 2, 3, 4. And then, well, I will see you in the next lesson for the solution of those exercises. 24. C++ Level 2: Exercises - Solution: This is the solution of the four exercises I have given you in the previous lesson for the level 2 of this C Plus Plus goods. So for the first exercise, let's create a new file named, let's say 2.1. So to underscore one, and let's say user name, age dots. I'm going to go back to level 1 and take the 1.1 and just take this code. Okay, because we're going to take this code and make a function out of it. And so what I can do here is actually from my functions, I already have a function say hello. So I'm going to take that function say hello. Okay. Let's not reinvent the wheel, but that you could write it by yourself, say hello with the username and user age. Thing is that you can see we have some arrows because I need to use here using namespace, std. Because if I don't use that, what is a string? What is SIADH? We would need to have std, cout, std, string, etc. And then we'll maybe what I'm going to do, I'm going to keep that say hello function and I'm going to create a new function, void Greeks user. And this will be responsible for getting the information we've seen. Okay, and then say hello. So what I'm going to do is I'm going to take this code, but it here. And I'm going to remove std because I don't need std anymore here. Okay? So this, what we do is we create a username, user age variable. It will ask what is your name? Okay, we've seen our diet. Another we've seen, and then what I can do is I can call, say hello, passing the username first, then the user age, Sigmund. And as you can see here, that's another example of the scope. I have the username variable here, the username variable here, the user age, he unusual h here, but those two are different scopes. So that's not a problem. I can use username here and here. That's going to be two different variables and from the main. So usually I like to keep my main quite minimal. I'm just going to call great user. Just like that. This is a void. So we don't return anything. And simply grid user, which is going to ask for the user info and say hello. Okay? And we don't have STD anywhere. Okay, that's great. So now I can run that. What is your name? How old are you? Let's say 87 and LOL you are 87. So the code here might seem a bit longer, but it's much better because you can scale that code later. You can reuse different blocks of code. And the main is very minimal. Alright, now let's go to exercise number 2. I am going to create here a new file to add two ints that CVP. And I'm going also to go back to level one. And just but this code here inside the level two. And here what I'm going to do, I'm going to keep that in the main, okay, to enter number one and number two, I'm going to create a function for number 1 plus 2 to add two ints. Okay? So I'm going to create a function here, and I'm going to first choose a datatype. So we are going to add to install the result will be an int. I'm going to name it, add two ints with int number one, number two. And then I'm going to do return number one plus number two with semicolon. And then here I'm going to do sum is equal to add two ints of number one and number two. An actually because I just create some and just use it once and nothing more. What I can do is directly call the function here instead of some interest, remove that because I don't need this and maybe go back to a new line yet here. And so now we have the function, add two ints that we can call as many times as we want in our program. Let's run that. It's working and actually I also need to use, so using namespace, std. So I can remove the std here for c in and c out and also for end like so the code is easier to read. Now. All right, let's go to exercise number 3. I'm going to create here in phi 2, 3 average. So compute average that CVP. And let's go from 1.3, compute average. Let's copy and paste everything into the new file. I'm going also to do directly using namespace, std. And here I'm going to create a function that will return the average from a STD vector. So because I'm going to return an average, the average, as you can see here, is a double number. So I'm going to do double compute average from list. And I'm going to pass a vector. So instead of std vector, I can just put vector. And then I'm going to put double like this nevertheless. So that is the function double datatype and then a vector with double as a parameter and a meaningful name. So we know what this is about. So then what I can do, I can first compute the sum here. With this. That's going to be the same instruction. We accumulate. Well, I've used number list here and here. So those two are different variables because of two different scopes. But because that's the same name, I can just copy directly to instruction. And then once I have the sum, I can directly return the sum divided by the size of the list. And that is the average from the list. So now I'm going to remove those instructions. And I'm going to say double average is equal to compute average from lists. I'm going to pass number list. And I'm going to remove STD. And I'm going to move std here and also here. And just put like this. So now as you can see in the main, we just create the list and then we have a function to compute the average, and then we just print the average. Let's run that. And you can see average value in the list 6.05. So that's working. And finally, let's go to the Exercise number for me to call that. And I'm going to do new file to four, which is Celsius to Fahrenheit, that CVP. So I'm going to do include iostream because we're going to use c out. I'm going to use using namespace, std and create the main return 0. And what I'm going to do, I'm going to create a function that is going to convert Celsius degrees to Fahrenheit. So when we use degrees, usually we have a decimal point. So I'm going to use w. And then we're going to name it very simply Celsius to Fahrenheit. So that is something that I often use, is when you want to convert something to something where you just put the firstName and then two and then the signaling. So that's very explicit. If you want to convert, I don't know, like meters to feet are radians to degrees or anything else. Well, that's very convenient to use that convention. So this of course, will get some Celsius degrees. So double Celsius degrees, that's what we are going to get from the parameters. And then inside the function. So I open close curly brackets. I'm going to do written Celsius degrees. So from the parameters multiplied by 1.8, and I'm going to add 32. In fact, I'm not going to add just 32. I'm going to put 0, okay? Because as you can see here, 3200 is a double number. If I add 32, that is an int number. And when you work with double number, it better to put everything in w, okay? Because with int, you may have some weird behavior simply because when using int, it may truncate the numbers. So let's say the result is 68.7, you're just going to get 68. So if you want to avoid that, when you use double, well use double for everything, okay? Double, as you can see, double and double. And now, well, I can say, for example, C out, let's say 20 Celsius degrees is equal to and then put Celsius to Fahrenheit, we've 20. And then let's put Fahrenheit degrees and Enlightenment. Let's see what we get here. And so here, well, that is just a problem of printing character in the terminal. But as you can see, we have 20 Celsius degrees is equal to 68 Fahrenheit degrees. And now let's try with a different number. For example, 15.6, we're going to get 60.08. And of course, I need to change it here, so 15.6 and we get 60.08. As an improvement, you could also create a variable here. So you can just print this and pass this as a parameter so we don't need to write this and this twice, okay, as you can see here, and we don't get any error when we print the result. And then well, you can just copy and paste this line and choose different values. You can call this as many times as you want anytime, anywhere in your program. All right, so that's the end of the exercises and that's the, and also of the basic Slavic 2 for the C Plus Plus course. And now it's the time to go to the next level of the course. 25. C++ Basics - Level 3: You can now create reusable blocks of C plus plus code with functions and variables. You also know how to make your programs more readable and maintainable for the future. Let's now go to the next level, which will complete the core foundation. You need to start with C plus plus. Note that it's important you feel comfortable with what you've learned in the previous lessons because that's the starting point for this section. If you have any doubt, re-watch some of them before you continue. So in the following lessons, you will discover mainly conditions and loops. Those will allow you to create many different execution paths for different runs of your program. Let's say you want to ask for the user age and then display a different message depending on the age. Or you want to get a list of temperatures you don't know in advance and compute the average. Well, for that, you would need conditions and loops. And as you will see, it won't take much time before you can use those new concepts correctly in your C plus plus code. So at the end of the section, you will be able to add a lot of dynamic behavior and your sibling programs while controlling the execution flow. And let's get started right away. 26. Conditional Statements with Booleans: For this new section, Let's create a new folder here. I'm going to say new folder, name it Basics level 3. In this, I'm going to create a new file. Let's name it main.cpp. All right, and let's include iostream and int main. We have the return 0 minimum code. And let's come back a moment to the Boolean datatype. In this lesson, I am going to show you how you can make some tests, get a Boolean as a result. So this will be called conditional statements. Conditional statement is a test to make to get a Boolean as a result. And this will be the foundation for using loops and conditions. So we have our minimal code here. I'm going to come back to Boolean. So let's just print a Boolean. Let's just do C out and then true. And then let's say enlightened, okay, and I'm going to do C out. False enlight. Of course, if I use directly see out, I need to do using namespace, std. Okay, we just print true and false and return. Let's run that. So you can see true will give 01 and false will give 0 when it's printed. Okay? And those are the only two values you can have in a Boolean, true or false. Now what I'm going to do, I'm going to do C out and then bull alpha. Okay? And this is not really something important you have to learn, okay? This is just a landing you can add if you want that when you print a Boolean, instead of getting the values 10 on the terminal, you can see we are going to get true and false. Okay, so that's going to be easier when you debug offer meaningful in this lesson, when I want to show you different stuff that we can do with booleans. But in the end that's not going to change anything, okay, For your code and you actually are not going to use that in real life. So just for debugging and for this example. So now we have true and we have false. What I can do. So I'm going to remove this. I'm going to create a first conditional statement. Let's say I want to test the equality between two values. What I can do, for example, I want to test if one is equal to one. So what I can do, I can put parenthesis and then I can put a value, another value. And then to test the equality, I'm going to put two equal signs, okay? Two equals signs and not just one, that's important. And this is going to be evaluated, as you can see, I'm going to run, is going to be evaluated to a Boolean value in here. It's true wade through because well, one is equal to one. So that's a conditional statement. Now for example, let's try is one equal to two? Well, this is not true and you can see we have the value false. Okay, so for conditional statement, logic and logical thinking is very important. And so this is what you are going to use inside conditions and loops to control the flow of the execution. So now we have the equality, okay, we can also test the inequality. So the inequality will be exclamation mark equal. So is one different than 2? Yes, that's true. Let's verify that you can see this is true. And also you can see with Visual Studio Code you get some help. You can see that this, when you put your cursor on the parenthesis, this is a boolean, which is true if I put is one different than one. You can see now we have Boolean that is false because of course one is equal to 1, so it's not different. So we have the equal and the difference. We can also compare, for example, with this is one lower than two. And actually this means strictly lower. So let's try that. You can see that one is strictly lower than two. Now if I put one here, one is not strictly lower than one, so it's gonna get false. And I can also add an equal sign here, which means is one lower or equal than one? So in this case, it's going to give true, you can make some comparisons between values, okay, using the strictly lower than, the lower or equal than. And of course you have the opposite. You can test if it's strictly greater than or greater or equal than. So you have six operators. The equal operator that different than operator, strictly lower than, lower or equal, and greater than. So strictly greater than and greater or equal, you have six different ones. And here I have only tested using integer values, but you can also test using different datatype. For example, 1.01.7 is greater than one, okay, That's true. So you can test with integer, with double numbers, but you can also test, for example, with strings. Let's say I do hello, hello, hello. So this will give us true. Then let's say put an advocate here. So is hello with lowercase equal to hello with advocates. And that's going to give us false. 27. Combining Conditional Statements: Okay, so now you can write your own conditional statement and get a Boolean value as a result. What you can also do is to test a combination of multiple conditional statements. And let's continue with this example to see that. Now I'm going to go back to my one is equal to one, and I'm going to add another condition. Let's say I want to test if one is equal to one or if three is equal to four. And I will need to add some more parentheses here. And let me explain to you what I did right here. So this symbol here, the two pipes is actually the operator. Okay? So for operatory you need first conditional statement and another conditional statement. So we have one big conditional statement which contains a combination of two smaller conditional statements. Okay? Now what's going to happen is that with the O operator, the global statement will be true if at least one. The conditional statement inside is true. So here, one is equal to one, that is true. And you can see here Boolean true. Three is equal to four, that is false, but because at least one of them is true. Well, you can see if I put my mouse here, the global conditional statement is true. And if I run that, you can see I have true. So if both of them are false, the conditional statement will be false. But if at least one of them or two of them are true, is going to be true with the or operator. And then you also have the end operator. The end operator means that both this one and that one need to be true in order for the local conditional statements to be true. So as you can see here, if I run this to me, this false, because while this is true, this is false. So the combination with the end operator, which is two ampersand, is going to be false. If I put this, this is true, this is true, and the combination is going to be true. Okay? So you have here you can see or which is with two pipes in end, which is with two ampersands. Let's do another example. Let's say you have a viable, a double temperature which is equal to 25 degrees, let's say 0, because this is a doll. And I want to test if the temperature is between 20 and 30. What I can do is I can say temperature is greater than 20 and temperature is lower then 30. So here, strictly greater, I can put may be greater or equal. So that's 2100 will be accepted. And here strictly lower. So the max value is 29.999 something. So this will test if the temperature is greater than 20 and if it's lower than 30. So basically if the temperature is between 20 and 30, Let's run that. You can see now it's true. If I change the temperature to, let's say 35. I run that again. Now that is false. All right, and now that you understand the basics of conditional statements, Let's use them with conditions and loops. 28. Conditions with If: In a C plus plus program, what you have seen for now is that all the instructions are going to be executed one by one. With the if structure, you will be able to execute only some instructions if a condition is true. And to build those conditions, we are going to use the conditional statements we have just seen in the previous lesson. So I'm going to remove that code here, and I'm going to create a new variable. It's an int. User, age is equal to 23. And I'm going to do an if statement here to test something that's say I want to test if the user is an adult. So if the user is more than 18 years old. So I can do if in the end parentheses, user age greater or equal than aging. Okay, So that is the conditional statement that we have just seen before. And then I can open and close curly brackets. And I'm going to put some code inside the curly brackets. And this is the code that's going to be executed if that condition is true. So for the curly brackets, well, you have two choices. Basically, it doesn't really matter for the execution of the program. It's small for reading ability. You can either, for example, open it here, could just after the condition, or you can open it here on the next line. Okay, like you would do for a function here. So what I usually prefer is just to put them here, okay, So I opened it here, I close it here. And let's say I'm going to say C out. You are officially. And then in line. So that's how you write if it's quite easy, the if keyword, okay, you can see it should turn a different color on the IDE and then conditional statements. So the exact same thing we have seen before, open, close curly brackets, and then some instructions that you agreed to do only if the condition here is true. Okay? I'm going to add another C out here. And so we're going to print end of program just before were written. This line is going to be printed every time because it's not in a structure. Okay, so let's run that code. Run it here. And you can see you are officially an adult and of program. So what happened here is that we have a user age of 23. And then we test if the user age is greater or equal than 18. This is true because the user age is 23. So if this is true, we execute this line. So we print you are officially an adult. And then after the, if we go out, we continue on line 12 and 13, etc. Now, let's say I change this instead of 23, 8, but 16. And I run the code again. You can see now we have just end of program. So what happened is that, well, we have user age which is equal to 16. We arrive to the, if we test this and you can see that no, this condition is false. So if this condition is false, the block of code next to it is not going to be executed. So after this line, we are directly going to go after the curly bracket here and execute the next line, which is end of program. So this line is not executing. And well here we have a quite simple conditional statement, but you can make it as complex as you want, just using the difference operators and also using the O and the end to test multiple conditions together. And finally, one thing I want to come back to also is the scope. So if you remember, the scope is the visibility of a variable. And here you can see we have curly brackets. So if we have curly brackets, it means we have a scope. So this is a new scope inside the scope of the main function. And so the use of age here is declared in that scope. And the scope of the if is nested inside this scope. So here we can also do, for example, C out user age. I'm just going to print user age, just going to put it to 27. So it's going to work. And you can see that we can print 27. So we can use the user's age inside this code because this is a nested scope inside that one. Now, let's say that I'm going to create a variable int a. And I'm going to try to modify a after the if. And you will see that we have a problem because a was not declared in the scope here on line 14. Because once again, this is a monistic scope. So you can't declare a variable and use it outside of the scope. Okay, So I'm going to remove that. That was for the example. Okay, so very important. Make sure you pay attention to the scope always. So to recap on, if an if structure will allow you to decide to execute or not a set of instructions. And the decision will happen directly during the program execution. To make decisions, you can use any combination of conditional statements with any data type. 29. Else, else if: Let's now improve this if structure here. So we can execute this block of code if that condition is true. But also what if you want to execute a different set of instructions if the condition is false. Well, in this case, you also have the else keyword which goes with if. We have an if else structure. So when you put the if after that, after you close the curly bracket, you can put directly an else open and close curly brackets. And that's a new set of instructions that's going to be executed only if the condition here is false. So here I can put, for example, C out and you're not an adult yet it because in this case the age will be 17 or lower. So if I run this, let's run this with 27. You can see we have you officially an adult and this block of code is not executed. So what's happening here is that if structure, it's going to check if that is true. If this is fluid's going to execute this and then exit the structure. So the if structured accomplish structure ends here. So after executing this line is going to go back to line 15. Now if this is false and you have an else, is going to go to the else, and he's going to execute this and then exit the if structure. So now let's say put 17 and I execute this. You can see you are not an adult yet. So this was not executed, but this was executing. Okay, So if else very common in siblings plus end in programming in general. And you can also add intermediate conditions, okay, using the else if keyword. So let's see that with an example I'm going to change here the condition I'm going to say if user is strictly lower than 18, and I'm going to say, you're not an adult yet here. And then I'm going to say else, if user age is greater or equal than 18, I'm going to put parentheses here to test condition. And user age is strictly lower than 30. Okay? Make sure you have the correct amount of parentheses here, okay? One for this 11 for this conditional statement and one for the global one. And then I'm going to say C out. You are an adult below 30. Okay, I can add another else. If let's test. User age is greater or equal than 30, end user age is strictly lower than 40. In this case, I can say that you are in your 30s. And let's say I want to end here, I can put an else which says that you are 40 or more. And in this case you can see I have if else, if else, if. So, what's going to happen here is that the first one you have if the first condition is going to evaluate it, if this is true, that block of code is going to be executed. So that entire block of code with as many instructions as you want. And if this is true, well then after that we directly go to the next line, which is going to be line number 21, because we don't execute any of the rest. Okay? But if this is false, we go to the next elseif. If there is one and we check the condition. If this is true, we execute this and then we exit the complete block. If this is false, we continue and we check that one. If that is true, we execute this. If that is false, we go to the next one. And when you have an else, and else means that if you have not entered any of the previous blocks, because all the conditions are false one by one, then you are going to execute the else, no matter what. So here, if I use 70 and I'm going to get, you are not an adult yet. We're just going to execute this. Now if I put, let's say 37, I run the program. You are in your 30s, okay, because if I put 37, this is false. So we try the next one. And this is going to be false because while we have user age greater or equal than 18, okay? But we have user age strictly lower than a 30, which this one is not true. So the combination of the two with the end keyword here, the ampersand. Ampersand is going to be false. And so we go to the next one and this one is going to be true. So we enter that one. And if I put, let's say 77. Now we have, you are 40 or more because this is false, and then this is false and then this is false. And finally we get to the else and we execute what's inside the else. All right, so now you are able to use an if structure to choose what to execute depending on different conditions. This will allow you to make your programs much more dynamic. 30. For Loop: Let's now discover what our loops and how to use them in cplusplus, starting with the for loop. And let's first understand actually why you need loops. So here I have created a new program and you see plus, plus program. We've, as you can see, 10 C out with hello. So I want to print hello ten times. So I'm going to run out and you can see we have hello printed ten times. But, well, that's really not convenient. And here we just need to print hello ten times. What if I tell you that you have to print hello a 100 times or 1000 times. As you can see, that's not going to be very practical. We are going to have big problems when we want to scale the code. And so for that, we can simply use a for loop. So let's actually see how to do this. I'm going to just remove everything and I'm going to do something to write the following first and then explain to you how it works. So the for keyword and then int I is equal to 0 semicolon. And then I lower, strictly lower than 10, for example, semicolon and then I plus, plus. And then I'm going to open and close curly brackets, okay, for a new block of code. And I'm going to do C out. Hello, and then inline. Okay? And with this, I am going to run that code. And you can see we print hello ten times. So this code is the same as the previous one, but here we'll just three lines of code and we just write the instruction once. So now let me explain to you how to write a follow-up. So first you have the for keyword and then parentheses. In the parentheses you have three different things separated by semi-colon. The third thing is the initialization of the index. So we are going to use an index to go through the fall. And here I simply create an index. So int i integer, which starts at 0. Okay? The second thing in the for loop is the condition. So this is a condition actually to check. And while this condition is true, we are going to continue to go through the following. So here the condition is that I must be strictly lower than ten. When I is equal than 10 or greater than 10, then we're going to stop the top. And then the third key action here after the last semicolon is what we are going to do with the index every time, with every iteration of the loop. I plus, plus simply means that we are going to add one to i, okay, So in C and C plus plus actually, when you write I plus plus or plus plus, if I do I plus plus, it's the same as if I is equal to I plus 1. So I just add one to the variable. Okay? So here let's check the flow of that program. So we enter the for loop. I is equal to 0, and then we check, is I strictly lower than 10? Yes, because 0 is strictly lower than 10. So we enter, the for loop, will print hello, and then we come back here. So after this here, when we exit this block of code, we don't continue the execution here. We go back to line seven and we execute the for loop again. But this time with I plus plus. So this time I is not equal to 0, but i is equal to one. And we check is one strictly lower than 10? Yes, so we continue. And then we go back here. I is equal to two, which again 3456789. So at 99 is still strictly lower than 10, so we continue to execute. And then I plus, plus, so I will be 10, and then we have 10 strictly lower than 10. This is false. And because this is false, we are going to exit from the for loop. So in this case, we are going to start, in this very specific case, we are going to start at 0 until nine. And when we reach ten, we go out of the loop. So in the end, we are going to execute this ten times. And in programming that they're important, as you can see, we don't start to count at one. We start to count at 0. Okay? So if you wanted to count from one to ten, you actually going to come from 0 to nine. Okay, so that's how it works. And actually here, so you have a i, okay, you have int i variable inside the for loop. So in some situations that may be very useful to use the index, okay, when you enter the for loop, for example, I can do L0 and then, but I don't just going to print hello, hello, one, etc. Let's run that. You can see Hello 0, 1, 2, 3, until Hello nine. And here you can clearly see what is the value for the index every time we enter the follow-up. And one last thing I'm going to come back again to the scope. Okay, So you have seen that with if, because you have a new block of code with curly brackets, you have a new scope. Well, that's the same thing we follow here. You can see we have, so we don't need to create a new variable to test that. We already have a variable here, int. This is created and this is in the scope of the four loop. If I try to do let's say aye. Aye. Outside of the for loop. Well, the thing is that you can see I is undefined and we have the error. I was not declared in this scope. Okay, So the same thing applies for if. And for the for loop. You have a new scope and you have to pay attention to the visibility of variables with this scope. In. All right, Finish. So now we print this ten times. What if you want to print it a 100 times? Well, you just put a 100 here and that's pretty much it. So let's actually run that again. Okay, maybe save it. Okay, that's working. So sometimes with a code runner extension on VSCode, if it doesn't work, maybe you have to save the file before. I don't know exactly. Maybe that's Berg in the extension that Indian, so that should work like this. So you can see here hello, we start at 0 until Hello 99, okay? So as you can see, if we want to execute this 11010 thousand times, that's the exact same code. We just change one number here. 31. While Loop: There are two kinds of loops you can use in C plus, plus the for-loop, which we have just discovered in the previous lesson here, and the while loop, which we are going to see right now. And to explain how while loops work, I'm first going to do the exact same thing as we did here with the for loop, but using a wire. And I'm going to actually first, I'm going to keep that, but I'm going to comment those lines so they are not going to be executed. So actually to comment those lines, as you can see, I can do this and then this, et cetera. But I can also use the features of the IDE, which is just to select the line. And I'm going to press on to go on edit, toggle line comment. And you can see the shortcut here if you want to use that. And I'm going to click on that. And this is going to comment all the lines here. If I want to end comment the line, I just select the code again, Edit, toggle line commit. Okay, so that's very convenient. And now let's write the wild. So I'm going to write it and then to explain it to you, I'm going to create an index i outside of the while. And then I'm going to do wine. I lower, strictly lower than the 10, just going to put 10 right here also. And then I open and close curly brackets. I do C out. So actually let's copy this. I'm going to print hello and index. And I do I plus, plus. So let's run that. And you can see hello 0 until Hello nine. So that's the exact same behavior. So for a while loop, what's going to happen is that you're going to test a condition here, okay, so this is a conditional statement. And well, while this conditional statement is true, you are going to continue to execute the following block of code. The moment that the conditional statement is false is going to continue the execution after the block of code. So it means it's going to continue on line 16. And so here you can see the similarity with the wide and four for the same application, we create an index. So we create an index before the while loop. Int I is equal to 0. That's what we have done here in the fall. And then we check the condition I lower strictly than 10. This is the condition here in the follow-up also. And then we do our instruction and we also don't forget to increment here the index I plus plus, which is what we have done here, okay? Basically we do the same thing with a different structure. One important thing is that you don't forget this because what's going to happen? Let's comment this. So this line doesn't exist. What's going to happen if you just run this? So you create an index I is equal to 0 and you check while I is strictly lower than 10. So this is going to be true at first. Then you execute this, and then you come back here. And while this is still true because I is still equal to 0, so you continue to execute these, etc. etc. etc. I knew never go out of the loop. And this is what we call also an infinite loop and what you want to avoid in your programs. So with I plus plus here, what's going to happen is that at first I is equal to 0. So this condition is true. We execute this. Now, I is equal to one. We come back here. So this is still true. We continue to execute these 23456789, and then we execute it for nine. And then I will be equal to 10 because we do 9 plus 1, we come back here. Ten is strictly lower than 10. This is false. And because this is false, we exit the while structure and we continue the execution. So that's how a while loop works. Basically, if you want another analogy that's very similar to an if structure, okay? This is the same as doing if I is strictly lower than 10. We execute this block of code. But just at the end of the, if you continue the execution on the next line, we have a while. What you do instead is you go back to the white line and you test the condition again until this is false. So this is kind of a if mixed with a loop. And well, because I talked about the scope for if and because I talked about the scope for the for loop, I'm also going to talk about the scope for a while because again, that's the same thing. You have a block of code. So if you create any variable inside of this while loop. So if you declare any variable inside is not going to be available outside of the Y key. You can see we create, so we declare int I outside of the while loop, and we can use it inside because this is a nested scope inside the scope of the main. So that's working in that way, not on the other way. And well, that's pretty much it for the while loop. And now the $1 million question, when to use a for loop and when to use a while loop. So use a for loop when you know exactly how many times you want to execute an action. Use a while loop when you don't know how many times are. For example, if the condition to continue is external to the loop. As an example, let's say you need to ask some numbers from the user. In the first scenario, you want exactly 10 numbers. So you are going to use a for loop to ask ten times. In the second scenario, you allow the user to give as many numbers as they want and you stop asking whenever the user gives you the number 0. Here, you are going to use a while loop. And don't worry if you still have some confusion about this. In many cases, both options are actually possible just with a different way of writing the code, as you could see here in this example, with a bit of experience, the choice will become much easier for you. And lastly, if we come back to actually this example here I used with the print of hello multiple times. You can clearly see that a for loop was more appropriate because we knew exactly how many times we wanted to print the text. 32. Loops and Arrays: One thing you have to know how to do is to iterate on the list we've loops. So you can perform a set of instructions on each element of the list. I'm showing you this now because simply you are going to use this multiple times in every project you create in the future. So first, we're going to use a standard for loop and then an improved version with modern C plus plus. Let's say you have a list of temperature here. I've created one array, so vector double of different numbers. I have 1, 2, 3, 4, 5 elements which represent Celsius temperatures. And what I want to do is I want to be able to go through each element one-by-one to do any action I want. So what I'm going to do, I'm going to create a for loop here. Int I is equal to 0. So I'm going to create a for loop with an index starting at one. And then I'm going to do I strictly lower than temperature list dot size. Okay? And then I plus, plus, and I'm going to open, close brackets. So here I use temperature list dot size. So size is, you can see returns the number of elements in the vector. So here it's going to return five. So basically the condition is I strictly lower than five in we do I plus plus. So it's going to start at 0, and then 1, 2, 3, 4, and then exit, which is exactly the index of this array or vector 0, 1, 2, 3, and 4. Okay? And so what I'm going to do, I'm going to just print them out. I'm going to do temperature list dot at and then use the index, okay? So temperature list at index I, which is 0, 1, 2, 3, and 4. So I'm going to print that and let's take enlightenment. Okay, let's run this. You can see I have each value one by one. So now what I can do is because I'm going through all of the index is of the vector. I can modify the values, I can get the value, I can do anything I want. For example, let's say that I want to print all the values in, then I want to print a warning if the temperature is negative. So I can say for example, if Temperature list at i is negative, so maybe what I can do is because I'm going to use this twice. I can use double. Temperature is equal to temperature list dot at i. So I can create a local variable that I'm going to use inside the fall. And then I'm going to replace this year. Okay? And I'm going to check if temperature is strictly lower than 0, then I'm going to also print out its freezing, then endline. Okay, so let's just run that code. You can see 12.3 here, Okay, Nothing else. And then minus 4.58 freezing, and this is the second element, 1511 minus 0.4. It's freezing again. Okay? So this just to show you that you can do whatever you want, you can combine four with if you can even put that in a function. So well, you can combine everything together to make your programs more powerful and more dynamic. And here, as you can see, I have created a local variable because this will allow me to just use that variable in my block of code. Not use temperature list dot add every time. Okay, so this is going to make the code easier to read, easier to maintain. Now. So this is, I would say, a more classical way to go through a vector. I'm going to write the same for loop, but using modern C plus plus. So I'm going to comment that also. Elite toggle line comments, very practical. And I'm going to do for double temperature. And then colon temperature list. Close the parenthesis, open, close curly bracket. And then I can do directly see out temperature like this. I can do the if, if I want to, but I'm just going to keep it simple like that. And if I run this, you can see we have the same thing. We print each value and we get access to each value one by one. So what happened here? So this structure is much simpler, okay? You do four and then you are going to create, this is going to be a local variable, okay? So because we are going through a vector of double, I'm going to put double datatype can it should be the same. And then temperature is going to be the local variable that we're going to use in the fall. And then colon temperature list. This is the collection here, this is the vector we are going to use. So what? It's going to do, this for loop, it's going to go through all of the elements of the collection of the vector n. For each element, it's going to enter this block of code with the double temperature, which contains the value of the element. And so we can use the value of the element directly here in this block of code. So that is super convenient and as you can see, it's much easier than creating this and then doing temporal journalist at AI, etc. This is much simpler and easier to read. All right, so as you can see, combining a for loop with a list is an extremely powerful combination. You just need one line of code to do that. And then you can write a block of instructions to apply for each element of the list. 33. C++ Level 3: Exercises: Now is the time for another set of exercises to practice on everything you have seen in this section, we've specifically loops and conditions. So here three exercises. The first one, you are going to compute the max value inside a list of numbers. So of course you are going to use vector here. So what you can do is you can create a function, pass the vector as a parameter, and then use a loop and use whatever you need to compute the max value just to find the max value inside the vector. And then this function is going to written the max value that you can print in the main of your program. The second exercise, you're going to create an empty list. So an empty vector. And you are going to ask the user to give you exactly five numbers. So number 1, 2, 3, 4, 5. And then once the list is full, you are going to print the max value. Okay? So for that you will need to think of what kind of bloop you need. If you need a for loop or if you need a while loop, you're going to use one of the two. And when you need to print the max value, in this case, what you can do is you can directly use the function you have created in the first exercise here on the top. And the third exercise here, you are going to also create an empty list. So you're going to do the same thing, but this time you're going to ask the user not to give you exactly five members, but just to give you numbers, okay? And you're going to keep asking the user for numbers and you're going to stop when the number is 0. So when the user gives you a 0, you're going to stop adding numbers to the list and you're going to print the max value again using the function that you have created before. And for all those exercises you can just use integers if you want. Our double, well, I'll let you choose what you want to do. Solution, I'm going to use integers. Well now it's time for you to practice. If you have any doubt, again, re-watch some of the previous lessons and then I will see you in the next listened for the solution. 34. C++ Level 3: Exercises - Solution: This is the solution for the previous exercises for the three of the cplusplus course. And let's start with the first exercise. So I'm going to create a new file here, namely 3, one max value that CVP. And I am going to just create the minimum structure. So include iostream. I'm going also to include vector directly because I'm going to need vector using namespace, std, int main greater than 0. And I'm going to create a vector here. Vector int number list is equal to and just put some number, let's say 3588156 and minus six, okay, just random numbers. And now I'm going to compute. So I'm going to actually find what is the maximum number from that list. So we should get, of course 156. And to do that, I'm not going to do that in the main. I'm going to create a function here. Okay, so first of all, what do we want to return from the function? We want to return the max number. We're just going to return an integer number because we're going to pass a vector of int. And we're just going to written what is the max element, which is an integer. The name of the function I'm going to name it gets max value from number list. So it's quite long, but it's quite explicit as well. And the perimeter is going to be vector of int, let's say number list. I open, close the curly brackets. So we pass a vector of int, which is going to be numbered list inside this block of code. And we are going to return an integer. So what I'm going to do now is I'm going to go through all of the elements of the list using a for-loop, and I will need to find the max value from that. So what I'm going to do first, I'm going to do int max is equal to 0. I'm going to initialize the max value to 0. And then I'm going to do for int number, number list. So I'm going to go through all of the numbers in the number list here. And I'm going to, if number is strictly greater than the max, in this case, I do max is equal to number. So for each element of the list, I check if the element is greater than the current maximum we have. If this is the case, I just update the maximum value we have with the number that we are currently using here in the list. So after this for loop, we have been through all of the elements of the list. And the max variable here will contain the max element. So what I just need to do after that is important is to written max value. So don't forget the return statement. And this is going to return the max value from the vector that we have passed here as a parameter. So now what I can do is I can call this function directly here from the main. And I'm going to call it from C or c out, Let's say max value from number list. And I'm going to go to get max value from number list. I'm going to pass the number list vector input n, like and because this is quite long, I'm going to go back to a new line here to make it better, made me do this, Okay? Just like this. So it's very clean. We print max value from the Middle East and then the result of function. And then end of the line. Let's test this code. And you can see max value from number list 156. So that works. I'm going to keep the code like this, but also you could add an improvement here you can see that we initialized the max value to 0. So if we only have negative number in the list, well, the max value will be 0. So what you could do is you could initialize the max value to the first element of the list. But if you want to do that, you also have to check one thing. You have to check if the number list contains at least one element, okay, So if you want to modify the behavior, first, check if the number list size so that we, the site function is greater than 0. If this is true, you can say that the max value is going to be the first element. And then you go through all of the elements of the list. And if this is false, well, there is no element in the list, so there is no maximum. So maybe you can written a number like minus1 are defined a number that is going to correspond to an error code. All right, so that's it for the exercise number 1. Let's go to the site number 2 and me to create a new file, 32. I'm going to name it, get numbers. And just that one because we have the number 1 and number 2 dot CPP. So what I'm going to do is I'm going to copy this and paste that. So in this exercise, what we need to do is we need to create an empty list. So to do that, I can just do this, create an empty list. And then I need to fill the number list directly by asking the user for five numbers. After I do this, I can compute our get the max value from the number list. And this, I can directly do this using the GetMax value from numberless function I have created before. So the cost structure is the same just to fill the array, it's going to be different. And here do we need to use a for loop or a while loop? So we need to ask the user exactly five times. Because we know how many times we need to ask the user, because we know how many times we need to do the action. We can use a for loop because we know we need to do the action exactly five time. And so I'm going to do for int I is equal to 0. So let's initialize I to 0. I strictly lower than five, which means it's going to go from 0, 1, 2, 3, 4. So it's going to go five times I plus, plus. And so 45 times, I'm going to ask for the user for a number. So I'm going to create int, let's say input number. So I create a local variable. And then I do see in we've angled brackets in this direction, input number. And after that, after I get the input number, I'm going to do number list dot, push back to add a new element. And I'm going to add simply the input number I got from the user. And what I can also do here is do C out. With eyes. You can see angled brackets in the opposite direction here. Enter a number and no end line, okay, because we want this to be on the same line as this. So this is going to be the prompt. Okay, now I'm going to run this. And you can see enter a number, I'm going to be four. I'm going to give minus 7, let's say 76453. And you can see after five numbers, this automatically stops. And you can see max value from number list 76. So those are the numbers I actually gave from the terminal. And now the program has computed 76. Okay, so that's it for the exercise number 2. And now let's go to exercise number 3. So I'm going to create a new file here. Three, get numbers to that CPP. And I'm going to copy this because that's the same code. I'm just going to remove this for loop. Okay? So we start with our empty vector. We still have the function to compute and get the max value from the number list and know what we need to do is we need to ask for the user for numbers, but we don't know how many times we are going to ask. We just know that we need to ask until the user gives us the value 0. So the condition is actually external to the program. We don't know before how many times the user is going to give numbers before they are going to give the number 0. So in that case, we are going to use the while loop. And while you have different ways to solve that problem, okay, Usually in programming, you have different ways to write some code. So here I'm going to tell you just one way, maybe you always different and that's also going to work. So what I'm going to do first, and this is quite common, is an MQTT rate of Boolean. Ask user for numbers is equal to true. So basically I'm going to create a boolean that we can also call a flag. That is true. And while this flag is true, so why ask user for numbers? We are going to ask the user for numbers. And then inside this I'm going to test the condition that the user gives us 0. And if the user gives us 0, I'm going to set this to false. So then we don't enter the while anymore. So as you can see here, the conditional statement is very simple. I don't have any equality or anything. I just put the Boolean value because this is already a Boolean value. Okay? So for now it's true. And what I'm going to do is I'm going to do int input number. So let's ask for the C out. Enter a number. I can also add an instruction, for example, zeros to stop. And then, okay, and then seek in like this input number. So now I have the input number in this variable. What I'm going to do is I'm going to do an if input number is equal with two equal to 0 in that case. And when to put the flag, ask user for numbers to false. And if the number we get is not 0, I'm going to do else. And I'm going to add the number to the list, number, list dot push back with the input. So let's see what's going to happen here with this while loop. So first of all, the Boolean value, the flag ask user for numbers is true. So we are going to enter this and we are going to get the number from the user. Okay, nothing special. We test the input number with if else structure. So if we give any number different than 0, this is going to be false. So we go to the else and we add the number to the list. After this, we're going to go here and we are going to exit the while. But because this is why we go back here. And at this time, the ask user for numbers, boolean is still true. So we enter again and we continue to ask numbers. Now let's say that here we give 0. So if we give 0, we are going to enter this part of the if, because this condition is going to be true. In this case, we are going to put ask user for numbers to false and then exit the if, exit the while, come back to the while. And this time ask user for numbers is going to be false because we set it to false here. And because this is false, well, the wild will stop walking and we go out of the while and we continue the execution here on line 34. And then we get, and we print the max value from the list. Okay, so let's run that. You can see enter a number 0 to stop, so mean to but seven and maybe 3, 45 minus 781651000, let's say 2000. And then 154. You can see I can continue to add numbers. Okay. It's never going to stop 65, 34, and then I'm going to put 0. If I put 0, you can see that it's going to stop. And then print max value 2000, which is the value I gave here. Alright, so here you have another example of when to use a for loop here. And when to use a while loop, depending on what exactly you need to do in your programs. And well, that's the end of the lever. Three of these C plus, plus schools. 35. C++ Basics - Level 4: Working with variables, lists, functions, conditions, loops, et cetera, is the first fundamental step you need to take to learn C plus plus. And that's what you have just done. With this knowledge, you will be able to create almost any project you want. Now is the time to go to the last level of discourse. And this is a little bit different than the first three livers. Here I will teach you some stuff and show you some tips that are between the beginner and intermediate. Live it. But don't worry though, if you have made it until this point, there is no reason why you can't continue on why you can't understand. So in the following lessons, you will discover what is a reference and went to pass a function parameter by copy or by reference. And we'll also learn how to separate the interface from the implementation in your siblings passcode using function prototypes and header files. This will help you make your code much more organized. And I will give you a very short introduction on how to compile and earn a C plus plus program by yourself directly on the terminal. So at the end of this section, you will be able to clearly organize your siblings passcode for scalability and you will understand each step of the C plus plus program creation. All right, let's get started. 36. Functions - Pass Parameters by Copy or by Reference?: All right, To start this new section, I have created a new folder here, basic level 4 and main.cpp with the minimal code. So I'm going to come back to functions here. And there is something more you need to know about passing parameters to functions in C plus plus. So you can decide to pass a parameter by value, but also by reference. And to understand that in which one to choose, let's see how passing a parameter already works under the hood. So let's do that first, I'm going to create a new function here. Let's say void, add zeros to list. So I'm going to create a function that is going to add any number of zeros. So new element to a list of integers. So vector int. I'm going to use, if I use vector, I need to include vector and I'm going to use, so using namespace, std. So this one is going to be number list and I'm going to add another parameter, int. Let's say 0, zeroes number. Basically, what I want to do is I want to pass a list to that function and then a number of 0 I want, for example, let's say three and then four. So if I put three here, I want to add three new element to that list, which are zeros. So basically I initialize new element at the end of the list. Okay, so to do that, what I'm going to do, I'm going to do for int I is equal to 0. I strictly lower than zeros number. I'm going to use the parameter I go here, I plus, plus. So I'm going to go through 02 zeros, number minus one basically. And I'm going to do number list dot push back. And because I want to add zeros, so that's the function, doesn't return anything. So we have void. And what we do, we simply use a for loop to repeat an instruction which is to add a 0 at the end of the list. So now let's call that function. And let's see what is the result. So I'm going to create first a vector int. Let's name it list. Let's initialize it with just three elements. What I'm going to do first, I'm going to do C out. Now I'm going to print the size of member list, size of the list. And I'm going to list dot size and enlightened. Then I'm going to do add zeros. So I'm going to call the function and we need to pass the list. And I'm going to say, I want to add four zeros, okay? So here I have three elements in the list. Once I call the function here, I should have seven element. And I'm going to repeat this. So I'm going to print the size of the list before the function and after the function. Now, let's run this code and let's actually see what those. And you can see size of number list three. And after size of number list three. So nothing changed. Let's actually put this here. I'm going to put inside the function, and let's name it a, and then B, and then C. Okay, so we have the other of the execution. And he is not listed number list because we are in the function that's a different scope. So this one is going to be called first and then we call the function add zeros to list, which is going to call that one. And then we call that a, B, and C. Okay? I'm going to run that. So a size of number list three, which is normal because we have the list and nothing else. Then B, you can see B is here, size of number lists, seven. So here we have added four elements which are zeros to the list. And then we exit the function. We come back here, and then we come back to size of number list. We've seen three. So the elements that we have added here in this function are actually not added to the list we have passed to the function. Why is that? This is because actually when you pass a parameter to a function like this or like this, the parameter is going to be passed by copy, body copy. I mean that whatever you pass here, the function is going to create a copy of that. So here's going to create a copy of the vector int and a copy of the integer here. And create a new local variable here, which is, well, a copy of the variable or the arrays are wherever you are past. So when you modify the Netherlands here, you don't modify the list you have passed. You modify a copy of the list you have passed. And then, well, this number lists, it's just going to be created here and then it's going to be destroyed after you exit the add zeros to list function. If you modify a copy of a variable, well, you don't modify the original variable. So now we have a problem, but how can we fix this? Well, we can use a reference. So I'm going to simply use a reference. And as you can see that it's going to be very simple for the syntax. I'm going to add an ampersand here before the name of number listed here. And let's run that. And we're not. I have added the ampersand. You can see that we still have a size of number list three and then B size of number list seven inside the function. And, but then you can see the c after the function in the main, we have size of number list and that list seven. We have added four elements to that list. And now, so why is that? So a reference, basically, when you pass a reference, you don't create a copy. So the function is not going to create a cookie inside a new local variable, is just going to use the same variable, are the same Victor, for example. So you pass this vector to this function here, what you're going to get, so it's going to be named number list. But this is going to be a reference to what you have fast. So this is going to be a reference to the vector into you have created here. When you modify the number list, you actually modify the list here. And so this is very useful when you want to pass something, for example, an array or a vector on object, when you want to pass something to a function and you want to modify that thing inside the function, you can just pass as a reference here. And then you have the power to modify the item inside the function. So now of course, using the reference is nice, but you are not going to use reference for everything and every time, basically what you can do is you can, here as you can see, we still pass this parameter int by copy. Okay, we don't use, I don't use the reference here. We are going to keep it by copy. So when you have a basic data type like int, double, string, etc, you can pass by copy, there is no problem with that. Or if you have very small structures that you don't intend to modify. Okay? So you're going passed by copy, but if you have stuff that you want to modify inside the function, for example here, you can use these to pass by reference. And also, let's say that I have an array that I don't want to modify in the function, but this array contains 10 thousand elements. The thing is that if I just passed by copy, it's going to copy 10 thousand elements, which may be quite long here. If I pass by reference, nothing is getting copied. So I can pass a 10 thousand Victor to the function without having to create a new copy. So that's going to improve the code a lot. And actually there is something more you can do. So you can pass an element on item by reference, but you can also pass an element by const reference. Okay, so if you run the const keyword to make something constant, okay, So you can't modify it afterwards. And actually let's see an example to do that. Let's say void, print all elements from the list. We've, I'm going to use vector int list. And just do four int number in list. I'm going to do C out number. And like so very simple, just go through all immense and print them. Now, as you can see in this function, well, I could pass the vector by copy because I don't want to modify it, but then what? It's going to copy everything. So if I have 10 thousand elements, that's not going to be practical. So what I can do, I can put this. So I'm going to pass directly the reference to the array. But for more safety, what I can also do is add const before Victor, so const, type, and then ampersand, and then the name of the variable you want to have in your function. And this will allow you to pass the vector by your reference, but also to protect that vector so you can't modify it. Okay, Let's say I want to do list dot, push back 0. Okay? And let's say I'm going to execute that. And you can see we have an error. So we have an arrow because we can't just modify something that we have passed as a const. So using const reference is very useful when you want to pass large data, a function, so you don't need to copy anything and you are sure that it's not going to be modified in the function. All right, so to recap, when passing something to a function as a parameter, you have three choices. You can pass the item by value if it's a very basic datatype, or if you really want to copy of what you are passing, you can pass by reference. If you want to be able to modify the item, are you can pass by reference if you want to avoid creating a copy, but you don't want to allow the function to modify the original item. 37. Functions - Prototypes: Now let's focus on how to organize your code in a better way, which will allow you to easily scale it and also make it easier for everyone to navigate. We will start with function prototypes in this video and then header files in the next video. So I have created here a new CV B5 that have named prototypes that CVP and I have just included two functions we have already created before, triple number, which will return the triple of any number you gave. Ok, So int number, and here you can see we return an int and then void print triple number, which is going to just call triple number to print it directly. And I just call print triple number in the main. So if I run this code like this, this is going to work. I have 12, which is the triple of. Now the thing I'm going to show you two problems we have here. So first of all, with this way to write code, if you want to call a function, you have to write the function before you call it. Lets the iPad this here. What's going to happen is that we have an arrow because triple number here on line 8. So when we call, it, was not declared in the scope simply because triple member was declared after the print triple number. So I have to respect a certain order. Okay? Let's say I put those functions after the main. Well that's the same thing. We won't be able to call. Print triple number because it's been declared after we want to call it. Okay, so that's already quite annoying. We have to respect a certain order for the definition of the function. So while the two programs here are, the first one is this one. If you have a function that depends on another one, you have to respect to certain other. So that can be quite complicated to have a good Other when you create many functions. And then the second problem is more about readability, okay? Is that the more complex your application becomes, the more functions you will have here, and the less readable your code will be, your main, will be at the end of the file. This is going to be all over the place. Annual phi will be super, super big. And so the solution to that, the solution to the older problem into the readability problem is to create function prototypes and also to separate your code into different files. Okay, so let's see how to do function prototypes here. And actually the concept is very simple and you already kind of know it. When you create a viable, It's a want to create int a is equal to two. Well then create a variable. Here I have two, actually two steps. First, the declaration and then the definition of the vial. Here, I do the two steps in one. But what I can also do is I can create here. So int a, and then I can modify a or I can define a, which means that I have here the declaration Finishing, Well, that's the same thing for functions. Basically, we're going to create a prototype, which is kind of the declaration of the function this time. And then we're going to implement the function in a different place. And so to create a prototype for a function, It's super simple. You just take the return type, the name, and the parameters. So you just take this line, you copy this line. You put it there, and you put a semicolon. This is the declaration of the function. Then this is the implementation. So you have separated the interface, which is the declaration, and the implementation, which is the code inside the function. And let's do the same with this. And actually we can put all the declaration of the prototypes at the top. And now what I can do, I can just move this, for example, after the main. I can change the other. Let's say do this. And now. So that's removed some lines. Now I can run the code. And you can see the code is running. You can see here we have 12. No compilation error in the code is running. So now the problem is already better, okay? In our code we have so I can hide that in our code we have the prototypes for the functions, then the main, which is going to call different functions. And then I have the implementation which I can put in a different place. And so here we have already solved the other problem for the functions. And creating prototypes is actually a very good best practice when you write C plus plus code. So to recap, to create a prototype, you just take whatever is actually before the block of code, before the curly bracket. And this, you put this at the beginning of your program with a semicolon and that's it. 38. Organize your Code (.hpp and .cpp files): Using prototypes for your siblings plus functions is a good first step, but still you have all your functions in one place here, in just one file. Here I will show you the second step. We organize your code, which is to put your functions in different files while still being able to use them from your main function here. So I'm going to create here two new files. Okay, I'm going to create right-click, let's say my computation. Computations dot age PEP, which is the header file for siblings class. And right-click my computations. Cvp. So the same name for the PSI-BLAST plus and the age final for the header file. And I'm going to go first to the head of fire. What I'm going to do here, I'm going to do. So that's a very specific syntax you can do for every header file you have. And this is what is called Include Guard. I'm going to do this and then explain to you. So you can do if in depth like this with hashtag, if and if. And then what you can do is you can put the name of your file in uppercase, my computations, and then add underscore H at the end. And then you're going to do define my. So the same can just copy this to make sure it's the same. They're important. And then, and, and what you can do now is write all your code between this and this, okay? After those two lines, before this line which is at the end. And those are includes gowns. So basically this fine. Then you are going to include this file into different other files, okay? And this will prevent the compiler to include this file every time you include in different files. And for now I'm going to keep it like this. And I'm going to explain to you Actually when we have a concrete example of this in just a few minutes. So you have include guards and then here what you're going to put you into, but here are some integral back to prototype that CV. You are going to put the declarations are the prototypes of the functions. I'm going to copy this. I'm going to go here, and I'm going to paste this pixel. That's where you're going to have your prototypes. I'm going to save the file and I'm going to go to my computations dot cpp, okay, So the same name, but that CVP. The third thing I'm going to do is include and I'm going to include the header file and to include the header file. So you have seen that here when we include something, we use angle brackets because this is something that is installed on the system here because this is a file I have here. I'm going to use quotes, my computations. And you can see I have here with VS Code auto-completion. So I'm going to include my computations that HPV, which is that one. And in the C plus plus file, I am going to simply do this. I'm going to copy and paste the definition or the implementation of the functions. As you can see here, I need actually to add those lines include iostream and using namespace, std. So what I can do, I can add this here in the C plus plus file, but I can also add it here in the HTTP file. That's going to work the same way because, because I include that file, if in this fight I include iostream main, I use using namespace std, then that's going to be valid for this CPP file to save this and save this. And then in my C plus plus file in my, let's say main fight prototypes. I'm going to remove this. I'm going to run with this. And I'm going to do here. So with the Include, Include, with quotes. My computation's got age VP. And you can see that now, so I'm going to save. You can see that this function is recognized. So now we have a main file, cannot see b, which is very minimal and you can see we just have one include and then we can use the function in the final is just ten lines here. And then we have the header file, which contains the prototypes of the functions. And we have a C plus plus file which contains the implementation or the definition of the code for the functions. And so this is what we call the interface, because this is what you actually include a neediest might you already need actually, when you are the client of the library. So let's say this is the library, my computations when you are the client, which means that when you are using that library, what you really need to know is the prototype, okay? You need to know what kind of value you're gonna get. What is the name of the function? What parameters you need to pass, okay? You don't necessarily need to know the implementation of the code inside the function. You just need to know this information and maybe if you have some comments here that explains to you exactly what it does, you don't need to read the code. So this file, you actually maybe don't need it if you just want to know the information on how to call the function. Okay, So here you have the interface when you want to use the library or the functionalities here. And the siblings plus Phi, well just contains the implementation of the function, so two different files. And then you include the HTTP here to use the library. One thing I'm going to come back to this now, the Include Guard. So you can see that we have, include my computations dot HBP here, and include my computations that HVP here. The thing is that every time you have include HPV five, what is going to do in simply going to copy and paste everything and put it at the beginning of the file. So here it's going to put it here, it's going to put it here. And every time you call that is going to copy and paste on code, which is going to increase the size then for the compiler. So this those two lines and that one, I'm going to just prevent this and it's just going to copy this one time, even if you call the include 100 times. Okay, so that's going to optimize a few things when you compile. And well, that's a very good practice to put this whenever you create a header file. All right, so to recap on that, when you create functions, what you can do is first separate the interface, which is the prototype of the function, and the implementation, which is the definition of the code inside the function, you will put the prototype in a header file and the implementation in a cpp file. This way is going to be very easy to read the code, to know what it does and how to use it. And also by doing this, if you increase the complexity of your application, it doesn't mean that you have to increase the complexity of your code. The code can stay clean and readable, whether you have 10 lines of 5000 lines. Okay, and now I'm going to make a very quick transition to the following lesson is that I'm just going to try to run this. And as you can see, it's not working. As you can see when I tried to run this, I truly the copulation doesn't work. And I'm going to explain that to you in the next video. 39. Compile and Run a C++ Program in the Terminal: In this video, I will show you how to compile a C plus plus program by yourself in the terminal, and then also how to run the executable you have created. And this is a good time to do that because as you could see in the previous video, we couldn't make the compilation walk. Could just by clicking in the play button here of the Visual Studio Code extension we have installed. And in fact, there is probably a solution to make it work with this extension. But here, instead of trying to change some settings for an extension, let's actually focus on how to make the program compiled by yourself. You will see that will be super easy, actually much easier than you think. So here let's have a look at the terminal. Let's have a look at what happened before. So when we were using the main dot CVP here, you can see that when we actually click on the Play button, what's going to happen is that we have the cd command to make. The compiler kind of go inside this folder. And then we have this command which is going to compile the code. So this command is very simple. You have g plus plus, which is the compiler for C plus plus. And then you can see main.cpp, which is the name of the file. And then dash. Dash O simply means output main. So basically what you're telling the compiler to do is just take the main.cpp, combine this with the compiler, and then the output file. You specify that the output file is going to be called name also. So this you can change if you want. But what you can see here is that when we execute this, we have a main executable. So on Windows you will have main.xml, but on Linux system you may just have main. And then you can see we have the comment to execute the main as simple as that. So now let's go back to the era we had with the prototypes dot CVP. Now you can see we have prototypes dot CVP and we have a library. Here are a header file with a C plus plus file that we include in our prototypes that CVP. And when I click on Run, What's happening is that you can see here g plus, plus prototypes, that CVP dash o prototypes. There is no mention of those two files here. And that's why it's not working, because this and this are not compile. Okay, we've prototypes that CVP. So then when you try to include the header file, of course it's not going to be here. And so what we need to do now is just we need to do this command. So the same coming, but we also need to add this my computations. So we can compile my computations with prototypes, and then prototypes can find my computation. And so you're going to open a terminal here on Visual Studio code. So let's say it's closed. What you can do, you can click. So I'm going to click on Alt here and you can just do view terminal. Terminal. You have the shortcut here to open. You can see View terminal is going to open and close the current terminal you have and make sure that you are in the correct folder. Okay. Basics level for if you are not in the correct folder, for example, I'm going to use c k, which is basically to move from the folder to another one. So that's a little bit out of context here because that's basically Linux command line tool. If you are in, for example, you can see close project. What you can do is simply do cd basic level for a new gonna get. Finally, level four like this, because the other one doesn't exist. And you're going to go inside the correct here you can see the correct folder. So if you're not in the correct folder, US city. Okay. To navigate CD and the name of the folder. Okay. I'm not going to explain more about that coming here. And whether you are on Windows, Linux, and macOS. If you use the terminal here from Visual Studio code, that's going to be the same comments. And actually the g plus plus command that we're going to use now is going to be the same whether you want to use that from a Linux terminal, a Windows Terminal, or a macOS terminal. So what I'm going to do, I'm going to do, Let's say that we have G plus plus prototype, that CVP dash o prototypes. I'm going to do g plus plus prototypes. I can use Tab for auto-completion. I'm just going to remove that if they put that here. So prototypes that CVP and then my computations dot CPP. So you can see it's going to a new line, but that's the same line here. So what I'm simply doing here, I'm simply adding all the C Plus Plus files that I have on my program. You're not going to put the HBV file, you're just going to put the CPP file. So you just put the list here, g plus, plus prototypes that CVP, my computation's dot CSV. And then once you have this, you can put dash o to provide the output name. And then you can just put anything you want. Let's say put test. This means that it's going to compile this and put that inside a test executable. Let's run this and it's working. You can see now I have test.txt, a new test executable. And what I can do now to run this, I can do dot. And then well on Windows you're gonna do DOT backslash desk and run that. And you can see now it's working. And if you're on Linux or Mac, you're going to do dot forward slash test. Okay, so that's the difference between Windows and Linux. Backslash for Windows, forward slash for Linux and Mac. And so here you have seen how to compile a C plus plus program, okay? This is the very basic way to compile it with g plus, plus. Okay, then you can do much more complex stuff, but I'm going to keep it simple here. So how to compile a C plus plus code with an output executable that you choose. And then how to run that executable, which is actually very simple from the terminal. 40. C++ Level 4: Exercises: And time to practice more on what you have seen in this level for all the siblings plus schools. So here I'm going to give you three new exercises. The first one, you are going to come back to the main.cpp that we have written in the law before. And here you have two functions. The add the zeros to list and also the one to print all elements from a list. You're going to plug those two functions in a different file. So you're going to create a prototype for those functions. You're going to create a HTTP NSABB file, which you can name my vector functions, okay, because those are vector functionality that you have just created. So let's name it like this. And so you're going to separate the interface from the implementation. And then you can also make it compile. Okay, so with the compilation step that you have seen in the previous video, in just one tip is that in the header file you will have to add include string, okay, because string is from the STD, so the standard library. But in the header file, you will have to include that or else it's not going to work. Okay, so that's the first exercise. The second exercise, you're going to actually use the result of the first exercise, okay, to the Seguin exercise. And you're going to create a new function, okay? To add elements from the list to another list, just using integers to make it simple. So this function, of course, you're going to create a prototype in the header file and the implementation in the PSI-BLAST beside. And you can also call it from the main function okay, to test it. And so you're going to have a list a and List B. And you want to put the element of the list at the end of the list B. Now you will have to pass, so you will have to pass two vectors to the function. And you have to think, do you need to pass the vector by value, by reference or by const reference. So for each Victoria you have to think about this. And the third exercise is yet a new function. You're going to create a function to find how many occurrences of a string you have in a list. So often list of string, of course, of std string. So you're going to pass a vector to the list and you're going to Bus also a string. And then in the function, you're going to go through all the elements and check if you have elements that match the corresponding string and then the return, the number of occurrences. So you're going to return a number. And here again, you will have to think, is it better to pass the vector by value reference, our const reference. And with that, I will let you work on the exercises. So make sure that you have correctly understood the previous lessons. You can always go back to watch them one more time. And then I will see you in the next video for the solution. 41. C++ Level 4: Exercises - Solution: This is the solution for the three exercises I have given you in the previous lesson. And so let's start with the first one. So what we have here in our main.cpp is, so we have a main and we have two functions here that we are going to separate. Okay, we're going to create a prototype and we are going to create a header file specified to put those functions. Okay? And what I'm going to, I'm going to clean a little bit of the logs here that I'm doing. Let's put a in its butt, be here, but I'm not going to put any printing inside the add zeros to list. So what I'm going to do, I'm going to do, I click here new file and I'm going to name it my vector functions, but HBV. And I'm going to create a new file, my vector functions that CBP, so the exact same name. Okay, it's a good convention and a good practice to do this. So in my vector functions.php, I'm going to do if N def gambling to add first the Include Guard. And I'm simply going to put the name here in uppercase, my vector functions. And I'm going to add an endoscope h. And then I'm going to do define. I'm going to put the exact same name. And then, and that's the include gut. And then what I'm going to do, I'm simply going to put the prototype of the function which is just this before the play bracket. I'm going to put that here, and I'm going to put a semicolon. And we have to do the same with that one semicolon. So here we have a few arrows. Why is that? Because, well, in this we need to include vector or Chile. And I also need to do using namespace, std, which is going to make things better. Okay? Now it's better. So this is the interface. Okay? I have also told you that you have to include string, okay? That's going to be four, actually exercise number 3. So I'm not going to include it now, but we're going to include it just a bit later in this video. Now, in the civil specified, the first thing I'm going to do include my vector functions.php. And I'm going to, so this is quite simple here. I'm going to just copy paste the implementation of the function just like this. And here I need to include iostream, okay? So I can include iostream here, or I can also include, include iostream here. That's going to be the same because here we are not going to need to use iostream in the HPV, just in the CBP. Good because we are not going to do C out in the attribute phi. So we can just include iostream inner CVP. That's going to be basically the same thing here. I save this file. And then in the main, what I'm going to do, I'm going to remove all that. And I'm going to include here, include my vector functions that HPV. All right, and now the thing is that going to need to compile these. Phaedrus run this, it's not going to work okay, because it's just going to compile main.cpp. It's not going to comply with the vector functions but CVP. So let's go ahead and do that. G plus, plus main.cpp. And then my vector functions that CVP dash o. And actually I can choose a different name for the executable. Let's name it Exercise one. So now I have an exercise 1 dot z that they can do. So DOT backslash on Windows or forward slash on Linux, exercise one. And you can see size on liberalised etc. So we have the main that is getting executed with the same functionality as before, but now we have separated the interface here, the implementation here, and we have the main code here, which is very clean now. Okay, and now let's go to the exercise number 2. So in this exercise we are going to create a new function. And this function is going to take a list and add it at the end of another list. So I'm not going to create directly the function here. Now that I have here my structure, I'm directly going to create using the right structure. And so what I'm going to do first, I'm going to create the prototype, okay? This is the most important thing to create the interface. So what do I want to do for this function? So I'm going to add a list to another list. Do I want to return a value? Well, no. So I'm going to put void. And then how I'm going to name it. I'm going to put things simple here and say add list, two, list. I'm going to give two parameters. The first one is going to be the list that I'm going to call input list. I'm going to add two. Output list. So I will have a vector int input list. And I'm going to put inside vector int output list. And week 2, but a semicolon. And actually better without a space. Now the thing is that I have to think about, do I want to pass the vector by copy, by reference or by const reference. So for the input list, what I want to do from that list, I want just to read that list and I want to put it after the output is two. I'm going to modify output list, but I'm not going to modify input list. So I could leave it like this as a copy, okay, because maybe there's going to be a smallest, but I don't know that maybe there's going to be a big list. So I want to avoid actually making copies. So if I want to avoid making copies, but I don't want to modify the input list. I'm going to put const reference because this is quite big. I can maybe put a new line here. You're just after the parentheses is also nice. After the parentheses are after a comma here. So that's more reading. So input lists is going to be const, reference and then output. So this one actually if I leave it like this, I'm going to have a problem because I'm going to add some elements to that list, which is going to be passed by copy. So actually I'm not going to add elements to the list and passing, I'm going to add elements to a copy. And I don't want that. I want to directly modify the output list. So here I'm going to put a reference and that sits no const reference, just a reference. Okay? And so now I have my prototype which is ready, and without actually knowing what I'm going to put in the code does already easy to know when you need to call the function here from the main, what it's going to do, okay? At least two list and you can see that the first one is not going to be modified. In the second one is going to be modified. And now let's implement the code for this function. So what I'm going to do is I'm going to copy the prototype, okay, without the semicolon here. So I'm going to copy this and put this in the C plus plus file. And I'm going to put it there and simply go back to a new line. Open, close the curly brackets, just like we did for the other functions, but the other functions we actually have defined them before in the main and then moved them in the HBP NCBI B5. Here I directly create first the prototype, and then from the prototype I create an implementation in the C plus plus file. So here what are we going to do? Well, we're going to go through the input list. And for each element of the input list, we're going to add this at the end of the output list. So let's do this for int number. And we are having number here. So number from input list. What we can do simply is output list dot push back. And we're going to put the number we have directly from the input list. And well done function is finished. So the implementation here is quite easy in quite quick, if you use the correct FOR loop with the list to save this. Okay, Now make sure that you save the file because we're going to compile directly from the terminal. So you need to save each file before you compiled. And so let's do an example here. So let's put the command here. For example, Exercise one. Let's put a comment here, Exercise 2, so we can easily see what code is for what. And let's create two new vectors. So vector int, I'm going to name it input and I'm going to put 234, okay? And then vector int output. And I'm going to put, let's say 10, 11, and 20 elements. So we have two elements here, three elements here. Now I'm going to call the function. So, so as you can see here, we have already the Include Guards. We are already all the setup for those two 5s and we already, I include my vector functions.php. So if I create a new function here, I can directly call it. From there. I don't have anything to add. So and list, two list. And so I need first to give the input list, which is input here, and output lists over here. The other you can see it's very important. And now what I can do is maybe to check, I can just print the output list. So how to print the output list? Will I already have a function here? Print all elements from lists. So let's use that function and print all elements from a list using output. Okay, let's run that. So save and I'm going to do view terminal. And let's compile it again. So if you can use the arrow keys, okay, to get g plus plus main.cpp, my vector function of the TV dash O, and then I'm going to name it Exercise 2, okay, for the executable. And here I am not. Ok, you can see I'm in course project. I need to go in basics level four. And then I can do the command again. And we don't have any arrow. Now let's do DOT backslash because I'm on Windows. Exercise 2. Let's run that and let's see. So we have first this from the first exercise. And then you can see the output list contains 10, 11, which is here the beginning of the output list. And then 234, which is the input list that was added to the output list. Okay, so everything worked correctly. All right, and now let's go to the exercise number 3. We need to create a new function to find how many occurrences of a sudden string we have in a list. So I'm going to go to the HB fi first and I'm going to create a prototype. What do we want to get from the function? Well, we expect a number that's going to be an int number, okay? Because there's going to be a number of occurrences, so integer, I'm going to name it. Let's say Get String occurrences in a list. Let's name it like this. And I'm going to pass first the list. So that's going to be a vector of string. Because we are going to compare strings with strings. I'm going to mimic list. And then a string. That's going to be the text we want to check, okay? And I put a semicolon. So here, let's check. Do we need to pass by a copy, by reference or by const reference? So further least here. Well, actually Victor, It's usually best to pass it by reference, okay? In case we have a very big vector and we are not going to modify this list actually. Okay? So because we are not going to modify it, I'm going to put const, we are just going to go through the list and check the equality with these texts. And now, well, for the string text, while this is a very basic datatype, so we don't really need to put a reference. So I'm going to keep it like this by copying and know where I'm going to save the file and I'm going to copy this. I'm going to put that in the C plus, plus 5 and, but some got in brackets. And now I'm going to write the code for the function. So let's start. Int or currencies is equal to 0. I'm going to start a counter at 0. And every time we find much here, I'm going to add plus one to the counter. So let's go through the array 4. So we're going to get a string, I'm just going to name it S here. So for each element in the list that we get here, I'm going to check if S is equal to text that we get in. If this is the case, I do occurrences plus, plus, okay, so I can do a currency is plus one. This is just going to the same. And at the end I do written occurrences, okay, because I need to return an integer. And this is, as you can see, an integer. So with this code, we're going to get how many times we have this text inside this list to save the file again, so make sure that both files here I saved a little bit to the main. Let's create here Exercise 3. And let's create a new vector. Let's do victor. String. Let's say city least CAN going to put some silly names. And let's start with so for example, Paris and London, and then Berlin. And then I'm going to go back to a new line here. Let's do Paris again and then building again, maybe Madrid and Paris. Okay. So on this list, I have Paris, three times, London, onetime Berlin twice, and Madrid. Just wanting to test the function, I'm going to do C out number of occurrences of Paris. I'm going to test for Paris. In this, put a colon here. And I can call the function directly, get string occurrences in list. Actually, let's go back to a new line here. Let's align this for clarity. And I need to give here. So first the array list, which is going to be passed as a const reference. And then I need to give the pattern or the text. I want to check Paris. And well, let's actually do enlightening. So I create a list. I pass the list here, the vector to the function. And the function is going to return an integer number that I'm going to print here. Let's save this. I'm going to open a terminal. Let's compile. And actually let's combine to exercise three. Okay, so as you can see, we have here an arrow. This is because you didn't have this era before. But here, when you create, actually when you use the string here in that CPP, how HPV file. Here you can see we have an arrow. You can see string was not declared here before. You need to include string like this, okay? Just like you had to include vector here, you need to include the string. So I'm going to save this and I am going to electron domain here and just compile again. And it worked. Now we have exercise three here. And we need to do this exercise 3 to run that. And we have, so we have pixel size 1, 2. And then you can see number of occurrences of Paris. Three. If I try with, let's say Berlin, I'm saving the fine. I am going to just compile again and run it the size, of course, better if I put bearing here as well. So let's just compile again, run again, and you can see number of occurrences of Berlin. So it's working. Alright, that's the end of the exercises here, which were a bit, maybe a bit more complex but more complex, okay, for your learning path. And that's also the end of the living for the C plus plus goes. 42. Extra: C++ OOP: You have now finished the four C Plus Plus levels for this course grade. Now, here is an introduction to OP, our object oriented programming with C plus plus. And why did I add this section to the course? Well, first of all, C Plus Plus was designed exactly for that. At the beginning, cplusplus was not named cyberspace, but something like C with classes. So not only you have here a language made for object oriented programming, but also nowadays, OP is used almost everywhere. So I felt this course wouldn't be complete without at least an introduction to OP. And well, one thing is that at the end of the section, don't expect it to be a pro or, or be programmer or right, This section is here so you can get a grasp of how it's working and be able to write your own basic classes so that even if you don't want to use OB in the future, well, when you're going to encounter some sibling, our OP code, you will be able to understand what those, and you'll be able to use it in your own programs. Okay. And with that said, let's get started. 43. What is OOP, What are Classes?: In this video, let's understand what OB is. So object oriented programming is a way of organizing your code into what we call classes. A class is basically a structure you can use to then create an object in your code. And what do you put inside a class? Well, two kinds of things, variables and functions, which are of course related to the class. Let's see with an example actually because I don't want to lose you with too much theory. And because I like robots and AI mainly worked with robotics programming, let's use a robot as an example. This will change from the classical animal class, which is always the same in every tutorial in which you are probably going never to use in real life. So let's say you want to code the behavior for a robot. We are going to stay at a very high level here. So we need to think about what kind of attributes a robot can have. For example, an aim, version number, the internal temperature of the robots, etcetera, etcetera. But let's keep it short. And then what functionalities the robot has. The robot can say hi, with a speaker, are just a screen. Doesn't really matter here. And so the robot can see high and also say its name. Then it can print all its internal information, including the name, version, number, temperature, etc. All the attributes we have seen before. The robot can also initialize its hardware in well, many more things. You can add any other functionality you need. I'm going to keep it super basic and high level with a limited set of functionalities. But this is so we can focus 100% on understanding OOP with C plus plus. So we have defined attributes and functionalities for the robot. Now, if you want to implement that with C plus plus code, you are going to create some variables for the first part, in some functions for the second part. Well, if you create a robot class, you are simply going to group those variables in functions inside one structure that you are going to name. For example, robots in, in a class. Instead of using the word viable, you are going to use attribute. And instead of the world function, we use method. This is a quite useful convention to avoid any confusion. So here the version number of the robot is a class attribute and the init hardware function is a class method. Now, as you can see, creating a class doesn't add any functionality or spatial behavior to the robot. This is just a different way to organize and write the code. In speaking of writing, well, let's actually write that glass with C plus plus. 44. Create a C++ Class - Attributes, Constructor: The first thing to do when creating a class is to actually define what attributes and what methods you need to put into the class. Well, that's what we have just done in the previous lesson. And now we can start the implementation with C plus plus code. So for this section on Obi, I have created a new folder here named OB and just the main.cpp with the minimal code. And I'm going to create the class directly here. So what I'm going to do first, I'm going to create the class here. And then in the following lesson, we are going to also split the code. Okay, like we did, we function in different files, but for now let's keep things very simple and it's just right the class here. So to create the class structure, it's very easy. You just use the class keyword. Can see it should turn in a different color. And then you put the name of the class. For example, robot, I'm going to name it robot. So the convention for class names is to start with an uppercase K. And if you have different worlds, for example, if you want to create a robotic arm, which we are going to see later. In this case, start each word, each new world with an uppercase, okay? Class robotic. Actually cast robot and then open close curly brackets. And you can open this for example, and we have the last curly bracket. It is very, very important. Don't forget to add a semicolon here. Okay, so that's the first thing you need to write, class robots in the curly brackets, semicolon, okay? And everything you are going to write into those two curly brackets is going to be inside the robot class. Okay, So if you write a functionality here, it's in the global scope. If you write a function idea here, it's in the scope of the robot class. And now I'm going to add two new keywords here, public and then colon, private caller without any indentation here. And this is going to be very useful for the concept that is named encapsulation with OP, okay? And actually I'm going to explain this concept a little bit later in this section. When we have a real example that you follow, you can just put public and private. So everything you put on the public is going to be public and everything and the private is going to be private in, well, what we can do know is to create the attributes for the class. So we have three attributes, and I'm going to put them below private here. So I'm going to use tab. I'll just put an inhibition for clarity or for readability. Let's just start with the name. So we have string name. I'm going to create a string here, and I'm going to do using namespace, std, okay? And maybe also include string if needed. So here I create an attribute just like I would have created a variable. Okay, That's the exact same thing. The only difference is that this variable is inside the class. Here in class robots. So this is an attribute of the class robot, that's it. And then we have a version number is but int rational number, and we have a temperature, let's say double internal temperature. Okay, so here you are just going to declare the attributes. You are not going to define them, okay? Only declared there in what you do usually is you're going to put them private and we're going to explain that a little bit later. So you have a class with attributes, but what you need to know is to create a constructor, okay? Which is a very special method of the class, okay? Because, well remember that a class here is just a structure. It does nothing by itself. You will need to create some objects from the main here. So you can use the functionalities of the class. When you create an object from the class, the first thing that will be called the constructor of the class. And so let's focus now on the constructor. So the constructor is a very special method and actually the name of the constructor will be the name of the class. So you just put here robots get the same name as the class. And then you can put some parameters. So this method will be called when you create the object. And usually that's going to be used to initialize the attributes you have here. So what you can give as perimeter is for example, string name, int, version number. Okay? So when you create an object, the class, you can give it a name, okay, that's going to be the name here. You can give it a version number. And for the temperature where you're not going to give you temperature because the temperature is going to come directly from the class, from the temperature sensor for example. Okay, so I create a function like this. And well, let's just implement that function here. And as you can see, there is no return type here. And it's very different from other functions. Okay, That's how you create a concert. Just the name of the class. And then you can put whatever parameters you want in here you're going to initialize. So for example here named version number, internet temperature. And you can do some setup. Also if you want. And so we're here how to get access to attribute of the class. Well, let's start with internal temperature. I can just write the name internal temperature, and it's built for 3500. Internal pressure here is going to be the attribute of the class. But now the thing is that we have an attribute named name and another one here, a parameter which is also named name. So we have a name conflict here. And when, instead of just changing the name of the parameter, what you can do is you can do this with an arrow. Name is equal to name. Okay? When you use this, this refers to actually this object which corresponds from the class, okay? And this arrow, you can get access to attributes and methods of the class. So when you use this name, you actually use the name here. And when you use name here, you use the name from the parameters. Okay? So this name equal to name, this version number is equal to version number. And with this, you have initialized your attribute. I can also put this here, okay? There is no problem with that. If there is no collision, you can use this or not. That's going to be the same. So this is, I would say the more classical way to initialize attributes in a constructor. And I wanted to show you this so you can understand the, this keyword. But actually there is a better way that you're going to use in C plus plus. And this is simply to do so I'm going to do this and explain it to you to do colon. So you're going to add a column here. And whether you added here are maybe just in the new line. It doesn't really matter. And New, I'm just going to put first the name of the attribute, which is named name or so here. And then what value you are going to pass to this. So I'm going to put name, name. And this name actually refers to the attribute. And what you put into parenthesis is the value you are going to put fallen at Troy. So that value is this parameter, okay? And then you are going to separate each attributes by a comma. So version number would be version number. And I can put another comma. Let's go back to a new line and you can do internal temperature. And let's put 3100. Okay, and now that I have done that, I can just remove those three lines and know where the thing is that the code here, the function is just empty. We could have other code here, but here is the initialization for all the three attributes, which is enough for what we want to do. Okay, so you add colon, and then for each attribute here, you got the value you want to give in parenthesis. So the value can be a value like this. For example, a number, a string, whatever. It can be directly from a parameter that you get in the method, in the constructor method. And if you want to do something else, well, you can do that here. All right, so now we have created a class structure for the robot, and we have successfully declared and initialized the attributes inside of the class. 45. Add Methods to the Class: Now that we have the structure of the class with the constructor and the attributes for the class. Let's implement the methods are, in other words, the functionalities of the class. And to create a method, it's almost the same thing as to create a function like you did previously. So I'm going to add three methods here because we had three functionalities when we define the class previously. And I'm going to put those methods in the public, here, below public and note below private. So we will be able to call those methods here from the main when we create an object. Okay, I'm going to come back to this public and private, and naturally the encapsulation in the next video. So let's create a function void. Say hi. Okay, So that's very classical function. And I do see out, Let's say Hello. My name is, I'm going to put the name of the robot. So named the attribute name. I can do, ready to help. And then inline. So as you can see, to get the attributes, I just put the name of the variable or the name of the attribute. So that is very simple and in a concatenate different strings to make something nice to print. And so this function here say hi, it's actually a midst all of the class robot. So this is not going to be available from outside of the class, okay? This is part of the class robot, and it's only going to work when you have a robot object and you call, say hi from the robot object. Now I'm going to read another function. Let's say Void init. Hardware, like this, for example. And let's do C out. He need hardware. So we've enlightened. So the thing is that in real life, you would put the real code to initialize the real hardware. Here we don't have any hardware. This is just for testing. Oop, okay, and the point is read to understand our p.stance with an example. So let's just use a print to see something on the terminal when we call the init hardware function method. And let's create another method, void print info. Okay, so I have created three void methods here with no parameters, but of course, those are just like functions. So you can return into, you can written string generator whatever you want, and you can put different parameters, okay, we already have some parameters here. So you can put any number of parameters you want, just like in the normal function. And here in printing for what? I want to print all the info from the robot, starting with the name. And actually we already have say hi, which is saying Hello, my name is the name ready to help. So what I can also do from this method is to call this method, say hi. So as you can see, you can call a method of the class from another method of the class. This is absolutely not a problem and you don't need to add any namespace, any prefix, anything. This is in the same scope, this is in the same class. So you just use say hi. If you want to use the function or the method, say hi. And then I'm going to put C out, let's say version number. And in version number and line. And then another C out, temperature. With internal temperature. Inline. Print the name with a nice message, the version number and internal temperature. Okay? And you can see again, to get access to attribute, you just put the name of the attribute inside, misspelled after class. Okay? If you want to modify attributes, you can also do so. For example, if I want to modify the name, I just put name is equal to NI, put a new string here. Okay, so just like you would modify a variable. All right, so here you can see the class with everything. So we have successfully written all the functionalities of the class inside different methods. And we will be ready to create an object. 46. Create an Object (Instance) from your Class: You now have a class with attributes, methods, and constructor. Great. But this is just a structure inside your program if you run your code, no, Well, nothing is going to happen. So the compilation is successful, but nothing happens just as we have seen with a function. Well, a function is just a bunch of code that does nothing by itself. You need to call this function in your program. And this is similar with classes. You will need to create an object or also called an instance of the class. So you can use the functionalities of the class. And let's create an object from this robot class in our main function here. To do that, well, you can simply start with the name of the class, which is robot, and then create a name. So that's going to be the name of the variable, the object. Here we are going to name it an object, an instance of the class. So let's name it a robot simply. I'll just Robot 1. Okay? So that's going to be its name. And then I'm going to open and close parentheses. And in this, what I'm going to put is the parameters I need to give in the constructor. Because when I do this, the constructor is going to be called first, okay? If you remember to initialize all the attributes of the robots and initialized Thomas test that you need to initialize at the beginning. So here you can see I need to give it a name and version number. So a string and an integer. Let's name it R2, D2. And let's say it's version number is three, okay, just run them. After this, I'm going to put a semicolon. And this statement is now complete. We have created an object. So Robot 1 we can use robot will know in our code of type robots. And its name is R2D2. Its version number is three. And we can use all of the method here, say hi in it our way and print info. So let's actually do this. Let's do Robot 1 dot. So if you want to use a method of the class, you do the name of the object dot. And then you can see you have autocompletion. For example, say hi. And you just call the method like you would call a function, okay? Just the function or the method is linked to the object. But then it's just like you call a normal function. So let's run this. You can see Hello, my name is R2D2, ready to help. Hey, that's great. I can also do, for example, let's say in IT hardware and then Robot 1 dot print info. And I'm going to run that. And you can see any hardware. And then hello, my name is R2D2, ready to help. So when you go to print info is gonna get to say hi first. And then it's going to print the version number. You can see three, That's what we have given here in the constructor. And then the temperature is 30, okay? That's what was initialized here also in the constructor. Okay, and now what about those public and private keyword? And about the encapsulation. So the encapsulation basically will allow you to protect some attributes and some methods. So you can't just get access to them from outside of the functions are the method of the class. So let's see that with an example. Let's say that no, I want to get access to the version number directly. So I can do Robot 1 dot version number. Let's say I want to get access to it. I want to print it C-out robot one version number. Well, It's not going to work. And you can see here, version number is inaccessible. Let's actually run the compiler to see. You can see another arrow here. Version number is private within this context. So the thing is that when you create an object here, so you are outside of the class, you create an object. And from this object you tried to get access to version number because this is private, you can't get access to it. But inside a method that is declared and defined inside of the class, you can see we can get access to it here. No problem. So that's what's private, is basically and public where the public basically you can get access to it from inside of the class, but also from outside of the class. That's why we can call, for example, print info. If I put print info here, let's put that in private. So in private you can put attributes and methods. So if I use print info in private and no, Well let's remove that. And it's just run this. You can see print info is private so we can't call it from here, the main with the object. All right, I'm going to put it back in public. So this is encapsulation. So if you want to avoid that, the client of your class, which is basically here, the main when it's using the class. If you want to prevent the client from modifying some elements, for example, some attributes, or from calling some methods. You can put them in private and they will not be available from outside of the class. So that can be very useful. All right, so now that you have a grasp of encapsulation, well, you can see we have an object created from the robot class. Everything is working well. And we're actually, we can create as many objects as we want from the class. Okay, we have Robert 1. Let's create robot, Robot 2, and let's name it c 3, 0 for example, we version number 1. I'm going to remove that line and I'm going to do robert one print invoke Robert to dot print info. And let's see what we are going to get. As you can see, we have hello, my name is R2D2 and then version number three. So this is from the first robot. And then hello, my name is C3PO, version number one. This is from the second robot. So you can create as many objects as you want from the same class, which is kind of a blueprint, okay? So every object will have different attributes, so you can initialize them in will have its own life, basically. Ok. And not to recap. In order to create an object from the class, you need to write the name of the class to call the constructor and pass the required parameters to initialize attributes. Then from that object, you can call the class method. You can also create multiple objects from the same class. Each object will have its own internal mechanism and attributes independent from the other object. 47. Organize your C++ OOP Code: In the Level 4 of the cplusplus course, you have seen how to organize your code by creating prototypes for functions and then separating the interface from the implementation using header files. Well, for classes, this is actually very similar to what we are going to do. We're going to create a HTTP and a CBGB E5 to put the class outside of this main file. Then we are going to include the class here so we can use it and you can just leave the main code like this. Okay? So the class, we are going to separate it into an interface, into the implementation. Okay, let's see how to do that. I'm going to create a new file here. Name, for example, robots dot HPV. So we have a robot class. I'm going to name the fight robots dot HVP. Okay, that's something that you may see quite often is that the name of the file is also the name of the class. But we'll actually don't need to do that. It can work with any other valid name. Okay? So here I'm just creating robot dot h BP and robot dot cpp. In robots dot HTTP. I'm going to first do include guards. So if in Banff, so if not defined, robot underscore age, define robots underscore age and then endif. All right. Now what I'm going to do is I'm going to take the entire code from the class. And I'm going to copy and paste between the two first-line and end if like. All right, now I have this and I'm going to also do include iostream, include string. And we also need to use using namespace. Okay, let's see if we have any error. Seems good. So now the class is outside of the main.cpp. It's in a robot dot 850. And we are going to go a bit further. Okay, because here we just want to keep the interface. So what is the interface? The interface is the class structure with the prototypes for each method, just the prototypes and of course also the attributes. So we want to remove the code, we want to remove the implementation code from the method here. And we're going to put those in robots.txt CPP. So the first thing to do in Rabat, the TV, include robot dots, HBP. We include the header file. And now what we're going to do is exactly the same as we did for functions. Okay? I'm going to just copy the Antioco here for all the functions and put them here, paste. So as you can see, we have an indentation. I'm just going to select everything and do Shift and Tab to remove one in notation. In robots dot HPV. I am going to remove now the implementation. So I'm going to remove brackets and just put here. So I'm trying, I need to run that for the constructor as well. Just going to put the prototype of the function or the method, and just put a semicolon, okay? Just like this, like this. And like this, I can group the methods and you can see now it's much clearer. You have a robot dot HVP in which you declare the class robots. You can see the attributes and you can see all the methods. So if you want, you can add some comments here maybe. So when you actually need to use the class, you can just read that and you can see that you need to pass a name, version number. And then you have a method to say hi, a method to any hardware metal to print info. You don't need to know the specifics of what's inside the code. And let's go back to our solid save this file. Let's go back to our robot dot CVP. Actually, doing this is not enough here. What you need to do is you need to add the prefix robot colon, colon to each method name. So for the constructor you will have robot colon, colon, robot for say hi here. You're going to put that after the datatype. So void robots say hi. Okay, because you can see here when we didn't have that, we had an arrow here. Name is undefined because actually here you are kind of in the global scope. If I put robot, Say hi, This is the sayHi method from the robot class, okay? If you remember, that's very similar to name-space, okay? Using namespace was the same thing. So basically, this is kind of when you create a class, you create a namespace robot for the different methods. So if you want to implement the method, you have to put the namespace first. Robot colon, colon, robot colon, colon here. And also here you can see Say hi is undefined because we are outside of the robot class. Robot colon, colon. And now this should work. Hey, it's saved is fine. And now, well, the HPV file is complete, the CPP file is complete. I'm going to remove all that. And I'm going to include here, include robot dot h. I'm going to remove a string here also. And just by including robot dot HPV, it's going to include the class with the implementation, with everything. And you can get access to the robot class. I'm going to save, save everything. So here, our main program, our main CPP file is very clear, very minimal. They're shot at the ribbon. Then we have a header file which is called the interface. This is what you need to see. This is the interface of the robot class or the robot library for example, this is what gives you the information of what you can call, what you can use, etc. And then you have this syllabi Phi, which is the implementation. Okay, So we have separated the interface from the implementation. The implementation here you can see, well, you have all the code for all the methods here that you have declared in the interface. So now let's run this. And actually, if you just run this, That's not going to work because it's just going to try to compile main.cpp without the robots dot CPP. So I'm going to do g plus plus to make sure you are in the correct directory. G plus plus domain dot cpp with robots.txt, BB dash 0. Let's call our executable robots within S, just any name you want. And then dot, slash or backslash robots. And you can see we have the exact same thing we had before. So here we didn't add any functionality. We just changed the code organization. Alright, so now not only you know how to create a class, but you can also clearly organize your code, which will make your entire application easier to read, easier to modify, and easier to scale. 48. Intro to Inheritance: In this video, I'm going to introduce the concept of inheritance in OP. This concept is quite big and complex. So this is just an introduction to it. So you can get the very basics. No problem if you don't understand everything the first time here, this is really an intermediate level. Alright, so let's get to it. Let's say now you want to create a class for a robotic arm. For the robotic arm is actually a roped, which means that to create the robotic arm class, you will need to write again, most of the robot class code here, because a robotic arm will have a name, we'll have a version number, will have an internal temperature, will have those methods, etc. And there is a way to avoid doing that and directly create the robotic unclass on top of the robot class. And this is actually called inheritance. So let's see what this is and how to do directly with a code example. I'm going to create a new class, robotic arm. And actually what it can do is I can directly create a class here in the same file, okay? After the class robot, okay? You can create multiple classes inside one, a fight just like you can create multiple functions. You can create multiple classes. So I'm going to name it so class robotic. Okay, so uppercase and lowercase for each word. And now I'm not just going to put directly the curly brackets. I'm going to put a colon and then public robot and then curly brackets. And I don't forget the semicolon after the last curly bracket. So what this means here is that this class is going to inherit from this class with a public inheritance. So there are different kinds of inheritance. I'm going to stay with public here, which means that basically the robotic arm class without anything here, already has the three private attribute here and the different methods here from the public. So everything that is public and private inside the robot class is also available inside the robotic and plus. And now what you can do is you can create more attributes and more methods that are specific to the robotic arm class. And you still can get access to the robots functionalities. So here I'm also going to both public and private, Okay, Just like we did here. And in private, I'm going to add a new attribute, which is for your Pole, Double rich. So what is the rich of the robotic arm in millimeters, for example, okay, as you can see, this is very specific to a robot car, okay? You can see that every robot has a name, but every robot doesn't have necessarily a rich depends on what kind of robots. But for a robotic arm, it makes sense to add rich on top of all those attributes. So I'm just going to add one more attribute, which means that now the robotic arm class has four attributes, a three here and that one. And I'm going to add also the method for the contract. So robotic arm, okay, that's the name of this. And I'm going to put string name, int, version, version number, and double rich with a semicolon. Okay, I'm just going to put the prototype here, so the declaration. And then I'm going to put the implementation in the CPP file directly this time. So here I asked for the name, the version number HE IS goes also the name version number, and I add also the rich for a robotic arm. So I'm going to copy this Control C. I'm going to go in Rabat dot cv. And I can also add this here. So I'm going to paste that and put some curly brackets. And this time I also need to put the kind of the namespace for the class. Robotic. So make sure you have robotic arm here. So this is a method of the robotic arm class. This is a method of the robot class. And this works because we have included robot dot-dot-dot HBP, where we have declared the class. So how can we actually write this constructor where we are going to use the same syntax here. Okay? So I'm going to put here a column and I'm going to initialize each of the attributes. But actually, we already have a constructor for the robot class. And it's already initializing the name, the version number, and internal temperature that is also available in robotic arm class. So what I can do is I can directly call the robot contract or here after the column. And I'm going to give it a name and version number. And after that, I'm going to put rich. Rich, okay? So I'm going to put the rich, I get here inside the rich attributes. I have a, you can see here robotic amperage. So as you can see, creating a constructor for a class that inherits from another class, it is very practical. You can call the constructor of the parent class directly in the child class. And we have nothing ready to add here. So I'm going to save this. Come back here and now, well, the class is already complete. We could just create a robotic arm like this. I'm going to add two new functionalities, okay? I have one more attribute. I'm going to add two new functionalities. For example, void pick object, let's say double x, double y. And void place objects double x, double y. So the robotic arm can pick and place objects. So I'm going to create a pig object and place object method with coordinates in the form of x and y. Okay? And those functionality that you can see are very specific to a robotic arm. So it doesn't make sense to put them inside a robot. And if you have a different class, Let's see, for example, a drone, which would be also a robot. So you could create a drawing class which inherits from robot. You would not, but pick objects and placed objects from the drug unless it has this functionality. Okay, So make sure that when you add a method to a class, make sure that this method actually makes sense for this specific class. Now that I have my prototype, I'm going to just copy this and paste that here. I'm going to remove the indentation with Shift Tab. I'm going to put curly brackets, remove the semicolon. And I'm also going to put robotic colon, colon here and robotic column, column here. And now I just need to write the code. So the code actually I'm not going to pick an object. I'm just going to print c out. Let's say pick objects from. And let's put a parentheses. But x. Let's make something nice like this, y. And let's close the parenthesis. And, and I just print the coordinates. Okay, I can just copy this here and just put place objects to pick from place to with the coordinates we get as parameters. I'm going to save this. I am going to save this. And I'm going to go back to my main.cpp. I already have included robot that HPV. So now what I can do, I'm going to just comment dotted lines here. What I can do is I can create a robotic arm, which I'm going to name it unforgettable. And I need to give it a name. Let's call it Bob version four and reach, let's say 300 millimeters. I put a semicolon, and now I have the robotic arm instance in my code. What I can do is God. And as you can see, I have all the different methods. So in IT hardware, print info and say Hi from the robot class, and then pick objects, placed objects from the specific robotic arm class. So I can do, for example, print info. And then I can do dot. Let's say pick objects. I'm going to put 12, place objects, 34, just for the example. I'm going to save. And now if I want to run, well, I need to append terminal. Here. Let's compile again. I don't have any new file so that the same common. Let's run the code. And you can see, Hello, my name is Bob, ready to help chemicals, namely the version number for temperature is 30. And then pick objects from one to place, objects 234. So that worked. And if you want to go further with that, you could create a class, for example, for a mobile robot and Mumbai Bayes, drone, a sudden marine, etc. And think about what functionalities and what attributes are going to be specific to each kind of robot. And then declare an implement the classes with the different methods and call the different robots here from your main function. All right, so here you have seen how you can use the power of inheritance to create programming blocks on top of other programming blocks without reinventing the wheel every time. 49. Best Practices when Writing C++ Code: This is now the conclusion section of nice cplusplus schools. And I want to give you a few best practices I've learned from my own experience before you continue your C plus plus Jony, those will help you write better code and solve problems in a more efficient way. Let's start. First tried to respect naming conventions. This may change from project to project, but basically, for one specific project, you should have the same rules for all variables, all glasses, etc. If you start your variable's name with an uppercase letter, fine, but do it for all the other variables you have in your program. And if you join an existing project, then just follow the existing roles already in place. Doing this will force you to be consistent. It will make your life easier when reading code from others who are also respecting those conventions. And it will make other people's life easier when reading your own code. Well, the conventions are simply here to facilitate collaboration. So use them properly. Also give meaningful names to your variables, functions, classes, et cetera. If you need to raise the temperature, then name the variable temperature and not something like TPD, TBLT for reasonable, just to gain a few characters and add a lot of confusion about what your variable means, then use the standard or std library whenever you can. Don't try to reinvent the wheel when you have a problem to solve. First, check if you can find a function, a class are whatever in the std library that can solve your issue. This library is really big in you will often find a solution. Another best practice is to try to not repeat yourself, use loops, functions, and if needed classes, whenever you can, create building blocks and reuse them instead of writing the same code all over again and all over the place, then end. This is more general but also super, super important. Keep things simple. It's not because your application is complex, that your code should be complex or complicated. Think before you write code in, right? Just what you need. You don't create the foundation for a castle when what you really need is a wood Kelvin. All right, so don't optimize your code and actually don't optimize that all before. You already need to keep things simple when you go to the point and focus on solving the problems you really need to solve. And the more. And the last advice I'm going to give now is to search on Google and actually practice searching on Google. This, I can tell you, is there a real skill that unfortunately is completely underestimated by many people? Being good at programming doesn't mean, you know, all the functions of all the languages by Hurt being good at programming is about being good at solving real problems using code. And a part of that is searching on Google whenever you don't know something. In fact, if you ask any developer, are there including me, what's the mostly do in a day? They are probably going to tell you, well, I search stuff on Google. You don't need to know everything, but you need to know how to search for information and how to apply that information to solve a given problem. This is the real value of a great developer. 50. What to do next: Congratulations, you have just finished the course with what you've learned. You should now have a much better understanding of civil service. And you should be convenient to write your own first programs and applications. And now it well, there is no magic here. This is only the basics of C plus, plus. What you've learned is the solid foundation you can now use to go further. So the next step for you is to pick an application domain and continue to learn C plus plus with this domain. For example, video games and beliefs, software, robotics, artificial intelligence, operating system, etc, etc. There are so many applications you can do with C plus plus. And basically all the industries in the world use. And most importantly for the following, it's important to work on projects. So try to get your own project or follow online resources which also have a project. But so you can practice. Practice is really the key here. The more you practice and you challenge yourself, the more you're going to progress. All right, time for me to say, thank you for taking this course and I hope to see you soon.