Complete C++ programming from C++ Basics to Advanced C++. Learn C++ from Scratch. | Muhammad Hamza AbdulRehman | Skillshare

Playback Speed


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

Complete C++ programming from C++ Basics to Advanced C++. Learn C++ from Scratch.

teacher avatar Muhammad Hamza AbdulRehman

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

47 Lessons (2h 45m)
    • 1. C++ Introduction

      1:06
    • 2. Envorinment

      1:57
    • 3. Variables and Numbers

      3:36
    • 4. Mathematical operations on Numbers

      5:16
    • 5. Strings

      1:23
    • 6. User Input

      4:21
    • 7. What are header files

      1:17
    • 8. Loops Introduction C++

      0:58
    • 9. For loop

      6:58
    • 10. Task Factorial

      0:58
    • 11. Solution Factorial Code

      5:45
    • 12. While loop

      3:19
    • 13. Adding Multiple conditions in while loop

      2:13
    • 14. Task Tables App

      0:28
    • 15. Solution Tables App

      4:53
    • 16. If else

      3:43
    • 17. Task Grade Program

      1:01
    • 18. Solution Grade Calculator

      3:38
    • 19. Optimize Code using else if

      3:35
    • 20. What are Arrays

      1:38
    • 21. Arrays

      4:49
    • 22. Size of Array

      2:06
    • 23. 2D Arrays Explanation C++

      0:37
    • 24. 2D Array Code

      4:32
    • 25. Functions C++

      1:54
    • 26. What is OOP

      1:41
    • 27. What is Class and Object

      3:51
    • 28. Class

      3:02
    • 29. Constructor of a class

      2:02
    • 30. Make Object

      4:09
    • 31. Adding variables and functions to book class

      10:26
    • 32. Multiple Constructors in a class

      5:43
    • 33. Encapsulation and Access Modifiers

      6:37
    • 34. Inheritance Explanation C++

      3:18
    • 35. Inheritance Code

      6:35
    • 36. Access Modifiers

      5:22
    • 37. Polymorphism Explanation C++

      3:34
    • 38. Polymorphism Code

      7:31
    • 39. Abstraction Explanation

      2:07
    • 40. Abstraction Code

      2:00
    • 41. Pointers

      0:50
    • 42. Pointers Code

      2:31
    • 43. Pointers of different datatypes

      4:25
    • 44. Array of Pointers

      4:35
    • 45. Benefits of Pointers

      3:59
    • 46. Dynamically allocate memory using pointerss

      5:08
    • 47. Benefits of pointers explanation

      3:49
  • --
  • 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.

20

Students

--

Projects

About This Class

In this course you will learn C++ programming starting from Fundamentals and going to advanced topics like Object Oriented Programming and Pointers.

In Basics Section we will learn:

  1. Loops
  2. Conditionals
  3. Numbers
  4. Strings in C++

In Advanced Section we will learn:

  1. OOP- Object Oriented Programming.
  2. Inheritance
  3. Polymorphism
  4. Abstraction
  5. Pointers

This course is designed for complete beginners because topics are explained in detail and step by step explanation is also provided for some.
 

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. C++ Introduction: Salam alaykum high, their peace and blessings be upon UDL students. I welcome you to this complete C plus plus programming course. This course starts from the very basics of C plus plus programming and takes you to the advanced level topics in C plus plus programming. So how to learn programming better? The simple answer is by doing so this course, besides other topics that includes fundamentals and advanced topics, there are coding exercises in between. I will also give you the solution of those exercises so that you can compare your code with dab. So either it's a complicated subject like class and objects in object oriented programming or inheritance. In object-oriented programming, we will learn that all. Or it's a topic like encapsulation. We will learn these topics beside fundamentals like for loops and conditionals and loops and numbers and strings. All of that we will cover in this course. So I'm looking forward to see you in this course. Thank you. 2. Envorinment: Welcome to the first coding session of the C plus plus scores. I'm in God editor. And in this session I will tell you about this environment and code editor, a few things about Discord editor. I'm using Eclipse at an ASM code editor. You can use any code editor of your choice. The code will be same. So our purpose here will be to learn code. This is the starting code and we will be using the score God in all of our coding sessions. So this will be our base code. What this code is, this is our main function. You can think of your main function as an entry point for the compiler. So all the code we write is inside of this main function. So you can think on main function as the main gate of your house. From here you enter. This will be the point from where compiler enters into our code. This on top you can see is a header file. There are a lot of things we use from this hetero, hetero file. You can think of it as a library where there are a lot of things that we can use that are ready-made. So we will get into the details in our upcoming sessions for now, I will just give you a brief introduction to this code editor. On the left here is our directories. We're all are like you can say files go and all other those things. And this top green button here you can see this is used to run our code. Now I will run this code and you can see this is our console window where our output of programs will be shown. So currently it is empty because we have nothing in our main function. So I will get into functions in detail when we move ahead in upcoming lectures. So for now I will just add a c out here to bring something so that you can see in the output screen, this is my first load. So I will now run this. And as you can see in the output window, it says This is my first code. So C out is used to print in this output window and see outcomes from this iostream library. We will get into the details of these in our upcoming sessions. So dapsone from decision. 3. Variables and Numbers: Welcome. In this session, we will learn about variables and numbers in C plus plus. So I'm in code editor and this is our main function. So I will do coding inside of this function and I will get into details of these functions and these header files in my upcoming lectures. So for now let's discuss about variables and numbers. So let's say we have a number 60 and we want to use it so we cannot keep it randomly here at any place. So we have to store it somewhere so that we can use it. We have to store it in some variable. So what I will do here is I will name a variable here, let's say 60. You can have any name of this variable of your choice. So what I'm doing here is as the value is 60, so I have named it 60, and then I will add a equal to sign here. So what I'm saying here is this variable contains value 63. So now I will have to define that. What type of value is this? So I have to define the datatype now. So this is integer. All the numbers in C plus plus are referred to as integers. And for dad, we use a datatype int In specifies that this variable will contain a value that is integer. So all the positive and negative values can be stored in these variables with datatype integer. After that, I have to close this line by a semicolon. So every line in our code editor is closed by the semicolon, which indicates that this line ends here and now we will move to next line. So all the lines will be ended with the semicolon. So let's move ahead and make some other integer variables as well. Let's say I have another integer variable, I can define interior and then the name of that variable, let's say I have a negative value. So I can, and I will put it equal to some negative value, let's say 80. So now what I've done here is I have made another variable negative value and put it equal to minus 80. So now these two variables can be used in my code when I will specify this name 60 at runtime, this will be changed to this value. Runtime means when I run this code. So this is the code editor where I'm coding. And whenever you press this green arrow button, this will run this code. And when we run our code does all things are compiled here. That compiler read those and get a meaning out of it. So as we have these values in integer in data die, we can also have decimal point values, but decimal point values have another datatype. Int cannot store decimal values. So for decimal, we use float. Float is a datatype for a decimal value. Let's say I have a number, I can name it anything, I will put it number and 90.80. So now what I'm saying here is this is a decimal number. And when I want to store a decimal point number in some variable, I have to put datatype float. Float is the datatype for decimal points. And we have another datatype for decimal points as well that is called double. So double is also used for decimal points. Float is 32-bit size and double is 64-bit size. So it can contain double the large size of value if we have a large size after this decimal point, this decimal point here, if we have large value, then we can use double. And if we have small, we can use float because float is 32-bit and 64-bit. So their basic function is same. I can define an another number here. So let's say number 2 is equals to 7.7. So this is how we declare variables and assign values to them. So that's all from this session. And next session we will learn how to perform mathematical operations on these numbers and variables. 4. Mathematical operations on Numbers: Welcome. In this session, we will learn about how to perform mathematical operations on these variables and numbers that we have here. So we have currently two integer variables and one float and one double variable made. So now let's perform addition on two variables. For dad, I need to store the result in some variable. So what I will do here is I will say integer, I've named the variable sum. So this sum variable will contain the sum of variables as I have there. So I will put it equal to, let say 60. Now 60 will be replaced by this value 60. Then I can add this operator plus to add. And then let's say I add this number here as it is a float. And I can keep on adding as I want things to be. So let's add two values for now. So 60 plus this number. As you can see, this number is a float, has a decimal point. So integer, we'll ignore the value after decimal point because it has integer if I change it to float or double, it will also include that. And to show the SUM function on my output screen, I need to do C out. So I will just write as C out here. And after these C out, I will write some here. So what I'm doing here is this c out is, comes from this library iostream. What does this library iostream, you can think of these libraries as they contain bunch of functions and useful things that we can use to make our code easier. So This PSC outcomes from this iostream library. If you remove this library from here, this will give an error. Okay, I will quickly run this. As you can see in the output it shows 150. So via 160 plus this number 90 equals 150. So it prints the result and it has ignored this decimal point value, 0.80. So if I want to include this point AT as well, I will change it to float. Now I will run it again. And as you can see, it says 150.8. So it depends upon the variable datatype that what it will be containing. So now if I remove this iostream library from here and this part, let's see what happens. As you can see, it gives us an error. It says errors can be read from here. As you can see, this is error use of undeclared identifier C out. So C out is real, it is inside of that library. So I will just undo the changes. Now this iostream library has the C-out. Think, now I will run this again and it will run fine. As you can see, 150, 0.8. And if we add an another value here, let's say num number two as well. It will also add it to the result. As you can see, it says 158.5. And instead of these variables, we can also use simpler values. Let's say I add a value here, like a 100. So now my research should be to 58.5 there. So I run it again. And as you can see now it has 258.5 in my output window. So we can perform these operations. So this is for addition. Now let's write it for subtraction as well. We can, instead of sum, I will make a integer variable. I will name it, subtract and put it equal to 16 minus 10. So what it will do here is it will just subtract 10 from the Sixth Street. And now instead of C out some, I will use subtract. So I'm just going to print the value of subtracting my output window. As you can see, it says 50, 60 minus stamp 50. So all these operations are similar. We can add as many values as we want and variables here. So one more thing to note here is variable is called a variable because its value can be changed. If in this line I write here like 60 equals to 10, then it will update the value of the variable. Let's see. As you can see how the output is 0 because I made 60 variable equal to ten, and here it was replaced with 1010 minus ten is 01. More thing to note here is that when we have made a variable with the datatype int like this, 160, when we update its value, we need not to define the data type again. So I need not to write into here again. So we can simply just by writing the name of variable, we can change its value. So now we will make it for multiplication as well. So I will make an another variable, int multiplied. And in this variable I will multiply 60 with, let's say I multiply it with a 100. And I will just remove this updating parts. So 60 contains 60. And I will run now, I will see how to multiply here. So I will run this and 60 multiplied by a 100 is 6 thousand. So we can use this asterisk sign for multiplication, and we can add as many variables here. And it works for multiplication, same as it is for addition and subtraction. Now I will make an another variable, divide. And I was voted equal to 64 divide. We use this symbol and let's say I divide it by 10. And instead of printing, multiplier will print here divide. So I will run this again. As you can see, it prints six. So we can perform these mathematical operations on our variables and we can add values there and do a lot of stuff with these things. Currently we are just displaying this value on the screen. So that's all from this session. 5. Strings: Welcome. In this session we will learn about screen datatypes as we have integer, double, and float datatypes. Similarly, we can also have screen datatypes for Dad, we have to include a header file. I will quickly do that, that is hash include. And the name of that header file is string dot h. So to create string variables, we will use this string dot h header file to get that string class. So I can write the name of this data type like string, and then the name of my variable, let's say fruit and put it equal to some string, apple. So fruit has a data type string and it contains a value that is apple. And it says screen, we can have long and short strings and that all can be stored in the string class. Now I can have some biggest strings in this as well. So writing the name of the datatype and I will name this where even long screen. And put it equal to long-term. Let say I am a very long string. Example. Now I can print these strings similarly as we did for integers and doubles, by using C out, I can write the name of string and it will be printed on the screen long string. And when I run this, you can see in the output window dat, it prints that screen. It says I am a very long string example. So if I will change the long string to fruit, it will print apple there. So we can have different string of our choice. Debt can be used in our code. So that's all from this session. 6. User Input: Welcome. In this session we will learn how to take user input and to take user input, we use c in and c out. So let's see how it's done. First of all, I will write c out and to less than signs. After that, I can write any statement that I needs to be printed as it is on the screen. So I will say enter your name. So what I'm asking user to enter his name after that, I can already see in two greater than signs after C in. So now what it means here, now I'm getting some value from user, so it will stop here and it will wait for user to enter some value. So after writing the c and I have to specify a variable in which I want to get that value. So for example, if it is a name, I will make a string variable named name. So what is the string variable industry worry about, I will get that name. So after the c and n two greater than signs, I will write this name here. So now the value that user enters will be inside this variable name. Now I can just use this name anywhere in my code. So I will just print on the screen dat. For example, if I want to show the user that his name is, so I will write your name is. And after that, if I want to include this variable, I will just add two less than signs, again, because this is a string and now I'm going to specify a variable. So I will just divide it with these two less than signs. After this, I will write name. So now it will print this name. They are in front of this statement. So let's run this and see output. As you can see, it says Enter your name here from this line and it has stopped. Now it wants us to input the name. So I will input here, John, for example. Now it says your name is John. So whatever name I enter here, it will print that. So that's working. See incumbency in is used to enter this name. Now, similarly, as I have used this name, I can also get integer values. Suppose I have two integers, a and integer b. Let's say, and I want to get these two values from user and then add those and show it some. So what I will do here is, first of all, it will ask enter your name, and after that, it will put that name in this name variable. And then I will repeat this thing. I will say enter value of a. So a is this variable which we have here. And after this I will put it in a variable. Again, what I will do, I will repeat this thing here. And I will ask the user to enter the value of b now. So I will say enter value of b, and I will put it in a variable named V. So now we have this name here in name, a has first value, second value. Now we can simply add a plus b, and now it will say your name is, name, whatever the name of the person is. And then after dad and with C out, some off, a plus a and B is. So this will show the sum. Now we can add a plus B here. After adding these two less than operator simply I can write a plus B. Now it will add a and b and showed in the output or else we can also do this mathematical operation in some variable as well. And we can just put that variable here, but I'm directly doing it. It's fine. You can do this this way. So what I will do next is I will go ahead and run this code. So to see the output. As you can see, first it says Enter your name, so I will write comes up. So now name is Hamza. Now it says enter value of a. So what is value? I will write 10. Now it says enter value of b. I will write 20, not ten plus 20 should be 30. As you can see, it says your name as Hume's are. And then after debt sum of a and B is 30. So now as it is in same line, we can also use one more thing here in this line, your name is after this. I can use these to less than operator and right, and L, which is endline, it will move to next line after that. So I will run this. As you can see, it says enter name, I will write Peter value of a, ten, value of B, 20. Now it says your name is Peter, sum of a and B is 30. Now this statement is moved to next line due to this and L which I added in this c out statement. So this is how we did user input and use those in our code. So Dax, all from this session. 7. What are header files: Welcome. In this session we will learn about header files. So have you noticed from we're DC out and see in comes from the c in and c out are in this iostream header file, which we are using here. If you remove this header file from here, this program is running fine. Before we'll give some errors. It says, let's read the error here. It says use of undeclared identifier, see out. It doesn't know about this. So what we are doing here is we are adding this iostream header file, which is in C standard library, and this string dot h header file to get this string here. So we use this iostream, iostream stamps. I stand for input, o stands for output and stream, input, output stream in this hydrophobic file. So this allow us to use this C out and C in that we can use for user input. If we do not use this header file, we then need to figure out a way to input user commands and that would be difficult tasks. We have to write that code ourselves, but this library gives us the C out and C in that we can use to just simply do these procedures. So there are a lot of more header files that we can use to make things easier here in our code. And we frequently use those while coding so that we can use them and get benefit like these that I can have here is user input and showing it in output screen. So that's all for this session. 8. Loops Introduction C++: Welcome. In this session we will learn about loops. Loops are very important when we want to run a specific part of code over and over again. Let's understand it with the help of an example. Suppose we want to print from one to ten on screen. One way of doing it is writing density out commands. And if it is from 1 to 500, we have to write 500 C out commands. So dad makes a lot of code. This can be replaced by only one C out command. But how that can be done, that by writing only once you out command, we can achieve all this that can be done through loops. Loops are very important. There are two main category of loops for loop and while loop, we will learn them in detail in our upcoming sessions. Currently we have understood it with the help of an print example, but there are a lot of more tasks that we want to perform by writing code data required to run over and over again with different values. So all those tasks can be achieved by using loops. Let's learn them in our upcoming sessions. 9. For loop: Welcome. In this session we will learn about for loop. So I'm in code editor and this is our main function. So I will quickly make a for loop here. To make a for loop, first of all, we use a keyword for which defines that we are going to make a for loop. Then there are two wrong brackets. Inside of these two round brackets. Define three things and they are separated by semicolon. So what are these three things? First of all, we have to tell this loop from where it has to start. And then we have to tell it where it has to stop as it makes sense. Because we need to tell this loop from varied needs to start and where it needs to stop. So first of all, I will declare a variable here named i, and I will put it equal to 0. So what I'm saying here, I'm saying make a variable I and put it equal to 0. So this is the starting point, start from 0, and then I have a semicolon. So first thing is defined. Now, I have to tell how many times this loop should iterate. So I will say I less than 10, let's say. So I'm saying start from 0 and go to I less than 10. So this will be the stopping condition here where it will stop and then 13, that is of most importance. What we will do here, we need to tell the increment as initially I is 0. So now we have to define that what increment will be there so that this condition, it will reach this condition. So what I will do here, I would say I plus plus. So simply what I'm saying, in every iteration of this loop, increment I by one. So I plus plus means increment I by one. So now I will use these curly brackets and inside of these beggars, we write the body of this loop. So what I will do here, I would simply print the value of I. So I will write c out i and then endl to skip the line. So simply I'm printing the value of I will run this code and then we will do a little dry run here. As you can see, it started from 0, then 123456789. So why it stopped on nine? Because we say I is less than, then, if I will do here less than or equal to 10, and I will run it again. You can see it started from 0 and ended at ten. It included then as well. So what it did, first of all, it went here, it check for the variable, the variable was 0, and then a check for the condition that it is less than 10. So it was less than 10. So it went into this body without, in the first, it didn't went into this part. So only the first two parts were red. That is, I is 0 and it was less than 10, so it printed the value of I. Then from here it went to this part of this statement. It incremented i, so I initially was 0, then it became one. And then it again check for this condition here, one was less than 10. So it again went into the body of this loop and printed the value of I. It will keep on repeating this process. That is, it will go here to this part. It will increment I and then check for this condition and go into the body. So this bottle for loop is only the advance data is initially. After that, only these two parts will be read again and again in every increment of our loop. So now what we can do, we can do a lot of combinations here for different types of loops. And finally, when I will be incremented to 11, this condition will fail that I is less than or equal to 10. So eventually we will reach a point where I is equals to 11. So this condition fails and we will not move into the body of this loop. Instead, we will move out of this loop to this statement return 0. So now we can learn about different combinations here. There are a lot of nominations currently we are incrementing I by one, so we can change it to increment by two. So what I can do here, I will say I equal to I plus 2. So now simply I'm saying increment I by two instead of one. So let's run it. And as you can see, we have increments of 202468 and 10. So successfully we have incremented it by two, we can do anything here incremented by three. That is also possible. So we haven't in the output, we have increments of three. Now, we can also make this loop reverse. Let's say I start from 10 and a given condition here, it is, I is greater than or equal to 0. So now it will be reverse loop. I've, instead of incrementing i, i will decrease it. So what I'm doing here, I'm starting from 10 and have a condition here. I is greater than 0, greater than or equal to 0. So I'm saying when it is less than 0, that is minus1. Stop this loop. And now I'm decreasing dy by one. So now I will run it. And as you can see, the loop is in the reverse 10987 and so on. So this is another combination here. Now we can also take an input from the user and Saturday or so, okay, I will write a statement here, C out, asking the user for how many dimes you want the loop to run, how many times you want to run. So user will given in particular, and what we will do, we even see in it and some variables. So I will make a variable here in user input. So in this way, he ever lived a store word user has given me the number, so I would say c, n and user input. So I'm getting the input from user and storing it in this variable named user input. And now what I will do where I will use this variable, I will use this in for loop. Now here I will start from one. Let's say, I recall, I will start from one and then the number user has defined. I will give it here. So what I will say, I is less than user input. And I will add equal to here as well. So as we are starting from one, we will start from one. And then whatever the user input is here, we will be going to less than or equal to there. And then instead of degrees I will increase i by one and we will bring the value. Let's see, by running it. Now it says how many times you want loop to run. So let's say four times, as you can see it printed 1234. Now again, I will run it and given another input, let's say I say it a 100 times. So as you can see, it ran for a 100 times. So this is all loop works. We can have multiple combinations here in this round brackets are for loop. There can be multiple combinations that we can use depending upon argues that how we want to use this for loop and how, how many times we want it to run. So we can make multiple combinations here in this for loop. So that's all from this session. 10. Task Factorial: Welcome. In this session I will give you your tasks to perform. And in the next session I will also be giving you a solution of this task, but I would recommend that before you go to the next session, you try this task yourself. This will be your concepts stronger. So your task is to make a program that can calculate factorial of any given number. So this program will work like this. First of all, it will ask the user to enter a number. Suppose user entered five, then it will display as factorial. That is, factorial is 120. So it will calculate the factorial of any given number. So the hint in this program is the formula for calculating factorial is this, that you keep on multiplying that number with one less number than that until you reach one. So if you are given any, given any number by applying this formula you can calculate is factorial. So this program should work on any number given. So that's your task. In the next session, I will give you solution of this. Does 11. Solution Factorial Code: Welcome. In this session we will write code to calculate factorial. So I'm in code editor and this is our main function here. So the first thing we will do here is we will ask the user that the number which he wants a factorial to be printed. So we will take the number from user and then we will print the factorial of that number. So I will use c out to ask user enter a number. So now user will enter a particular number and we will calculate the factorial. So the next thing I need to do here is I need to get this number which user will enter. So I need to have a variable here. I will name that variable number. This will be that number in which we will save that number. So now I will use C in statement to get this number. So now this statement will get us the number. So user will enter a number and we will put that number in this variable named number. Now we will just calculate the factorial here. So how we can do that, we will use for loop for that because we do not know that vision number user will enter and we have to multiply it with the numbers less than that. So I will use a for loop here. Wrong records are FOR loop, I will make an integer interior. So this will be the starting point from where our loop will start. So what I will give you, I will give number minus one. So why I'm doing this? Let's look at this figure. Suppose the user goo is file. Does the user want us to calculate the factorial of five? So what we are doing, the number variable here, which we have just made in our code will contain the value five. And now our next step is to multiply it with one less value, that is four. So I will start the loop from one less value. So number minus one in this case, when we have value five will be four, number minus one will be four. We will be starting from this. Then I will write here the stopping condition. That is I is greater than 0. So as we do not want to move on to 0, because when we multiply anything with 0, it will get to 0. So I'm saying keep this condition greater than 0, so then it becomes 0, this loop it stopped. So next thing I will do here is I will just, I have to give the increment here. So what I'm doing here, I will give I minus minus because we have two degrees. The value we are starting from one less than the number, and then we will keep on decreasing it until we reach 0. So when we read 0, we will stop. So initially in this example, as you can see in the figure, if we start from five, the number minus one will be four. Then when we will be decreasing, I minus minus, that will get it to three, then two, then one. So that's what we want. So it will keep on decreasing the value until we reach 0. And when we read the room even stop this loop. So that is the formation of this loop here. So now what we need to do here is we need to calculate the factorial in the body of this loop. So how I can do that, I will create a variable here named factorial. So now we have another variable name factorial. In this variable, I will calculate the factorial and then I will put factorial equal to number. So suppose we have number five of which we want to calculate factorial. So I will say factorial is equals to number. So initially factorial will be containing the same value as of number. So we're starting from five. Suppose the example we are starting from five factorial will contain the value five. So now in the body of this loop, I will say factorial is equal to 2 factorial into I. So what I'm doing here, I'm saying initially factorial will be five in our example, and then I will before as we are using number minus one here. So five into four will be stored in this variable factorial. And then after that, as you can see in the figure, what we need to do, the result of 5 and 2, 4 will be multiplied with three. So as we know, factorial contains five into four. So it will be then multiplied with three and it will be stored. The value of this factorial variable will be updated every time. And then we will be multiplying it with one less value than I, which was previously. So it will be calculating factorial here. And then finally, when we move out of this loop, we will display the result to the user and the result will be invaluable factorial. So we will say C out. Factorial. Factorial is, let's say, and then we can add the variable here. So simple even show the result by adding a statement factorial is and then our variable, which we have here. Now I can just run it and we will see the output. So it is asking us to enter a number. So let's say for the first example, I enter five here. And as you can see, it shows it correct factorial here that is 120 or five as it multiplied five with four then 321. So this statement results to be 120. So that's correct answer. So how it did that? Let's relook at this code a little bit. So when initially we entered five, factorial has the value five, then it went into the for loop and stored the value four in I. So multi here, but in the initial run, 5 multiplied by 4 and store the result in the same variable factorial. And then in the second iteration of this loop here, in this Victorian variable, we had a result of 5 and 2, 4, and then it multiplied it by three. It continued this in every iteration of this loop by decreasing the value of I. And then finally, this variable factorial contains that value. And then we printed the value to the user. Now if we run it again and we will give it an another value, let's say I give it three and factorial of 3 is 6, because when we multiply three with two, it's six and then one will give us the same results, so it's six. So for every value we give here, it will calculate the correct factorial of that variable. So that's all from this session. 12. While loop: Welcome. In this session we will learn about while loop. While loop is a type of a loop where we have a condition and as far as that condition is true, that loop runs. So I'm in code editor and let's make our while loop. So I would write while here for specifying that it is a while loop. And then these two round brackets. In these two round brackets, we can define condition for which this while loop will run. So I've defined that condition, but before that I will complete this loop by adding these curly braces. So in the body of this loop, we even write the thing that we need to run in loop. So this is the y loop here, and let's give her some conditions. I will make a variable here. I didn't name it counter and put it equal to 10. So we have a variable named counter and I will write the condition here that counter is greater than 0. So this loop will run as long as this counter is greater than 0. So when it becomes, this condition becomes false, this loop will stop. So what I will say here, I will just bring this out and I will write here I counter which we have here and then angle for moving to the next line. So I will just bring the value of counter every time. So now this loop will go in an infinite loop. Why? Because counter will always remain done and this condition will always be true. So that's why we do not require that we need to stop this loop at some particular point. So what I would see here, I will decrease the counter by one every time. So it will eventually become less than 0 because I'm degrees in the value of counter here. So let's run this and see the output. As you can see in the output, it started from Den, then printed the values by decreasing one value and move to one. So after one, this condition field here in the loop, because when it became 0, it was not greater than 0. So it, it was, it failed, this condition failed when it became 0. So it didn't continue after that. So that is how a while loop works. There are many benefits of by Louis can provide other conditions here as well depending upon the situation in which we are. So let's run this for a different type of condition here I will say this starting from 0 or instead, I will just do it here. I will take the input from the user do instead of doing that. So I will say C out. How many times you want the loop to run. So user will give some input here and we will depending upon that in both. Let's take that and put in some variable here. I will say counter, which we have here. So I will move it on top of this. So now we have a counter variable and we're getting that counter here inside the value. The value and user gives me are getting it in counter. So now it will, depending upon that value, this loop will run. So let's run this again. So here is just asking for the number, let's say a 100, I entered 100. So what it did here, it moved for every value. So this little continuity, Let's see, by increasing the area started from a 100 and move to one, all the values are printed. So we can do different kinds of things with this while loop. So that's all from this session. 13. Adding Multiple conditions in while loop: Welcome. In this session we will learn how to add multiple conditions in while loop. So currently we have one condition in our while loop and I'm in code editor. And what we're doing here is we're asking the user home anytime he wants the loop to run, and then we are running that loop for that specified down that user sees. So now I will add more conditions here. We can add conditions by using AND and OR operators. So I will write AND operator here. So this team, this operator will allow me to add other conditions. So let's make a Boolean variable here, Boolean. So I will say a Boolean so that can be true and false, right? Limit check. And initially I, let's make it equal to false. So now I will add here Jack. So simply I have to check. So if this will be true, it will run the loop otherwise not because we are using the AND operator, both the conditions after the and operator and before the AND operator, that is this one. And this one should be true. So that loop will run. So currently when I run this code, this will not print anything inside of this loop because this condition check is false here. So let's run this. And as you can see, it is asking for the input. Let's say I add 40 here and when I press Enter copy, it didn't did anything. Why? Because this condition failed. Check what's false. So if I change it to OR operator, Lexi, I'm for our iMovie have to use these two lines. So what, now we say here, any of the one condition can be true for this loop to run. So whether this condition is true or this condition is true, or both conditions are true, this loop will run. So let's see. I will run it again. So let's say run for 10 times, as you can see, it run for the 10, for 10 times. And this condition was false. So it ignored this condition because of OR operator. So now I will change it to true. So and I will change it to end. And you can see here that this will run. So let's say I run for three times and it printed 321. So that's all we can give multiple conditions here. So we can use these values with different combinations and Eigen further also give conditions here, combination Eigen given another AND operator here, and specify a condition after that. So depending upon the situation, we can give different types of conditions here by using AND, and OR operators. So that's all from this session. 14. Task Tables App: Welcome. In this session I will give you your task. This task is to practice while loop, so you have to perform it using while loop. In this task, you have to make a table's program that when this program runs, it will ask user to enter a number. So when a user enters any number, it brings it stable. So no matter what number user enters, it will Brent, it's stable. So you have to do it using while loop. In the next session, I will be given solution of the stars. 15. Solution Tables App: Welcome. In this session, we will learn how to calculate and print a table of a number that user enters. So this will be a table to map. The first thing in this app we need to do is we need to ask the user to enter a number. So I will write c out. And here I will say Enter a number of that I would bring to the table. So in the next line, I will get that number into some variable. I've named that variable table, and it will be int variable as it will. This variable will contain the number of which we will be printing the table. So I will write here C in. And in this table where you will, I will cache that number that user enters. Now the next thing we need to do is we need to print the table of that number. So I will be using a while loop here. I will write vial and inside the condition of this while loop, I will make a variable here, count, and I will put it equal to one in starting. So what this count variable will do here is it will start from one and move to 10 as we have to print 10 rolled off the table. And we can move further into this code. We will learn how to bring more rows as well. So now in this while loop, the condition will be gone is less than or equal to ten. So why I'm doing this condition here that less than or equal to time as we have initial value of count equal to one. So we will keep on increasing this value one by one, and we have to go to 10. So we have put it equal to less than or equal to 10. So as long as this condition will be true and this while loop will keep on iterating. And as soon as the value of count will become 11, this while loop will terminate. So now in the body of this loop, we can increase 10, we can increment count by one. So this thing by writing count plus plus will increase the value of count by one. So this thing will be there. And now we have to make the row of that table. So we have, as we have two brands, so I will write c out here. Now we will make the formation. The first term here will be the name of the table. As if it is five. If user enter five, it will be five and 21 equals 25. So the first thing here will be the name of the table. Suppose if the user entered five, it will be five. Then after that, we will add across sign here. That is for multiplication table into I have added these two spaces so that there is a gap between this multiplication symbol and the table name. And then there will be this count variable, as in first row, it will be one, then it will be increased here, then it will become 2, 3, and so on. And the next thing would be equal to sign here. That is there. And finally, here will be reserved to result should be calculated. So what I mean, right, I will say table into account simply. So this thing, this expression table into count, will be evaluated as table name. For example, if it is five and count is 15 and 2, 1 is 5, 5, and 22 is Dan. So this expression will be evaluated first and the result of this expression will be printed. So simply, we will have the solution here. So after that, I will also add an L here to endline to move to next line so that every time this loop iterates through this statement, it also moves to the next line as well so that all the things are not printed on the same line. So that's all from this abnormal, all the things will be calculated. This loop will be iterated ten times and printing from one. Okay, before running this, I can see your simple spelling mistake here. It's not C out its count. See you at UNT counts. So here in while loop condition we are using count variable. Initially it is one, then it would move one by one. So dads fits. And now when I run this code to see the output, okay, it says enter a number. Let's say I enter five here. And you can, as you can see, it printed the table or 5521 is 55 into two, is 105 into three is 15, and so on. So we have correctly made it tables app. Now let's run it again and bring the table of any other value. So let's say it's a 100. So it had rented the table of 100. Now, what we didn't do changes here. Now when we change this value that is in the condition of the while loop, we can make it print any number of roles. Currently, these are 10 rows. Now if I change it to, let's say 30, it will start renting 30 rows. So let's run this. I will enter a table here. Suppose I say F4, and as you can see it printed the table of four with 30 rows and all of these values are correct. That's how we make the tables app. I will just give you a quick overview of what we have done. First of all, we have get in number from a user, then we have made a count variable that we are changing, that we are incrementing in this while loop. And we have a while loop that stops on this condition. This condition fails. So initially it was 10, we have changed it to 30. So the main thing, the formation of the table row is done here. This is the single row of that table. First thing is stable. Then we have made information here and here we have calculated the value. So we can change this according to our requirement and can try different formats here. So when it comes out of this loop, it has printed the complete table. So that's all from this session. 16. If else: Welcome. In this session we will learn about conditionals, that is if and else. So I'm in code editor and let's begin by writing our code in this main function. First of all, I will make two variables, that is a and B. The first variable will be a and I will assign it some value, let's say four. And then I will make an another variable that is b and I will assign it some value, let's say seven. So now by using if and else, we will control the flow of our code. So to write a conditional, use a keyword if, and then after writing this keyboard Vietnam records here in these two long records, we can provide any condition after this, we have body of this conditional data, two curly braces. And in these two round brackets, I can provide any condition. Let's say I provide a conditional that a is less than b. So what I'm saying here is if a is less than b, then move into the body of this if conditional. And then if it is not less than b, if a is not less than b, then move into this else part that I can add by adding this keyword that is else. So if a is less than b, it will move into this part of code. And if it is not less than b, then it will move into this part of code. So by this, we are able to control the flow of our code. So let's tell the user that is less than b. By adding a c out, I will tell you their dad is less than b, so that user can know that a is less than b. And here, I can add that b is less than a. So I will quickly run this code and we will see our output. As you can see, a is less than d, So it says a is less than b. And if I change the value of a 240 now is not less than b. I can run it again, and it should say b is less than a, and that is true. So by doing this, we were able to control the flow of our code. That is, initially when a was four. And it said that a is less than B, as you can see in the output, it went into this part of code because a was four and D was seven. So, and it ignored this else part because this is only executed when we are not inside of this part. So initially it executed this part and left this pot of gold. So now when we change a to 40, it will move into this else part and it will leave this if Bob bought unexecuted. So only the else part was executed in this case. We can also use only if without using this else part. I can remove this as hot as well. And we can also add multiple condition here in if depending upon our situation. So let's make an another variable that is C, and I will assign it some value that is 60. So now I have three variables equal 40 and B7 and C6 3. So now I can add another condition here that is, and a is less than c as well. So I'm saying that if a is less than b and it is also less than z, then move into this if conditional. So what I will say here is less than b and a is less than c as well. So let's decrease the value of a. 24 now is less than b and it is also less than c. So it should say this, it should execute this part of code as I'm using AND operator. So boat up both of the conditions before AND operator and after AND operator should be true so that this thing will be executed otherwise not being and also use our operator here by adding two lines. So I will run this on us here. Output, as you can see, it says a is less than b and a is less than C. So that's correct. Now let's change the value of a 240 now it's not less than b. So what did we do here? I will run this again. And as you can see, there's nothing in this part because it was not less than b. So that's how we can control the flow of our code by using if and else statements. So that's all from this session. 17. Task Grade Program: Welcome. In this session, I will assign you a task that you can do using conditionals. So this task will be that when you run this code, it will ask the user to enter your marks. So if user enters marks 80 or above AD, like if I enter a D2 here, it will tell you that your grade is a. And if I run it again and if the marks are above 70 and below AD, let say 74, then the grade is B. So we have a bracket of 10, like 70 to 80, then 60 to 70 and so on. So I will again run this and you can see if it enters 60 or above. It will say your grade is C. Similarly, if it enters 50 or above, let say 55, it will say your grade is D. And if the user has marks less than 50, then it has to say, like, you fail the subject. So if marks are less than 50, it says you fail the subject. So you have to perform this task using conditionals. In the next session, I will provide you with solution of this task. 18. Solution Grade Calculator: Welcome. In this session, I will provide you with solution of grade calculating application. So I'm in code editor and let's start for that application. First of all, we have to get user marks. For dad, I will make an integer variable named marks. So in this variable I will just input marks from user. So to get the input, either ask user to enter his marks, enter your marks. So now I will just input these marks in this variable named Mark. So I will use C in. And so we will ask the user to enter his marks. And after that we will get those in this variable named marks. And then by using conditionals, first of all, we will test whether these marks are greater than 80 or not. So I would write if marks are greater than or equal to AD. So if they are greater than 80 or they are equal to ADP will give it a grid a. So in the body of this if statement, I will see that your grade, this is a. So by doing this, we are just telling you that his grid is a. And next I will write a gain and another if statement in which I will check if marks are greater than or equal to 70. And by using an operator, I will restrict that they are also less than 80. So I will say marks are less than 80 because if they are greater than 80, we have already assigned a grade a. So if they're less than 80 and they are greater than 70 or equal to 70, we will give grade B. So I will see you out here. Your grade is B. Similarly, I will do it for other as well. I will repeat this if statement. Now I will change it from 70 to 60, and this one will be 70. So if they're greater than or equal to 60 and less than 70 is grid will be C. Then again, I will repeat this thing here. Now this will be 50 if they are greater than 50 and less than 63. So we will assign a grade D. And finally, we will say if marks are less than 50, then he failed that subject. So we will tell the user that you fail the subject. Okay, that's all from this and we have all the if statements ready. And now I will run this and we will see our output here. As you can see, it is asking for Marx, Let's say I enter 60. It says your greatest see, because it went into this if condition that if marks are greater than or equal to 60 and they are less than 70 or greatest. See? So it said your greatest C. Now let us run this again and enter marks like 90. It says your grade is a. That is correct. It went into this if condition and it didn't went into any of these other if conditions because it's conditioned for you there. Now let's run this one more time and I will enter marks that are less than 50. And as you can see, it says you failed the subject. So it went into this part of our code and ignored all the other parts because condition failed there. Now this is the very basic implementation of this Grails application. In next session, we will learn about else. If and after that, we will optimize this app again. So that's all from this session. 19. Optimize Code using else if: Welcome. In this session I will guide you how to optimize code using else. If so, I'm in code editor and this is our previous code of grades program. So what this program does here is it asks the user to input is numbers. And after he inputs is Mocks, it calculates it grade depending upon those marks. So let's have a deeper look on this golden what it's doing so far. So let's say user entered marks that are 90. So first of all, it check for this condition that whether it's greater than 80, so 90 is greater than 80. So it will output juicer that your greatest eight. And after doing that, it will further move into discord and check for this condition as well. And for this condition as well. And it will keep on jet and for all the conditions which we have here. So that's the flow of our code right now. So if check all these conditions in this program. So now to test this, I will just remove this part from this condition here, and I will run this code and we will do a little analysis here. Let's say it says Enter your marks. I enter 90 here. As you can see it printed your grid is a, and after data is also printed, your grade is B. So why it does that? First of all, it went into this condition. So 90 was greater than 80, so it printed this your greatest a after debt. It check for this condition as well. And 90 was greater than 70 as well. So it printed your grade is B. So what, what is the need of going to this condition when we found our results here? So data is useless that we are checking these condition as well, our program mistaking a lot of time there. So why we waste our time in these conditions. So we can optimize our code that when we found our result, we need not to move any further. So what I will do here is we will add else if. So, what else if means here that if this condition is fulfilled, then do not move to this part and only move to this part, then this condition fails. So if marks are not greater than or equal to 80, it will move into this part otherwise not. So I will do it for other conditions as well, and I will remove this part here. As you can see, our code is getting optimized and it is getting neater here. So we have to do less code to achieve our results. I will add else here as well. So now behind every if I have added this LCM, so now it becomes elsif. So first of all, it will check for this condition. If it is true, it will move into this and it will ignore all of these. If this condition is false, the first condition, then it will move to second. And if that becomes true, it will leave other part of code as it is and do not execute that. So if the only all the conditions will be checked, only if it moved to this condition. So dad has benefit of using else if I run this again and you can see the output, as you can see, it's saying enter Mars, Let's say I enter 90. And now this code is working fine. Your grade is a because it went into this part and this was true, so it ignored all other parts. I will run this program again and let's enter 65 here. And as you can see it says your greatest see, so how it achieved that. First of all, it went into this condition. This condition failed, so it went into this other condition, the second one, this condition also fail because 65 is less than 70. And then it went into this condition and this condition was true. So it printed your greatest see, and it ignored these two conditions here. And it didn't execute it any part of this quote from this side. So that's how we optimize our code. So we write less code and we achieve our goals there. So by using else-if, we can optimize our code. So that's all from this session. 20. What are Arrays: Welcome. In this session we will learn about areas. Area is a type of linear data structure where data is stored in the form of a sequence. Suppose we want to make six integer values in our code. So do store those six integer values. We need to have six integer variables to store them. Instead of those six integer variables, we can store all of them in a single array. Like if we have six values, 10, 578, 24, we can store them in a single array. Array is in the form of a sequence, so every value is at particular index. The starting index of array is 0, then the second index is 1, third is due, and so on. Area is of fixed size. So while initializing an array, we have to define the size of that array. If we initialize an array with size three, it will allocate three memory blocks for that particular array. And if you initialize an array with a size five, then it will allocate five memory blocks. For data array, we can have short and long areas depending upon our requirement. And if we initialize an array with 10, it will allocate 10 memory blocks for that particular array. We have to make arrays very intelligently because if you make an array of size 10 and we only use two blocks of it, that is, we only add two values in that particular array, then rest of the blocks will go wasted because array memory blocks or only dedicated to that particular array and cannot be used by any other variable inside of our code. So if we allocate an array with size 500 and only use few blocks of it. That is, we add only a few values in that array, then rest of them will get wasted. So we have to make an array of size that is required by that particular array. Let's learn array in details in our upcoming sessions. 21. Arrays: Welcome. In this session we will learn about arrays in C plus plus. So I'm in code editor and this is our main function. So I will go ahead and make our first array. So first of all, we have to define the data type of array which we are going to make. So I will make an integer array. So I defined interior. We can specify anything like double float character depending upon the area which we want to make. So I will name this array. Array. We can give this name, any name of our choice. I give array here, you can give any of your choice. After dad, we will add two square brackets falling this name of that array. In these two square brackets, we can define the size of this array as array is a static data structures so its size is fixed. We cannot change its size. So let's go ahead and add some values in this area. So let's say I add three values, 1, 2, and 3 in this area. So by writing these values in these two curly braces, I have defined that size of this array is three, and it has three values, 1, 2, and 3. So these value will be on their specific indexes. That is, index starts from 0. So one is on index 0, do is on index 13, is on index two. So indexes start from 0. Here in these two square brackets, I can also write three, which will define the size of this array. So when we are initializing your directly after this equal sign, there is no need of writing explicitly here that what is the size of this array. So by given these values, three values, I am saying that its size is three. So let's print any of the value from this array. So I will use c out and to print any value, I write the name of this array. And then falling by two square brackets in these two square records, I have to define the index number of which I want to print the value. So if I want to print this value to, this is on index one. So I will write one here. And we will run this to see the output. As you can see it printed to dat is on index one. So if I write 0 here, it will bring value one that is on index 0. So as you can see in the output, it printed one. So this is how we make our array. There is another way of making this area as well. That is we're not initializing it in the same line. So what we can do here is we can define the size here that is three. And after that we can add values there by writing the name of this array and index number. So by saying 0 here, I'm referring to index 0. I can add value there, so let's say 10. And on index one, I have to Andy and an index do we have 30? So this is how we can also add values in this array. So now if I run this again, it will print 10 here. Because Dan is on index 0. We can also update values after adding those. So on index 0, I have added ten, and if I add it again and another value on index 0, let's say 500, it will update that value. So when I run this again, and as you can see, it printed 500, so it updated the value at index 0. So this was the array with integers. If we want the area with floats or doubles, we have to just change the datatype. So let's say we have an array of floats. Now it will contain value with decimal points. So let's say 10.120.330.8. Let's say we have these values. I will remove this update of this array and we can just run this and see our output. As you can see on index 0, we have 10.1, so it printed 10.1. Now let's change the index number 2, 2, and we will see the output, as you can see it printed 30.8. So this is the result which we want. So now we can also have an area of it's screens for dad. I have to include a header file of strings, so I will just copy this and include string dot h header file by which I can just use strings. So I will write here string instead of float. Now we have a datatype string here, and this array can now have string value. So let's say we have Alex, first string is Alex, that is name. And second, Hamza. And third, let's say iOS. So we have three names, Alexandra, vastly different indexes of this array. Let's run this code again. And as you can see, we have a bass on index two, so it printed that. Now let's bring the value at index 0. That is Alex. As you can see it printed Alex. So we have this array of strings where we can have strings at different indexes of this array. So this is how we work with one-dimensional array. That's all from this session. 22. Size of Array: Welcome. In this session we will learn about size of array. Array is a static data structure, which means that it has a static size. That is, its size cannot be changed. So for example, this is an example from our previous lesson. We have a string array with three size. So it can has three values, not more than that, has less values, but can not have more than three values. So array refers to a static data structure. Its size is always fixed, so we have to define the size of our array when we are specifying it. So now I will run this code and as you can see, we are printing array value at index 0, so it's Alex. Now, as we have specified, three has a size of this array. Let's add another value in this area and see what happens. So index 2 was lost index on index 3, I add James. So I have added a value at an index of array which is not there because this array is supposed to have three values and I have added four values. Now let's run this. As you can see, there is nothing in outboard that is our code stuck somewhere. Dad is here, as you can read this morning, array index three is past the end of the array, which contains three elements. So this area was supposed to be having three elements, not four. So we have edit and another element here, and this is wrong. So you have to keep in mind that array is static and is effect size. So while making this thing here, making array, we will define the size of this array. Now if I change this from three to four, now it's going to be good because we have four values. Now I will run this again. And as you can see, it printed Alex again without any warnings, warnings iPhone. So if I change it from 0 to three, it will bring james. Now that's fine. And if I change it to five and I have added for values, that is fine because we have just left the last index empty. So I will run this again. And as you can see, it goes correctly. And printer James, now if I add other values, it will add them correctly. So that is what we need to take care of. That array size is fixed. So that's all from this session. 23. 2D Arrays Explanation C++: Welcome. In this session, we will learn about two-dimensional array. Two-dimensional array is a type of array where we store data in a form of a matrix. That is, we have rows and we have columns. So this particular area that you can see on screen is of dimension two by four, which means that it has two rows and four columns. We can have 2D arrays with different dimensions. That is three by 34 by two, two-by-two. And any offered twice, a 2D array with dimension three by three will have three rows and three columns. And the dimension four by two, we'll have four rows and two columns. Similarly, a duty Arabia dimension two-by-two will have two rows and two columns. 24. 2D Array Code: Welcome. In this session we will learn about 2D arrays in C plus plus. So I'm and go to editor and we can make our first duty area here. Two-dimensional array is a type of array in which we have data in the form of a matrix. That is, we have rows and we have columns there. So we can adjust our data in rows and columns. So to define a 2D array of first of all, we have to define its datatype, whether it is integer double float or anything else. I will make an integer 2D array, and let's name it array 2D. So it's a two-dimensional array. We can give it any name of our choice. I have given a rare duty. You can give anything of your choice. So after that, we add two square brackets here. In the first year record, we will define the number of rows, and then second we will define number of columns. So let's say I want three rows in this array and three columns in this area. So this will be your duty array with three rows and three columns. After that, I have to put data inside of this array. So how we can do that, I will write to Berlin braces here. And inside of this, I will make three beers of these curly braces like this. So in these curly braces, the first one, I will add the first row and then insect in second curly braces I will our second row and in turn curly braces, I will add the third row. So that's how we put data inside of this area. So let's say infrastructure I have 1, 2, and 3. In second row, I have 456, and in turn draw, I have 7, 8, and 9. To better visualize this, I will just move it to next line so you can better understand this. Now, this is row number one, which has three values, 123, then rule number two, and then row number three. And similarly we have columns. This one 147 is in column 1, 2, 5, 8 is in column 2, and 3, 6, 9 is in column 3. I would just add them, Roosevelt, right, the rows as increments. So this is row one. Now row 2 here. So this is row 2. And finally we have row 3. So we have three rows here. Now we can just print any value to see how this works. So to bring these, I will write c out and then the name of array data is array 2D. After that I will add two square brackets. These two square brackets, we'll have the index number of the element which we want to print. Remember that this is row one. The index of row one will be 0 because indexes start from 0 instead of one. So this is row 2, but it's index will be one, and this is row three. And its index will be too similar is the case with column. So 147 are in column 1, but their index will be 0. So let's print this value 5-year, as we can see, it is in second row. So the first thing I will add here is one, because second row is with index one and it is in second column. So I will write one again here in its column space. So when I run this frequency five printed in the output, as you can see, the value five is printed. So if we want to bring this value nine, this is intergral, so I will write 2 here and it is in third column, so I will again write two here. So let's run this. As you can see it printed nine here. So we can specify the number of row and column, the index number of data, and we can bring, and we can use those values as well. So what if I want to add more value? So as this contain three rows, Let's add the fourth column. So for data, we'll use number 4 here. Now this 2D array has three rows and four columns. So I have to have some value at the other column, let say 50, 60, and 70. So now we have three rows, but there are four columns. So let's print the value 60 years as it is in second row. So I would use one here and it is enforced column, so I will use three here. This will print the value 60. As you can see, values extreme is printed. We can also update values at some particular index. For example, before printing the value of this index of this array, I change this value by writing this. So I'm seeing this array 2D. We have row number with index one and column number with index three less than that value from 62, let's say 345. So I have changed its value now, no lecture on discipline. As you can see, it rented 345 instead of 60 because we change the value. So we can also change value at any particular index as we want. So this is how we create two-dimensional areas. So that's all from this session. 25. Functions C++: Welcome. In this session, we will learn about functions. You can think of function as a processing unit that day if something has an input process on it and gives us some output. Suppose we have a function sum, so it will take two values as an input, add them in its processing unit and give us solution as an output. Suppose we have an another function named factorial. So it will take some value as an input, calculate x factorial, and give us some output to define a function. First of all, we have to define the name of function. So that can be anything offered drugs depending upon what functionality that function is going to perform. And then into round brackets, we have to give arguments. These arguments are input of that function. We can give an argument, two arguments, three arguments, or any number of arguments of our choice. A function can also perform without any arguments. So if there are no arguments, we will keep these do wrong brackets empty. Then we have a return type. So return type of a function is the datatype dysfunction is going to return that can be integer, double, float, array or anything. So the body of function is enclosed in curly braces. All the functionality that this function is going to perform is going to be there in these two curly braces. Suppose we have a function sum, then the name of the function will be some. And as an argument, it will be taking two values of which it needs to calculate sum. So it will be integer a and integer b. We have to define the datatype of vert. This function is going to have an argument. So return type of this function is integer because after calculating sum of these two variables, it will return us a integer value. And in the body of this function is simply add those two values which we get in the argument of this function and return those. So input of this function is argument a and b. And output of this function is some value a and B that is returned by a command return. So we use a command named return to return from any function. 26. What is OOP: And welcome to this session. In this session we will learn what is object-oriented programming? Programming can be mainly divided into two bars, procedural programming and object oriented programming. Procedural programming is that basic VR programming in which we go into our main function and write each line of code here. So a compiler start from the very beginning of our code, read it line by line for every step and moves to n. So everything is combined that same place. And this is called the procedural way of programming. And the other way of programming is object oriented, where we have classes and objects. So what we are doing here is we are dividing that same chunk of code into different modules on their similarity and type. So in procedural programming, If we have a very large file of code where we had thousands of lines of code, then it is very difficult to manage that code. You cannot manage that code easily because that code will be having so many lines and you will not be able to differentiate between different parts of dead code and it will not be extensible. So to replace this, we have object oriented programming where we divide our code into modules which are small and have that specific code which belongs to that module. So what we are doing here is we are just putting things in different modules that are easy to manage. So now these, this is extensible code and we can easily manage it. So there are benefits of object oriented programming that we can reuse our code using objects. Data hiding is important concept here, modular structure, which we have just discussed that we are dividing the large file into modules and code is extendable when we know about what we have in a particular module, we're going to easily extend it. So these are benefits of object-oriented programming and this will make more sense when we move further into this course. So let's move to our next session. Thank you. 27. What is Class and Object: Welcome. In this session, we will learn about class and object in object oriented programming. And this concept is very important in object oriented programming. So let's start and we will understand it with the help of an example. Suppose a construction company needs to build a building. So what they need to do for us, they cannot go directly at someplace and start making that building by joining breaks. So that is not the case. They cannot do that. So what they need to have first, they need to hire an engineer that will make a blueprint of that building. So first of all, they need to have the structure of that building built on paper or something before they can go ahead and make that original building out there. So Dan blueprint, which an engineer will make for that building, is called a class in object oriented programming. That blueprint has no real value. It's not something real out there. It's just a structure of that real thing on paper that we call Hebrew blueprint. And now, by using this blueprint, we can go ahead and make an original building out there. Because in Blueprint structure will be defined and everything. So now we can have some people there that can build their building. And that original building is called an object in object oriented programming. And now by using this blueprint, we can have another building out there as well. So now there are two buildings of same blueprint. And we can have a target on as well. And we can have any number of buildings out there by using this blueprint. So this concept is called class and object. Class is basically something referred to as a blueprint that defines the structure that how that real thing is going to be. So we need to have glass there. And by using debt clause, we can make as many real objects in object oriented programming. So object you can think of as something real that has a real value. Class is not real glasses something on paper and object is something real. So this concept is called class and object. So by using this class building, we can have Building a, B, and C out there. And these building a, b, and c will be real, but they will be derived from which class building that will define its structure there. Similarly, a car manufacturing company needs to have a model of car before they can start manufacturing that God. So any company needs to have debt engineering model there. So they will hire a person that will make that guard model there. And after this, we have that model of cards here. We can have any number of cars from that model. We can make those cars and factory by using that model, but we need to have that modeled here. So this model is called class and the real cars, which we, which we will make out of it, are called objects. So everything in real life is a class. For example, if you have a house, houses the class, and if you have a car, a car is a glass. You laptop is a class, your computer is glass. And anything you can think of in real-world is a class. Before we can have objects on that, we need to have something defined for that class. So what class is composed of? It is composed of two things, properties and functions. So what are these? If we have a car class, what will be the properties of car? It's colored top speed, number of wheels, doors. These all will be properties of this car. And you can get refers to how this looks and what discard have will be in properties. And the second thing of glass has is a function. So what functions guard can perform, it can accelerate, it, can start, it can read and apply break on this and we can stop discard. So any mechanism that any process there discard have any functionality that the scar is have IS, goes in this function part. So class has two things, only two things, properties and functions. You can refer to anything. If you have a building, then it will be have properties like color. How many rooms, how many floors, functions will be. Like you can open the door, you can close the door, and things like that in that building. So everything, every class has properties and functions. Here we have looked at an example of a car, but when we go to an example of book, we can open book that will be function, the color of book will be its property. Number of pages of that book will be its property. So we can, we can define these things in any of our class. So first of all, we have to define a class with the properties and functions. Then we can make any number of objects from that class. Now, let's move into code editor and write some real examples there of glass and object. 28. Class: I welcome you to this coding session. In this session we will learn about glass. So we have a basic idea of glass that it's a blueprint of which we can make objects of. So I'm in code editor and let's make our first class. To make class, we will define it outside of our main function. And to make a class, we use a keyword named class. So when we write this keyword, now it knows that we are going to make a class. So now we have to give a name to our class. So it depends upon what type of class we have. So let's make a book class. So I will name it book. The first letter of this class is capital, that is B is capital. So class name always starts with a capital letter. This is a good practice. We can also make it with a small b, but that will not be a good practice. So all, so make sure that you make a class name starts with a capital letter. Always. So after having a name, now we have defined that we have a class named book. We will have two curly braces. Now, what these two curly braces means that all the body of this class we can go inside of these curly braces. So what class basically have, you can think of a class as a container. So class is a container that has only two things inside of it. So two departments in a container, the first one will have the variables and the second one will have the functions. So that's it. Class will have only two things inside of it. First department, we add variables like properties, they are what this book class will have, like price, number of pages, name of author, and all those things goes into this variable part and other functions which we have like calculate number of pages, calculate price, get price, that author like these, the different functions that will be related to this class would go into second department. So overall, you can think of a class as a container which has two things, variables and functions. So let's make our first variable in this class. I will add two commands here. The first one will be variable. To understand that VR is we are adding things in these department variables and properties. And you can rename this and other things will be functions. So I have two commands. They are all the variables I add will go here and all the functions I add will go here. So let's make our first variable. Dat will be integer price. So for every book we have a price. So we have made an integer variable here, price. And as you can see in this image, price goes in this variable department. Now I will add access modifier here, like public. So what is this access modifier? We will get into details of these assess modifiers in our upcoming sessions. But for now, just keep it as public means. All the things that I will declare below this public access modifier will be accessible outside of this class book. So we need to have in there. So we have multiple other access modifiers like private, so we will discuss them in detail in our upcoming sessions. So now as we have our first variable DIR, it's time to add our first function there as well. So our first function will be constructor. In our next session, we will learn about constructor. So that's all from this session. 29. Constructor of a class: Welcome. In this session we will learn about constructor. So what is constructor? Constructor is simply a function that has seemed name as of glass. So if we have a className book, then the constructor name will also be booked. So why this constructor is specific? Because constructor is the only function that is called automatically when we make an object of this class. So when I will make an object of this class in our upcoming sessions, the only function that will be automatically call will be constructor. We need not to explicitly call that function because there can be a lot of function in this book class that I need to specifically call on the object of this class, I need to explicitly call those functions, but constructor will be the only function that will be called automatically on the object of this class book. So I will go ahead and make that function in Dysfunction part of our class. It will be named book as we know, constructor has same name of glass, so glosses and invoke the constructor will also be named book. So constructor is a function and it do not have a return type because constructor is only called once and it is used for initialization. So what we meant with initializations that the variables which we have in this class are initialized in the constructor. So if we have a price, I will set it to something some value. If I have, if I have no value, I can set it to 0 if I want the user to set this value. Otherwise, let's say I set a price of a 100. I can also get this price from user by adding a deer like this and set it here in the body like this. As often normal function, we get the arguments or user now has to provide this price there. So for now, just to keep it simple, I will say the price is 100 and it will have no argument here. Now, as you can see in this image, book, function goes into function part of our class. So it's a normal function and we can categorize it in our functions bar. So currently we have two things in our class. First one is a variable and the second one is invoke function. Now it's time to make an object of this class. So in our next session we will be making object of this class. So that's all from this session. 30. Make Object: Welcome. In this session we will make objects of this class book which we have there. So it will be our first object dir. Currently we have a book class, and as we know, book class is just a blueprint. It is not something original, it is just the definition of bugged and what we are going to have there. So object is the real example, or we can say that is the real thing that we made out of it loss. So we have our class book there. Now it's time to make an object of this class. So how we can do that, Let's see in our main function to make an object of this class book. First of all, I have to write the name of the class, so as it is book, so I have written book here and then I have to define the name of the object. So there can be off our choice. We can name it anything. I will just name it book with a lowercase b. So now it's an object and it is very similar to other. Like we are, let say we are making integer a here. What we're saying here is an integer and its type would be it. Similarly, we are making your book object and we're just seeing this data type will be book. So it was very similar to other implementations. So now, as we have our object dir named book, constructor will be automatically called. Surprise will be set to 100. As you can see, we are not explicitly calling this constructor, but it will be called. So let's print out the price and see whether it is set to a 100 or not. So I will do a c out there. And how I can assess this price here as it is public. So I can write book dot price. As you can see, intellisense is telling us that prices inside that book object. So I get that price here and now I will run this and we will see the output. As you can see in the output it prints a 100. And I never call this function book. So it means that it is automatically called when I made the object. So let's make an another function in this class. I will name this function set price. Just to understand distinct better dysfunction. We'll set the price very able to, let's say 500. Now, I have two functions. They are both function that has a constructor and a set price function that is an another function in our class. I will run it again and you will see that the value of price is still 100 because set by its function was never called. So All the function besides constructor should be explicitly call if you want their implementation to run. So only constructor will be run automatically. Know if I call this function, let's say Book dot when I, when I, when I dot, it will also show me the functions. As you can see, it says in your class there is a price integer and a set price function there. So I will select this one. And now, first of all, this function constructor will be called, it would set the price 200 from this slide. And then this function will also be called, and it will set price to 500. So we will have a new Bryce printed here that will be 500. Let's run this. So as you can see, the value which you get an output is 500. So this function was called, and we need to explicitly call this function here. So that's how these things work. They are only constructor, it's called automatically. So now we have a class and we have an object of it named book. Now we can have any number of objects that we want. So we have this implementation of glass there and now we can have book one, book two, book three, and as many books, as many copies of this book as we want. So that is how it's useful once we have implemented a clause and now I can have a book to hear as well, like this book too. I can name it anything off of my choice and it will have. And if I print the value of book do here, Let's do it endl here. So to skip the line and then I will see out the price of book to book two dot price. So what it will do, it will bring the price of book 2. Now what we have here, book one price would be 500 because we have called this set price function. But book, book to Bryce will be a 100 because only constructor is called on that function. So Book 1 is a copy of this class and book 2 is and another copy it has in other values inside of it. So these are two independent objects with different values. They can have different values and all the things that are in this class are available for both of these objects differently. So let's run this. And the first value printed will be 500 and the second is a 100. As you can see, the output is correct. So we can have any number of objects from this class. Now we can add variables and functions to this class book in our next session. So that's all from this session. 31. Adding variables and functions to book class: Welcome. In this session we will add a few other variables and functions to our book class. Currently we have a book class and we have a price variable there. Add a constructor name book, and a set price function there. So now we can make our class and add a few other variables that this class will require. So every book will also have a name. So why not have a variable named? It will be a string variable, I will call it name. So every book should have a name, so I haven't named variable there and then there will be author of every book. So we can also send that in here. So it will be string author. So every author will have a name and that will be set in this variable named author. And after this, we can also have a title of that book. So it will also be a string. I will name it Dido. So now our book loss has four variables, name, author, title, and price. So we can add as many variables as we want in our book loss. So let's go with these four variables for now. And now we have a function name set brace here. So we can give user the control to set the price. So we can get Bryce here, like integer. We can say price value. So now we will get a price value here and we will set it to our price value variable. So what we are, we will get into separate function. We will set it to our price variable here, which we have in our class. So this set price function will do that. What this constructor will do as it is a no argument constructor weekend set values to default here. So for example, let's say we have, if a user doesn't set a price for that book, we have a default price of 100. And what name we would have? V will have empty string in this name, which was specified. There is no name yet and author will be also equals to this empty string. Antigen will also be equal to empty string because we do not know it. Start What these will be until or unless user said these values there. So we can have functions to set these values like name, author, and title. So let's make these functions here. I will call it wide set author, or first of all, we can set the name of book, set, name of the book. So this function will set the name of our book and it will be taking a string as an argument that will be named Of book. So this set name of books in this body of this function, I will just set this namestring to what we have in the argument of this function. So name will be equal to this name of book. So simply setting the value of name. Similarly, as I have made this function for name, we can also meet this for author and title of this class. So let's quickly also define those functions here. So it will be wide set author, said otter, and it will get the name, name of author. Author name. And I will set it do Arthur. Arthur is equal x2 attorney. And then finally, the last thing here is to set the title of distinct. So let's make an another function, void setData. And this will get it idle string. Title of the book. Let's name it this. And I will say title is equals to title of a book. So what we have here, we have our variables and we have our functions to set those values to our variables. So now what our class looks like. So all of the variables goes in this variable part of our class and all of the functions that we have setName, set author, insert title goes into the functions part of this class. So now our class looks great because we have all the tin specified in their specific, specific bars. Variable goes into variable bars, name, author, title, and price. So whatever we add in this class, we will specify them in these two categories here. So we have this object named book here. Now I can call all these function on this book object. So let's call one function here. So when I have made this book object, first of all, constructor will be called and all the values will be set to the default values which I have here. Now I can set price here by writing the name of book, book dark set price. And what I will give here is I will give the price what I want it to be. For example, I want this book to be off 300. So this function is called and the price will be set to 300. Now I can also call the set name of book on this book object, Book dot set. When I write this dot operator, it should show me IntelliSense. And as you can see, it shows me all the things which I haven't disclosed, all the four variables and all the four-function. So I will select this setName of book and I will set something here. I will name it learn C plus plus. So I have this book named learn C plus plus. Now I can set the author of this book, set author, dad will be, let say Hamza. Then I can also set the title of this book. As you can see, I can set all these things by on our object, and it's very simple here. So I will set the title here, learning C plus plus in detail. So let this be the title off our books. So we have our book radiates prices 300 years. The name of the book is learned C Plus Plus author is Hamza, and the title is learning C plus plus in detail. So now all these values will be set to these particular values. So when I will bring to any of these things like c out, Let's say dido, book dot title, name of the object and then variable. So let's see what it prints here. It will say learning C plus plus in detail. As you can see, it says learning C plus plus in detail. So the title, if I change it to author, Let's see what it prints. It should print Hamza here. As you can see, it prints sum. So we have this unique book here that is not something real of this class book. So we can make other objects like I can make an other objective of this class like book one, book two in Book 3 and set different values for that as well. So now you might be thinking that we are setting price here in this function set price, but we can also set it directly like this, like book dot price is equals to 400. So why we are making a set price function here and setting the value there? This might be the question arising in your mind. So why we are making this function instead of directly setting these values. So the benefit of making these function here is we can apply constraint on this. For example, if I directly set a price here to 400, user can also set it to something like minus 800. Debt will not be a correct value. So let's see. If I commend to set price function and I print the price here, Let's see what it prints. So it prints minus 800 and deaths what is not acquired. So v I can apply a constraint here on the set price function that if price value, value is greater than 0, because I don't want it to be negative or 0. So if it is greater than 0, then it is a correct value. Otherwise, I will set it to something default, let's say, or I can show user and error that no, this is not a correct value. I will tell the user that this is not a correct value for price. So this is how we can handle these things here. Now as you can see, I am handling this thing here in the body of this function. Dad, I cannot do if I directly said this price here, dot-dot-dot prices because three minus 800, so that's not required. I will set the price and a function and I will apply my constraint there as well. So now if a user cette surprise of minus 500 or let's say something, instead of setting that price to our price variable, it will say this is not a correct value of price. And then it is also printing the default value a 100 because we have called the C out here. If I remove this and run this again, you will see that it says this is not a correct value for price. So I have applied this constraint as of my choice. So I can do this on other things as well. For something name of book as well. If I want that name of books, you'd only have like 20 characters, not more than that. I can also add that and on for set author, if I want some constraint on author name, I can add those and they can be applied constraint on this title of book. So we have those functions here to set the value. And if I now set a correct value here like 400, that is not a negative value. So it will simply send that value. As you can see, it doesn't show any error message and I can print that value here. And it will be, as you will see, that it is set to that book, Book dot price. It will be set to there. So let's run it again. And as you can see, it sets, sets that value. So directly setting the value of these variables is not suitable. And we will learn in our upcoming sessions that what we use these public and private access modifiers and that will explain these things in a better format. So I will be doing that in upcoming sessions. So now let's focus on this object as we have this book with the price 400 and its name is learned C Plus Plus author isms of bike and have other objects as well. Let's copy this thing here. Let's have a book do here. I can make an another object, this one, this one will be booked two, or I can name it anything. Its price is 800, let's say. And then it will be learned. C, author will be, let say Alex and learning C plus plus Learning see in detail. So now I have a habit for C plus, plus and for C. So now this will not be a book object here. Instead it will be booked two, dot set price and book do dot setName of book, Book 2 dot set author and book dude or subtitle. So now we have these two objects, book and book. Do they have other values? So by using this implementation of book loss, we have two objects here. So that is the benefit of classes and objects by simply I can make as many objects out of debt laws as I want. So now let's print the value of book author here. Now the book author would be Hamza and book to author would be alex. So I will add an L here, the next line. And I will also then see out booked two dot author. Now they both have different authors. Their book one has authored hands-on and book to as author Alex. So let's see what it prints in the output. As you can see, the book one author is Hamza, it prints it, and the next line it prints Alex. So Alex is the book 2's author. Similarly as Book 2, we can have a lot of other objects from this class. So currently our class has a very few functions and variables, but think of that, there is a very big glass that has a lot of functions and a lot of variables. So there's a lot of reusability, dear. We can just by making objects, we can use those. So dad has benefits of objects. So that's all from this session. 32. Multiple Constructors in a class: Welcome. In this session, we will learn about having multiple constructors in a class. So I welcome you to this session. We have a className book here which has one constructor. So as we know, constructor has the same name as that of glass. So now I can also have other constructor with different arguments. So let's make an another constructor in this class. So dad constructor will be of same name of glass and it will be having noted on type, but it will have different number of arguments than this one, the above constructor. So if we can have multiple constructors, but they will be having different number of arguments and only one of them will be called. So dad constructor will be off our choice. So currently we have a constructor with no arguments because it sets these values to default. Now the other constructor that I can have should have different number of arguments. So what I would get in arguments of this constructor will be the values which I want to set for these variables I have here. So let's say the first value will be string, and it will be name of book. And the second value should be now this, if I get this only one value, this would be fine, but I will get all these four variable values to set in this multiple argument constructor. So let's see. Now I have to add it for author. So string name of author. And then I have another string for title, title of book. And finally I have an integer price, so it will be int price of the book. So what I've done here is I have made a multiple argument constructor here. Now I have two constructor here in this class. So what I will do in the body of this constructor is I will set these variables to what I've got in arguments. So the name of the book now will be this name is this variable which I have in this book class. So name will be equal to name of book. This variable, and similarly, other author title and price will be equal to these arguments which are heavier. So, so author is equals to name of author, this one here. And title is equals to title of book, this one. And finally, price will be equal to price of books. So now what I have done, I have multiple argument constructor and I'm setting the values to these variables which I get from user. Now the person who will make the object of this class, we'll be setting these values. And if we call this constructor, then these values will be default. So let's see how it's done in our main function. As you know, currently we have a book object where we have set price or 400 and we have said the name, author and title here. But for in this case in which I have called made an object like this, the default constructor will be gone, which has no arguments. But when I do it like this and add these values, let say the name of the book will be learned C plus plus. And I have four arguments there. Author will be Hamza. Similarly, title will be learning C plus plus in detail. And price would be, let say anything of our choice as it is an integer. So let it be 300. Now I will remove distinct from here. So what I'm doing here is when I'm making the object of this class. Now I'm seeing that as you can see what it shows, it says it will call this multiple argument constructor there. Now, this constructor with no arguments will never be called because only one constructor can be gone by we are making the object and that can be our choice. So if I do not give these values while making the object, that would be fine. It will simply call this constructor of that glass. But now in this case, I have provided all the values which is referring the second constructor which I have there. So it will ignore the first constructor. It will call the constructor with arguments. So now let's print the author of this book and let's see if that constructor was called or not. So Book dot author. Yes, and I will just bring this value on screen by doing this. So let's run it and see our output. As you can see an output, it prints SAMHSA. If I change this name, lets it through John. Let's see what it does here. It prints John, saw are multiple argument constructor is successfully call here. And it said it sets that value to our book. Now if I want to change the value of this book author, I can also do it by calling my function, which I have their set author. So it will just update that value to Hamza. While making the object, I set the value to join, but later on I decided to change the author named columns are so I use my function which was already there and I will run it again. And as you can see now it shows me the updated value that is arms up. So I can do that by calling those functions. But constructive role is to just set those values initially when we make the object of that class. So we have successfully made to constructor in this class. We can have any number of constructor in this class, but there arguments should be changed. I cannot have duplicate constructor here with same number of arguments. It will show me an error here. When I run this, as you can see, it says error exists. So what is the error? It says this, it is saying on that book constructor it says previous definition is here. As you can see, note previous definition is here. So we cannot have this thing here. So in this session we have learned about multiple argument constructor. And we can have as many constructor in our glass as we want, but only one of them will be called. And that will be our choice, which we choose while making the object of that class. So that's all from decision. 33. Encapsulation and Access Modifiers: Welcome. In this session we will talk about encapsulation and assess modifiers. So I'm in code editor and this is our class book which we have recently made. So we have assessed modifier here, named public. So what public means that everything I did clear below the stack will be available outside this class and in any other class that makes an object of this class. So we have three types of access modifiers and C plus plus. The first one is public, second one is product protected, and the third one is private. So public, protected and private, these three access modifiers are used to specify that what data will be accessible outside this class. So first we come to public access modifier, public means it is assessable everywhere. So what do we mean by accessible everywhere as we have these four variables here. And we have other functions like set price, setName of books, set author and set title. So in main function, I can simply call these functions like set author and this book object. Let's say I can also, by using this dot operator, I can assess all of these like author named price entitled simply by selecting one of those author, I can change its value. So the ad, because these are public, if they are not public, then I will not be assessed. They will not be accessible here. So let's change them to private. So instead of public, I'm changing them to private. So now all of these things are private and they are not accessible outside this class definition. So let's try it. When I said their book dot set author to Hume's, I will run this and you will see, as you can see, it says some error there. So let's read the error. It says author is a private member of book. So we cannot, here we are using C outlook dot author. So it says it's a private member of books. You can not use it and it shows error every year constructor also become private. This set author also become private. And this book dot author also become private. So now they are not assessable in main. So if they are not assessable in May and then what is use of this private access modifier? I will just explain it now. So the use of this private access modifier is dad V make some of the things of glass private debt we don't want to openly put forward to World, for example, I don't want these variables to be openly accessible by outside world. So what I will do, I will make these private and rest of the things that will make them public. So now when I add this specific tag like private republic, so after, after this tag, for example, after this private tag, everything will be private until or unless it receives and another tag. So now it receives and another tag of public. So everything below it will be public. And if I want this function to be private, I will just add a private tag here. And if I want this function to be public, I will add a public tag here. So now everything below these will be public. So for now I will remove these because I want these functions to be public. Most of the time you will be using public access modifier. But here I'm going to explain the importance of these private access modifier. So now these four variables are private, so people can not make direct use of these. As you can see in our main function, I will run it again. Now this constructor is public and the set author function is also public, but Book dot author is not public, it's private. So we cannot open this to everyone. So how we can change the value? We can change the value by making these public functions. So for example, now prices private here in our book, class price is private, which is this one variable here. But by using this set price function, I can set its value because all the private variables are accessible inside of class. So when I specified this private access modifier, then all of the things will be accessible inside of this class, not outside. So if they are accessible inside this class, then these functions can use them, these public functions, so they can change their value. Now someone can not directly change, Let's remove this line. Now someone can not directly change the value of price like this book dot price. You may enter a negative value or wrong value for it or not, they will not be allowed to do something like this. So as you can see, it shows an error. It says, note it is declared private here, integer price. So we cannot directly change its value, but by making a public function in which we have our constraints like this set price here I have my constraint like price should be greater than 0 and I safely change the value of price here. And I can show error messages as well. So this is about private. We can make anything private debt, debt we do not want to expose to other worlds like main function or other things. So we have these three access modifiers, public, protected, and private. I have explained the public and private, and I will explain protected access modifier when we move to topic inheritance that is coming ahead in other sections. So that will make more sense when we moved to inheritance because protected is something like I have variables here, name, author, title, and price. And when we will use the concept of inheritance in other classes, they will be assessable, but an object still they will not be accessible. So this will make more sense when we moved to inheritance. So currently we have discussed about public, public access modifier is used when we want to make our variables and function accessible everywhere on our objects and everywhere and private is used when we don't want them to be publicly available. So there will only be available inside of that class. So these three Assess modifiers are used. So this also explained the concept of encapsulation. What is encapsulation? Encapsulation means hiding some of our data in a capsule to not make that available to outside world. So what I'm doing here by using this private access modifier, I'm putting name, author, title, and price, as you can see in the figure in a capsule. So they are not assessable on object now, they are only accessible inside of this class. So this concept is called and kept encapsulating data, hiding data. So if I put any of these functions in a private access modifier, they will also be part of this capsule and they will also not be accessible to the outside world. So this is a very useful concept here, encapsulation that allow us to hide our data from outside world. And this is a pillar of object oriented programming that is of course important because when you are working on bigger classes and bigger projects, then there is a requirement of hiding data. For example, we have, if you have a crucial data about some person, if you are making IEDs of person, different people, and we do not want to show their IDs to public or the people who are making an object of that class. So we have to hide debt critical data from users that is something like password or some things like that. So here this concept of encapsulation is used. So data all from this session. 34. Inheritance Explanation C++: Welcome. In this session, we will learn about inheritance in object oriented programming, and we will learn it with the help of an example. Suppose we have a class named car and it has few properties like color, number of doors. And if you functions like start and stop. And we have another class named Ford as forward is a car, so it will also have all of these properties and functions. So the relation between Ford and God is, is a relation that Ford is a car, so forth will have all those properties and functions that are inside car. One way of achieving is achieving this is that we rewrite all the properties and functions that are in car class in art for glass as well. And the second way of doing it is inheritance. So here inheritance come in play. That by using inheritance, we can simply use all the properties that are in car and all the functions that are in car simply inferred by just using inheritance. Similarly, we have another class name, Honda. It will also have all the properties and functions that are incurred because they have is a relation that Honda is a car. So we can simply achieve this by using inheritance. So by this class car, when we use inheritance and inherit these two classes, Ford and harder, all the properties and functions in our car class will automatically be added in our fourth glass and Honda class. So that is benefit of inheritance that we need not to rewrite all of these things there in these glasses are simply present in these both glasses. So when we inherit other classes from a parent class, that is the car class we have inherited three Clouds, Ford, Honda, and Toyota. We can also inherit other classes from this class car. So the top loss from here we inherit other classes is gone parent class, and all the inherited classes are called giant classes. They have another name as well. Parent class can also be called as base class and jive classes can also be called as Dr. classes. So all the properties and functions that are in car class will be separately edit to all inherited classes. That is, the fourth glass will be having God glass functionality, and in addition to dead, it will have other functionality that is specific to fold. Similarly, Honda class will have God loves functionality. And in addition to that other functionality specific to Honda. Similarly data's case for Toyota that it will have core functionality, all the things of God glass, and in addition to that, it will have other functionality specific to Toyota. So that has benefit of inheritance that we get all the properties and functions from parent class in Java classes. And then we can have other functionality related to those giant losses as well. Because Ford, Honda, and Toyota are different companies, so they will be having some specific properties to their brand as well. So that will be added to these glasses. So this is a benefit of object oriented programming, that data reusability. Suppose we have a base class that has 20 properties than a 100 functions. Now if you want to add all these properties and function to some other clause, we need not to rewrite them. We can simply inherit that glass from this base class and it will become a derived class and it will have all those properties and functions inside that class. And in addition to that, it can have other properties and functions that are specific to that Dr class. So this is a great benefit of inheritance, that is data reusability. We can reuse data from our base class into our derived class without writing and repeating dead code again and again. So that's all from this session. 35. Inheritance Code: Welcome. In this session we will learn about inheritance. So I'm in code editor, and here we have our class name book. So we have our book class ready. Now, if I go ahead and make an another class, let's say I name it cookbook. So I have made a new class cookbook and I will add some functionality in this cookbook class, but as it is a book, so it will have all these things which my book class has. It will have a name, it will have author, title and price, and all these functions as well. Dead set price, setName of book, set author and set title. So I also need all of these functions in my cookbook class because cookbook is also a book. So what should I do here? Should I copy all of this code inside of this class, or should I read I did, or should, what should I do to get all these functionality that I have already done in Book class, to have in my cookbook class as well. Because they are very similar. Book might have some few other functions that my book class doesn't have, but it wants all these function which I haven't booked class. So is there an easier way to do that? Yes, there is an easier way and dad is called inheritance. I will inherit this class from my book class. So how I can do that after the name of this class, when I'm declaring it, I will add a colon sign. They assess modified, Let's say I add a public access modifier and then the name of the class from which I am going to inherit this. So in this case it will be book. So now what, what has been done by writing these quote here? It will inherit all these things which I have in this book class to my new class, which I have here with the name cookbook. So by writing only this public book here, I'm getting all of this stuff in my book class, in this class. So as it doesn't seem to be edit here because we have no code in this class yet. But this class has all of the code which we have there. So let's make an object of this class cookbook. And you can see Cookbook, let's say I name it cookbook with a small c. And now when I write cookbook and dot operator, Let's see what you chose me. As you can see, it shows me all of these things author named Bryce, title set author, but they are not inside of this class. So how these things come here in the IntelliSense because I have inherited class from a book class. So in this case, book will be a base class, and cookbook book will be a derived class. So we have that relation in these two classes. Now, we have everything inside this cookbook class. And on top of that, I can also have a constructor off my cookbook class. So let's say I add a constructor here. First of all, I will add it public access modifier. So everything is public. I will add cookbook. And now this is a constructor of my class cookbook. So I will just print a message inside of this that, hey, I'm a constructor. I am constructor of cookbook class. So I'm just adding this line here to see whether this constructor is called or not. So when I make the object of this cookbook class, what it will do because it is inherited from this book class. First of all, this book class constructor will be called. So I have edited line in this book class constructor that hey, I am book constructor. So I will add one Morton class. I am book class constructors. So first of all, this constructor will be called and after that, because as this class is inherited, so It's constructor will also be called. So cookbook will also be called. I will add a line endl here to put all things in other line when this runs. So now as this class is inherited, first of all, Book class constructor will be called and then cookbook class constructor will be called here. So let's see by running this, as you can see, it says, Hey, I'm a book class constructor. And then it says, Hey, I'm a constructor of cookbook class. So both of the constructors will be called because this cookbook is inherited from this book class. And I have all these functions here like set author, set title in this cookbook. Now I can add my other functions live. If I add a recipe function, I can add that. Now this will be a recipe function that will be available only in this cookbook class, that will not be available in this book class because this class is inherited from Book class notebook. So I can add new functions here in this class, and it will have booked function and addition to its own functions. So I have a recipe functions that is only in Cookbook and not in my book class. So I will add something here. Recipe function, recipe function. So now let's make a book object here as well to just explain the concept of what we're doing here. Book. Okay, now we have two objects. One is a book and one is cookbook. So let's see, recipe function is available on cookbook and it's available on book or not. So book should not have that function when I write book dot. So as you can see, it shows me know recipe function, but if I change it to cook book, as you can see, recipe function is here. So in addition to all the functions that are in book clause, it also shows me recipe, function and goodwill. So that is the benefit of inheritance that we get all those functions that are in base class. And in addition to the custom functions, the new functions which we made there. So let's call this recipe function. And now I will also add endl here to just skip the line after this. Now what will happen here? First of all, this book constructor will be called as I have a book object after that, cookbook will make the book constructor to call and the cookbook constructor to call. So book destructor will be called two times and then after that recipe will be chord. So let's run it and see your output. As you can see, it says, Hey, I'm a book class constructor. Data is generated from this line book. And the cookbook, as we know that it will first of all call the base constructor and then the constructor of this cookbook. So it's calling the constructor of base here. Hey, I am book class. And then it is calling, Hey, I'm constructed of cookbook class. After that is calling this recipe function as well, which is cookbook recipe. So it calls this function as well. And as it isn't same line, we can just simply move it to next line by writing and L here. I will run it again and it will simply move to next line. As you can see, recipe function moves to the next line. So that's about inheritance. So we can also do multiple inheritance. Life cookbook is inherited from only book class, but I can inherit it from other classes as well. For dad, I just have to add a comma here and I can give a list of classes that I want this class to inherit from. So it can inherit from multiple base classes as well. Now, what are these public access modifier here doing behind this book? So in the very next session, we will be discussing about this public, private and protected access modifiers while declaring inheritance here. So pterosaur from decision. 36. Access Modifiers: Welcome. In this session, we will learn about public, private and protected inheritance, as well as assessed modifiers in a class as we have learned about inheritance. So now it's a good time to learn protected access modifier as well. Previously we discussed about public and private access modifiers, but in this lecture we will also discuss about protected access modifier. So this lecture is of more importance and you have to listen it very carefully because this will help you a lot in understanding these access modifiers and they are of importance. So let's start. What we have here so far is our book class. And we have inherited cookbook class from our book class. So we have a derived class name, cookbook. So we have two clauses here, bookend cookbook. So what we have here in this book class, we have everything stated as public. So I have used a public access modifier. And so everything, these four variables and all of these functions are public. So public, what you can think of public is that public is very lenient and it allows everything to be publicly available. So all these four variables and all functions will be available in this cookbook class, as well as in my main function where I'm making objects. So public means that. And if it is private, if I, I would have used private deer in my class instead of public here as private. Now, what do we mean by private? You can think of private is very strict, so it doesn't allow anything outside this class. So now as it is private, so we have these all things assessable inside this class book, not outside of this class. So they will not be accessible in this cookbook class, and they will also not be accessible on the object. So if they are not assessable on the, on this cookbook class and like object how we can use them. We can use them by public methods. So we need to have one or more public method there. For example, the set price, I will make it public. So by making the set price public, I'm actually changing the value of this prize inside this class. So I can use this public method inside of my class to change the value of this price. So we can change these private variables value by using public functions there, which we have in our class. So I will just remove this public part here as well now and I will revert it to public. So it's changed back to public now everything is public. So public and protect. Public and private is clear now. So what is protected? You can think of protected as somewhere between public and private. It's not dead lenient as public and it's not that strict as private. It is somewhere in the middle. So how somewhere in the middle. So if I change it to protect it. Now what this means, this means that everything that is stated with protected will be available in this class. That is fine. And it will also be available in these derived classes. So that's a good thing. Private doesn't allow them to be available in this drive classes, but protected is somewhere not that strict. It is linear, so it allows them to be available in Dr. classes, but protected doesn't allow them on these objects. So objects cannot have assessed to protected members, but these derived classes then. So that is very clear. Private doesn't allow it on both the places protected allow it in these drive classes. So that is what protected is. So now, as we have those access modifiers in our class, now what are these public, private, and protected while making the class? So let's understand it by a diagram. So as you can see in the figure, if we do a public inheritance as we are doing in this cookbook class, we are saying public book. So it's a public inheritance, which means that in the figure you can see the upper box is a base class and the blue box is a derived class. So in base class, we will be having some public, protected and private things there. And in Dr class, let's see how these are converted. So all the things that are under this public tag in base class remains public. And Dr. Glass, when it's a public inheritance and all the protected members remain protected. So in the drive class, all public and protected members will be still public and protected if we use a public access modifier. While inheritance and private members are never accessible outside of that glass, so they will still not be accessible in Dr class, but we can assess them with public functions. Yes. So now if we change this public inheritance to protected, now it's a little strict. What it will do is it will change all the public things there in our base class to protect it. Now everything that was public and our base class will be protected in our drive class. And everything that is protected in our base class will still be protected in our derived class. So it makes a difference there. Now if we do a private inheritance here, that if I change this public book here to private book, what it will do here is it will simply change public and protected members in base class to private. Now everything in Dr class that comes from a base class will be private. As you can see in the figure, public change to private and protected change to private. So how we can have this private inheritance simply as you can see in code, I will change this public truth, private now it's a private inheritance. And if I wanted protected here, so I will write protected here. Simply, we can do these type of inheritance, but most of the time we will be using public inheritance because that is used mostly. But we need to have a concept that why we are having these as modifiers here. So these access modifiers do there specific changes and Dr class as their name specifies. So that's all from this session. 37. Polymorphism Explanation C++: Welcome. In this session we will learn about polymorphism. Polymorphism is a very important concept in object oriented programming. Polymorphism can be divided into two parts. Poly and morphism only refers to many and morphism refers to forms. So polymorphism completely refers to many forms. So let's learn it with the help of an example. Suppose we have a class name shape. It can have a few properties like sides of that shape, area of their shapes and angles between the sides of debt shape. And this shape can be of different type like triangles, rectangles, gear, and so on. So shape is our base class and all the rest of these classes are Dr. classes. So triangle has three sides and rectangle has four. So all of these have these properties with different values. But when it comes to calculating area of all of these shapes, the formula for calculating area is different for every shape. That is, triangle cannot have same function for calculating area. And they have different formulas. So if we have a base class name shape and it has a function named calculate area, it might have some functionality, but when it comes to triangle, that is giant class, Dr class, it has different formula for calculating area. And so scare has retained will as well. They all have different formula for calculating their area. Now what we have concept of base and derived class, if we have it calculate area function in our base class. So the drive class automatically has that function. That is our concept of inheritance. So if we have a shape class has a base and it has calculate area function, then the rectangle class that is derived class will automatically be having dysfunction there. But when we go ahead and redefine that function, so what we are doing here, we are redefining their function in r dr class because rectangle has a different formula for calculating area. So we cannot use that same function of base class. So this concept is called overriding a function that we are redefining, calculate area function in our derived class with a different functionality. Now, it will ignore that function in base class and it will use the function on Dr. Glass. So base class function will never be called and it will only call derived class function calculate area. So that makes a lot of sense for rectangle, it will call rectangle area function and for triangle, the different function and triangle. So this concept refers to polymorphism. That is many forms. We can have many forms of same function calculate area is a function that is redefined in Dr class. So it has different forms, like for rectangle, it has different calculate area for a triangle, different for heads-up on different, for circle different. It has many forms. So this concept refers to polymorphism. This can also apply in other classes. Suppose we have a class named car, then different cars can have a lot of different functions there like starting mechanism. For example, different cars have different starting mechanism. Some cars are started by the P, some width button, and some different options there. So we can not have a starting mechanism function for every car. Same, we need to have different functions there. And similarly with the acceleration function, if we have the acceleration function, different cars might have different time and different processes and different mechanism of acceleration. And same is the case for breaks. Different cars have different mechanism of braking system. So we have polymorphism concept here in object oriented programming. So now let's understand it in code. 38. Polymorphism Code: Welcome. In this session we will learn about polymorphism. So I'm in code editor and I will go ahead and make a class named shape. So I have a shape gloss here in the body of this class, I will declare two variables. First of all, I will use assess modified, that will be public. Now, I will make two variables. First one will be, it will be integer variable. And second one will be height. So with the help of these variables, I will be able to calculate area of this shape class. So I will go ahead and make a function here named area. So it will be wide area. And it will, what this function will do, it will print the area of that class. So I will just see out for the sake of this lecture, I will just see out that this is area of shape class, which is parent, which is parent or, or base class. We can see because this will be our base class or parent class of r dr classes. So now I will go ahead and make another class here. I will name it rectangle. Now this class will be inherited from our shape class. So what I've done here, I have a shape class here. Now, I have also a rectangle class. Now this class is supposed to be having all of these properties and functions which I have in my Shape class. So whenever I will call area on this rectangle object, it should call this function here. So let's do it here in main function, I will make an object of this rectangle class. I will name it rectangle with a lowercase, lowercase r. And now what I will do here is I will call this area on this object. So I will quickly run it and you will see that what area is called here. So as you can see, it says this is area of shape class, which is patron base. So this area was called because we have inherited this class from shapes. So this area function is already inside the rectangle, but there is a point to note here that rectangle has its own formula for calculating area that is different from other classes. So what is that? We have width into height. So that is how we calculate area. So this function will be no more useful in this case because it will have something of its own functionality. So what we will do, we will overwrite this function in our rectangle class. So how I can do that, I will write void area. Now as I'm defining this function again in this class. So when I will call this rectangle dot area here, now no more dysfunction will be called. This function will not be called. Now, only this function will be called. So whatever functionality I haven't dysfunction that will be called and it will ignore the parent class function. So let's add a line of code in this area. That area of rectangle is. And I will print the area dash will be width into height. So what it will do, it will print the area that is written to hide. But before that we have to set some value for width and height. So I will add a constructor here in this rectangle class that will be, first of all, I have to add the access modifier and then the constructor. So in this constructor, I will be getting those two values for width and height. The first one will be with and then it will be height. So w will contain width and height. And then I, in the body of the constructor, I will set those values like this. Okay, so now we're setting these values of these variables here. One more point to note here is that a class can also have no constructor. We have discussed about no argument constructor and multiple argument constructor. But a class can also have no constructors in it as our shape class do. So, our rectangle class has a constructor rectangle here where we have width and height we are setting now in this area it will calculate with an I. So now simply as we have this rectangle class object here, so we have to call this two argument constructor and we have to give some values here. So let's say I give three for width and height equals 10. So now it should be three into ten will be the area of this rectangle, which will be 30. So let's see what it prints here. So what it says here, area of rectangle is 30. So now it is going into this area function instead of going into the parent class area function. So parent class area function is never called because this area function is overridden in our rectangle class. So that is how polymorphism is done as the Shape class is the parent class and we have a rectangle class from here. But rectangle class has its own formula for area. Now let's go ahead and make an another class here. Let it be triangle. It will be also inherited from our shape class, so I will say public shape. So now I have a triangle class. Triangle has its own formula for calculating area. So how we can do that? First of all, I will add a constructor here of triangles. In this constructor, I will also be getting width and height. And I will send those property for width and height like this I have done here. Gripped is equal to w and height is equals to edge. Now when I am going to make the area of this class, what I will do here is I will make the area function and dad will see out area of triangle is. Now I have to calculate area of triangle. So area of triangle is base into height divided by two. So base in this case would be width and height we have here. So base width into height divided by two. So I will calculate that here. Width into height. And then I will divide it by two. So this is the formula for calculating area of triangle. So rectangle area is calculated by different formula and triangle area is calculated by different formula. So let's call, let's make an object of triangle here. And I will give it some values, let's say five and 10. So again, I will call area function on this triangle object. So, okay, I have called this area on triangle as well. So I will add an L here so that it moves to the next line before printing other values there. So now what we have here, we have two clauses, rectangle and triangle data derived from this base class data shape. So here you can see clear polymorphism debt, this shape class has many forms. They are rectangle and triangle are derived from shape class, but they have their own method for calculating area. So they are overriding that function here. So this is called polymorphism. And by this we apply polymorphism using overriding a function. So now I will run this and we will see the output. As you can see in the output it says area of rectangle is 30, but area of triangle is 25. How it calculated 25, it multiplied five into ten days with 50 and then divided it by two, so we get 25 year. So these both glass has different formula for calculating area. So what we have learned in this class is polymorphism. And how we can achieve polymorphism is by overriding a function. So we override it this function area of our base class and achieved polymorphism. So that's all from this session. 39. Abstraction Explanation: Welcome. In this session, we will learn about abstraction and we will understand it with the help of an example. Suppose we have a class name some, and it has a function add that takes two integer and calculates their sum. So now when we make object of this class and call this function add, the person who is making an object of this class need not to know about what is internal functionality of this function. He only needs to call this function aired there and pass it two arguments like we have done 24 here. So he is unaware of that. What is internal functionality? They are inside of that function, that how we are calculating it, we are calculating it in another variable like C. We can change it to D as well, or we can only add this into return statement instead of having two lines there. So that depends upon us, the curator of that clause. So the person who will make the object of this class needs not to know about that functionality there. For this add function, it is very small functionality, but we can have a class where we have a function that has a lot of line of code. So the person who will make object of this function needs not to know about what is internal functionality. He only needs to know about the name of debt function which he is calling. So that will make very easy. So this process is called abstraction. That what we are doing here is we are hiding that internal details from outside world. So if a third person uses our class and makes its object, he needs not to know and he is unaware of what exactly the functionality is. He's he only wants dad functionality to be there and he is concerned with results, not their internal functionality. And if later on we change some functionality there, he will have, it will have no effect on that person because he is just calling the name of that function and internal things. The way we are calculating it may change because the algorithms may change and future. If we have some algorithm there and later on we have some Foster algorithm, they are weak and Jane dead functionality and its user interface will not change. That is, the function name will not change as long as the function name doesn't change, the third person who is using object has nothing to do with that. So you can easily use data and there are no changes on his side. So this process is called abstraction. 40. Abstraction Code: Welcome. In this session we will learn about abstraction. We have made it class shape here and we have to drive classes named rectangle and triangle. Both of these classes have a function named area that is calculating area for these specific classes. Now, just look into main debt while a person is making an object of these classes and calling this function area on the object, he is unaware of how we are calculating that area. So if you want to calculate area of rectangle, he is calling rectangle.js area. And for triangle, it is calling triangle.py area. So they are unaware of how we are calculating this with this formula. As for both of them, formula is different for triangle formula is this one and for rectangular formalize this. So he's unaware that what exactly the functionality is inside of this function. And we need not to show that the user is only concerned with calculating area. So he's calling this function area and he need not to know about how we are calculating it as well as far as we are calculating correct results. So this is called abstraction, that the person who is making object doesn't know is that what is the functionality? What, how we achieve this as this is a one-line code, but there can be a lot of line of code in this function. So in future, when the functionality inside this function changes, the user will again be calling this rectangle.js area. There will be no change on user side. So the person to whom we are giving this class, he has to call rectangle.js area. He will not know that what functionality is inside that we can change it later on and it will have no effect on debt user because he only knows about this function call. And he does not know about how we are doing that. So we can simply change that later on if we want it to be. So this is called abstraction. There are a lot of benefit of abstraction. Suppose in future we give this class public, adding it to some library and giving it to public. And they can use these functions. So they will not be knowing about that how we are calculating these things. And they can achieve their reserves simply by calling these functions and the internal details will be hidden. So this is called abstraction. 41. Pointers: Pointer is a very important concept in most of the programming languages. So having a better understanding of pointers is very important. So let's understand it by an example. Let's say we make an integer named ID and assign it a value three. So what happens in computer memory in the background? When we make this variable, its value gets stored at some particular slot in memory. And that particular slot in memory has an address there. Because computer memory, there are blogs that are available for storage of variables and every block has the address. So when we want to store that address of that particular place where our variable is stored, we use a pointer. The pointer is used when we want to deal with addresses of memory slots. So let's see how it's done in code editor. 42. Pointers Code: Welcome. In this session we will learn about pointers and we will declare pointers in code editor. So I'll go ahead and make a pointer. I'm going to make an integer pointer here. So I will write int as a datatype and then I will write the name of pointer. So for, just for this lesson, I will name it pointer. You can give any name of your choice. It is very similar as we declare other variables. But we add one thing here and that is as to resign. So when we add this aesthetic design, it refers to a pointer. So now this is not normal declaration of an integer variable. It's a pointer, so it will be used to store address. In the next line, I will make an another integer variable. I will name it as ID, and I will put it equal to ten. So now in this pointer variable, I will store address of this ID. So how I can do that, I will write the name of pointer and then put it equal to Id and add one more thing here that is an operator. So by doing this address off, this ID will be stored in this pointer variable. Now, I will just bring this pointer variable to show you that what is the address of this id. So I will write pointer here. So I will just quickly run this and you can see the output. As you can see in the output, we have address of ID variable. So this is at this memory slot in memory. So what, what if I remove this and operator from here? Now what I'm doing here, I'm seeing this pointer is equals to ID. So that's not correct. So it should give an error here. As you can see, it didn't run properly and it is giving me an error here that assigning to integer pointer from incompatible type integer, take the address with and. So it says you can add AND operator to take the address. It cannot take a value here. So by doing this, we are saying add, evaluate this pointer, but that is not true. So we will add IT AND operator. And now this is fine. When I run this, it will work fine. As you can see, it shows the address here. Now what if I want a value from that pointer? I have a pointer here to a specific address in the memory. Now if I want to get the value at this pointer, what I will do, I will add an asterisk sign behind this pointer. So if you want to get the value, we will just simply add it as static sign behind the pointer and it will give us the value at that particular address in memory. So I will run it again. And as you can see now it prints 10, which is the value at this address in the memory. So that's all from decision. 43. Pointers of different datatypes: Welcome. In this session we will learn about pointers of different datatypes. In the previous session, we made an integer pointer. And integer pointer can only store address of value that has the integer datatype. It cannot store address of other data types like flawed and strings and double. So for all those datatypes, we need to have a similar pointer. For example, if we have a float variable, we need to have a float. Wonderful dad, let's make an float pointer here. I will make it float pointer and any asterix sign, we'll define that it's a pointer. I will name it float pointer. So it will be a float pointer. And after that, I will just make a variable that is float. I will make a float variable now. So float as a data type and the name of that variable, I will name it float variable. So in this I, let's say I store a value 20.3 as it is a float. So we are adding the decimal point and a number after that. So it's a 20 0.3 value. Now of this float variable, I can store address in this pointer. So let's see how it's done. I will write float pointer, and then I will put it equal to float variable and add the n side. So I will write it float variable. So now it's good. And now I will also make an integer pointer here. Let's say I have a pointer integer. I will name it int pointer. And then I will also have an integer variable. I will name it into variable and put it equal to, let's say 30. I have put it equal to some value. So I have an integer pointer and I have a float pointer. Now let's know what I'm doing here. I'm saying that this float pointer should contain the address of this float variable. And I will print the value here, C out float. So I'm just printing the value, what we have in this float pointer and I will run it and it should work smoothly. As you can see, it shows the address here. Now what will happen if I add address of this integer variable in this float pointer? Let's see, it should give you an error here. I have just replay in the float pointer, I'm adding an address of integer variable. Now lecture on this. As you can see, it gives error here and what it says, Let's read the error. It says Assign into float from incompatible type integer pointer. So that's not working here. So we need to have similar data types for similar pointers and variables. So now I will just, I will just remove this line from here. And we will also make a string pointer here just to demonstrate how things work there. So including the header file there on top strings. So I can just make it a string here. So I will just make string pointer here. So it will be similar to as we have been doing previously. It will be, I will name it string pointer. And then I will also make it string variable. So I will name it string variable. And I will put it equal to, let's say, comes up. So now I have a string pointer and a string variable. I can have the address of this variable in this string pointer. Now, I will put string pointer equal to address of the string variable. So I will write string pointer and put it equal to address off string variable. So that's good here, and I will just print here string pointer value. And we can run this and we can see the output. As you can see in the output, we have address of the string. So for every data type pointer, we need to have similar datatype variable. We cannot mix them up. So one more thing here, as you can see, this is the address here, double E9, E9. So every time when I will run this code, this address will be changed. As you can see, it's now w is 0, 4. So wherever it finds a place for that variable when the program runs, it stores there. So it's not a hard rule that every time it will go to the same memory position, so it can go to any other memory location where it finds space. So now I will run it again and you can see the address will change again. Now it's 93 8. So it changes every time. Wherever it finds the location empty, it puts it there. So that's how pointers with different datatype worked. So that's all from this session. 44. Array of Pointers: Welcome. In this session, we will learn about array of pointers as we have areas of different data types like integers, floats, and strings. Similarly, we can also have an array of pointers. So let's see how it's done. I will make an integer pointer array for data and write an integer as a datatype. And then asterix sign that will define the dead. This is a pointer array. Then I have to write the name of array. I will just name it array. And in these two square brackets, I will define the length of this array. Let's say it, it can contain three elements. So we have an array which can store three elements. And now this is a pointer array. So we need to have addresses in this array. Let's make three variables, integer a, and I will add some value here of three. And now I have an integer b. Let's say it has a value four, and we have an integer c, which has a value five. So now I have three integers here. Now I can store addresses of this variable a, b, and c in my area. So I will write the array and index 0. At index 0, I will store the address of variable a. So I would write a AND operator and a. So from this we get the address of a and we store it at the first index of our array. Similarly, at other indexes, I will store the address of b and c. So I will write one here and B. So I will write array index two, and it will be equal to and C. So what we have done so far, we have three variables and I have stored the addresses of those three variables in my array. Now I will just print those addresses by using a for loop so that I do not want to write the C out statement repeatedly. So I will make a for loop here. I will make an integer variable and started from 0, I will say iterate three times, that is less than 3, and I will make it I plus, plus here. So in this for loop, I will just see out my array. And in this index I will give i. So initially it will be 0, then it was changed to one and then two. So our for loop will run three times. I will run this code and you can see the output here. As you can see in the output, we have three addresses displayed, but they are in the same line. So I would just add an end L here so that they are on a separate line every time I run this again. And as you can see now they are on separate line. We have three addresses. Just look at the last digits. The first one is 90, then it's 94, and then it's 98 as deer. And integer is four bytes, so it has a 4-byte difference. First one is 90 and then a four by difference that gets you to 94. And then again, if four by difference, that is 98, as a teacher is a 4-byte characters of one byte, and so on. So we have three addresses correctly printed there. Now, if I add an asterisk sign here, but behind my array, it will give me the values there. So as we can see now it prints the values 3, 4, and 5. So that's how this array of pointer works. Now this is the integer array and we have integer pointers inside of it. Here, the rule that we have to have the same data type also works. For example, if I change this from integer to float, this will not work because this is an integer array. So we need to have integer addresses here. As you can see, it gives an error. And what is the error? It says assigning to an integer pointer from incompatible type float pointer, because this one is float here. So don't work. We have to get it integer here. So now this would work fine. So as it works for the datatypes, we cannot also store integer addresses in a different data type array. So let's change it to float. Now, I have a float array which can store float variable addresses. And what if I store these things here? Let's see. As you can see, it again gives error. And what is the error here? It gives error on these three lines that we are storing the address of an integer here. And that is not assigning to a float pointer from incompatible type integer. So this will also not work. You have to change it to integer here. Now one more thing here that what if we try to store the value here instead of address, as you can see on array index 0, I'm storing it. This will also not work because this is a pointer array. Let's look at the arrow here. As you can see, it says assigning to integer pointer from incompatible type integer. And then it is also giving us the solution. It is saying take the address here. You can see take the address will end on this line here. Did the address with ans. So it is asking Earth, it is telling us that we should add, add operator here. So now this will be fixed. As you can see, it's working fine. So these things are very important to know because when we know these things, we can write a better code without errors. So this is how array of pointer works. That's all from this session. 45. Benefits of Pointers: Welcome. In this session I will explain to you about benefit of pointer with an example. So I'm in code editor and I will go ahead and make an integer variable in my main function. So integer as a data type and I will name that variable number and put it equal to some value, let's say 10. So I have an integer variable number and its value is 10. Now I will try to change its value by using the function. So on top of me and I will make the function change value. I will name it changed value. So dad, this function will change the value of this number. And in the argument it will take integer variable, I will name it value. So it will take some value as an input and change its value. So let's see how it's done. So here is the body of this function. This function will not be returning us anything. It will just take a value. So I have an integer number here in my main, and I also have a function here. So now let's call this function inside of our main function. So I will call this by writing its name and send it this number. So what I'm doing here is I'm calling this function change value and sending it this number. And here in the body of this function, as I will receive it with the name value, I will say value is equals 250. So I've changed the value 250. And now after this function call here in my main, I will just print the value of number to see whether the effects, whether the changes have been done. So I will write c out and I will print number. So let's see by running this. As you can see, the value is 10 here, which was initially in our main function, but this function was also called Jane value. And I set the value to 50, so it didn't take any effect. Why? Because this number has a scope that it is assessable only inside of these two braces of main function. So outside these records, this cannot be changed. If I want to change the value of this number, I have to set it here inside of curly braces of Maine. Outside it cannot be done. So in this function, it cannot be changed to 15 bird. There is a way by using pointers, we can change this number outside its scope, that is of main function. We can change its value by using pointers. So let's see how it's done. Now, instead of taking a value as an argument, I will take a pointer here. So I will write asterisk sign. So now this function is getting a pointer to some particular value. So it's not a value, it's the pointer now. And as this value will be a pointer, so I need to add an asterisk sign behind it so that I can change its value because this value will be some address of memory location. And to change the value at that address, I will add this asterisk sign. So now I will do some changes here in my main function as well. Instead of sending number, now I cannot send number here because a pointer is required here in argument of change value function. So I will add an ester, I will add it and sign here, that will give me the address of this number. So now I'm getting the address of this number and sending it to this Jane value function here. And at that particular place I am changing the value. So now let's run this again and see the output. As you can see now the output is 50. And I never changed the number value inside of this main function. So how did it happen? Because we're using pointers here. I'm sending the address of this number and I'm seeing change the value at that address. So it's simply change the value at that address. So let's call this function before printing the number as well. So I will write c out number, and I will write and L2 skip aligned. So now in this line I'm printing the value of number before calling this function. And after calling this function, I am again printing the value. Let's see the difference. As you can see before it was done and after that it was 15. So by using pointers, I changed the value at some particular place in memory. So data is a great benefit of pointer that you can assess values through their addresses and change them there. So that's all from this session. 46. Dynamically allocate memory using pointerss: Welcome. In this session, we will learn how to dynamically allocate memory using pointers and we will understand it with the help of an example. So I'm in code editor and we even write an example here. So instead of making an array with a static size, we will be asking the user for the size of an array, and then we will be dynamically making that array instead of making it static. So let's see how it's done. First of all, I would ask the user about how many hobbies he have. So he will enter the count of his hobbies and then we will allocate an array of that size. So I would write how many hobbies have. So user will give us some input here, so we have to get it in some variable. I will make an integer variable size. So in this size variable I will get the input of user. So I will write C in. And in this size variable, I get that value. So this will be the size of array, of array because the hobbies which user have, we will make an array of that size instead of making big or small areas at static. So we will be making them dynamically. Okay, so now user will enter a count of Hobbes. Tsunami can make an area for that we will be using a string pointer. I will name it pointer array. So what we're doing here, we're getting hobbies from user. And those hobbies will be some string. So we need to have a pointer of string data type. If we are getting an input which is an integer, we will make an inter-data type and similarly for double and float, so datatype must be similar. So now I will go ahead and make that array. I will write the name of this pointer and put it equals to. Here. I can write a new operator. New operator is used for dynamic allocation of memory. So we use this new operator. And after Dad, I will write the name, the datatype of array, which I'm going to make. So it is a screen area. And in these two square brackets I will write size. What I have done here, I have said pointer array equals to new string array of size. This size is the size with user enters and I'm having a string array. So this will dynamically allocate memory for an array. And this pointer array will act similar like the default array, the array which we have, which we commonly use. So now I will ask the user to enter his hobbies. So I will write C out, enter your hobbies. So now user will start inputting is Hobbes and we do not know that what exactly the number will be. So I will be using a for loop here. And we can make this for-loop verb on the size, because whatever the size of the array will be, we can make this for loop or conduct. So it will be integer I is equal to 0. Starting from index 0, I will be less than the size which user input and I plus plus. So in the body of this for-loop, I will use C in and get the input in pointer array. And here I will write i. So every time index will, first of all, it will be 0 and then one and then two and so on, depending upon the size of the array, as you can see, we can use this pointer array similarly as our common area. So it will add the values at different indexes of this array after dad even just bring those strings so that you can see them on screen. So I will write c out. Your hobbies are, I will also write and L here to skip the line. And then I will also be making, again, I will be making a for loop so that I can print all those values. So it will be integer I equals to 0. I is less than size again, and I plus plus. So what we are doing here in the upper FOR loop, we're just getting the hobbies in our pointers are a. And now in this for loop, I will just bring them by using C out. So I will say C out pointer array, and then in two square brackets I will write i, so that every value is printed and I will write and L here as well. So it, so that it moves to the next line every time. So that's all from our code. We have dynamically allocated memory here using new keyword. I will run this and we will see the output, as you can see it as asking how many hobbies you have. Let's say I enter two. So it says Enter your hobbies. I write, swimming, reading. Okay. We have two hobbies, swimming and reading. So it tells us that your hobbies are swimming and reading. So as you can see it correctly, input those values in this pointer array and then it printed them on screen. So we have dynamically allocate memory, allocated memory for this array of size this. So now I will run this again and we will give an, another input so that we can make sure that this is working fine. Let's say I write three this time. It says Enter your hobbies as you're reading, shopping, and swimming. As you can see, it says your hobbies are reading, shopping, and swimming. So it's working fine. It's, it has showed us that we can dynamically allocate memory of our areas instead of static allegation of memory. So this is how we allocate memory dynamically using pointers. So that's on from this session. 47. Benefits of pointers explanation: Welcome. In this session, we will learn about benefits of pointers. There are a lot of benefits of pointers when it comes to programming languages. So now we will discuss them with the help of examples. So let's start. Suppose we have an array of 15 elements. As we know, array has a fixed size. So if we have an array of 15 elements beforehand, we will be having 15 slots available in memory that will be dedicated to this array. So that space is allocated to this array and cannot be used by any other variable. So if we have only three values in this array, then rest of the slots will be wasted. So as you can see in this example, we have three values, 6, 10, and 38. So they are occupying their memory slot, but rest of the spaces are wasted. So how we can avoid this? We can avoid this by using pointers. So the concept is called dynamic memory allocation. We can do dynamic memory at runtime when our program is running as an arrays, we have to tell the size of array beforehand, but by using dynamic memory allocation using pointers, we do not have to do that. We can tell the size at runtime when our program is running. So if we have three values, we will allocate three slots only. And if we have five values, we will allocate five slots only in our memory, so our memory even not be wasted. So if we ask a user at runtime when a program is running that how many hobbies you have. So if he enters three, then we will allocate three memory slots and add values there. Instead of making a lot of slots in our array that will go wasted. And if he enters 20, we will make 20 slots in our memory depending upon the input from user. So we can do this by dynamic memory allocation, and we will learn how to do it in code in our upcoming sessions. So let's discuss in another benefit of pointer. Suppose we have an integer number defined in our main function. And we want to assess this number or change its value from outside of this main function. So that's not possible. We know that the only scope of this number is inside main function. So the value of this number can only be changed inside of this main function and cannot be changed outside of it. But there is a possibility using pointers. By using pointers, we can change its value outside the scope of main function. So we will learn that in code editor in our next sessions. In other benefit of pointer is dad, it makes the execution time of your program very faster. So we can have a fast execution time of our program by using pointers. Let's understand it by an example. Suppose we have an array of values in our main function. So you can see the memory footprint of this array as every value of this array will go to a specific slot in memory. Here you can see 1, 2, 3, 4, and up to 500 will be given a dedicated block in memory which will have addresses like one is stored on address number 0100, 700. So too will be a difference of four, that is 1074 because every integer is four bytes. We know that previously. So 700 then 74 and 78, and so on. Difference of four bytes, all values will be stored in the memory. So instead, when we want to copy this array or want to move it to some veer to a function or something, instead of popping on the values that are, there are a lot of values 500. So instead of popping those, we can just only send the address of slot. So by sending the address of only first slot, we can assess complete array because we know the difference between addresses as four bytes. And we can go through our complete array. But we are not sending the complete array. Instead of dat, we're only sending is small address value because we can calculate other values from this. Now, let's move into code editor and learn these.