Hello and welcome to another video. In this video, you're going to learn about the C++ class. Classes are abstract data types that are used to encapsulate concepts, and so we make instances of classes and programs to automate the behaviors of different objects. A class is a template for an object, and this is the foundation of object orientation. So in this particular case, we've created a class called Rectangle. Rectangle is a shape, obviously, it has a height in a width, and so in this class we have a couple of interesting things to point out. So the class itself, just like the struct that we saw earlier in the course, is designed by creating a definition before we use it, and in this particular case, we're defining the class with the word class. So class space rectangle is the start of a template of a new class called Rectangle. We have public and private members of this class. By default, the data members of a class are private, and the member functions are public. And so we have two data members of this class. A data member are variables. So this rectangle will hold on to two variables. One of them will be the width, and the other one will be the height. And then these are private by default. We have a public section, section, and the public section will contain methods that will run for this class. And so in the public section here, we have a method that's void, and the method is a function. And if you remember a function prototype, that's what we're looking at here. This is a function prototype says it's void, which means it doesn't return anything. And it's called set values, and it takes two values. It takes two ints and ints. And we have another function defined here. This one's called integer area, but this one actually has an implementation. It's not a prototype. So this function is filled out. They call this an inline function. And so because it's in the class definition, this would normally be inside of what's called a header file. And then we have an implementation file, which I'll go into next. But so if we were to put this in a separate file, we would call it rectangle dot h. And then we would use it in rectangle dot c plus plus in an implementation. And so as the header, or as the template for the class, you might use that word if you'd like, the integer area function is implemented. It's just returning the width times the height. If the implementation of the function is only one line, you can easily just write it out instead of using a prototype. That's a function prototype. It ends with a semi colon. This one is just a regular old method called area, which is going to return the height times the width to get the rectangle area. We end the definition of this class by a semi colon. This could be in a separate file again, called rectangle dot h. Now down below, we have the implementation of set values. So set values was that function that we created using a prototype. So it's void prototype. Now in the implementation of it, we use these two dots as a scope resolution operator to say that void rectangle, the name of the class, colon colon or scope resolution operator set values, which is the method set values as the method that we're implementing. And we're going to implement it with an integer x and an integer y. And then what we're going to do is we're going to set the width of the rectangle to x and the height of the rectangle to y. So we're populating width and height using x and y. And we're using it through a method called set values. And the set values method is implemented outside of the definition of the rectangle. And we're doing that by using the void rectangle as the class object that we're implementing, colon colon set values. Now that is the implementation of the class. If you wanted to, this here would go in a rectangle dot h file. I put it all in one file just so that and it will work in one file that I put it in one file just to make it easier for you. And then this one here would be in a rectangle dot c plus plus file. And this would be the implementation of it. So this is the prototype or the interface. And this is the implementation file. If you were separating this out, but for the purposes of this demonstration, it can all go into one file. It's not a problem. And so in main, we would make an instance of a class. So once we create this variable, just like we did with the struct early in the course, we use it as a data type. So now we have a rectangle available to us. And we're going to create a rack. This is the name of the variable that we're creating. And this is the data type. So rectangle space rec to create an instance. And then we use the dot notation, same notation as we saw with the structure to set the values. And so we run the method set values three comma four to integer values. We're actually running this method here by that line of code. So rec dot set values sends three and four to it. Once we set the values, the other functionality that we created was the area. So in here, we're just going to print out the area. So see out area, and then run the area function, rectangle dot area sets out the area. And what it does is it returns the width and height. And what we're going to do is see out printed to the screen. So if we have this variable rectangle, and if we're going to set to three comma four, when we compile and run it, we should see the area printed to the screen. And we do the area is equal to 12, which means we've created a rectangle with the area 12. This is a simple implementation of a rectangle class. The way that you build object oriented programs is you create classes, and then you make instances of the classes in what would be called the main driver program. So this is the main driver program. And this would actually be separated out into a separate file itself. So you could stick this in three different files. If you did that, then you can reuse rectangle anytime that you wanted, and you can redo multiple implementations of it as well. So the separation out into multiple files would give you more flexibility in reusing it. Otherwise, what ends up happening is further down the road, you end up with a program which all your classes are defined in there, and you can't figure out where it is, or what the program was called. So for reusability and object orientation, separating out the functionality into separate object files allows you to bring them in and include them, just as you were including iostream.8, you would include these class objects in your program to make instances of them and reuse the functionality. That was an introduction to classes. I hope you enjoyed it. And I encourage you to create some classes on your own, and I'll go through some more details about classes in upcoming videos. Thanks for watching.