In this lecture.
Firstly, we will start with fully featured C++ classes using it and we will get and write some practical
examples about it.
So the pod classes can contain only data members and sometimes that's all you want from a class.
So however, designing a programme using all the pods can create a lot of complexity so you can fight
such complexity with encapsulation.
A design pattern that binds data with the functions that manipulate it.
So placing related functions and data together helps to modify the code in at least two ways.
The first, you can pass related code in one place, which helps you to reason about your program.
You can understand how a code segment works because it describes in one place both program state and
how your code modifies the state.
The second, you can hide some of the classes, code and data from the rest of your program using a
practice called Information Hiding.
So in C++ you achieve encapsulation by adding methods and access controls to class definitions.
So we have a methods in classes here.
So methods are member functions.
They create an explicit connection among a class.
It's a data members and some code.
So defining a method is as simple as adding function to just in class.
So methods have to all of the class members.
So consider let's for example, create another method here.
Or first let's create struct date and my date and time.
Here.
Then add the void.
Add.
Yea.
And here.
Yea.
And the increment.
Yea.
By one.
And the list defined the year variable here or define here.
Interior.
Yeah.
So.
As you consider the add year methods, declaration looks like any other function that takes no parameters
and returns no value.
Within the method you increment the member year year by one.
So let's get another example here, which we created our struct and methods and we're going to write
some code in male function.
So for example, my time or.
My date here.
Firstly, my date and time.
My date here.
And they.
Or for example, then.
Indeed that year.
Equals.
For example, 2022.
And then ended that ad the year.
Here.
We will call this function.
As you can see, this takes no parameters.
So if you put anything here, integer E, for example, we will get an error and let's m d that let's
print the first layer.
Print our MD here.
Yea.
The new line will pass year round here and the year.
And then after calling this function, we will use print year again, year, year, the year and date
year.
So let's run our program.
As you can see, we got this output here.
So you declare the.
My date and time M.D. instance M.D. here.
So and then set the year of set a year variable here to 2022.
Next, you call the ad your method on the clock here.
Actually, firstly, you print it.
As you can see, this is the output.
And then you call the method here at year, which takes no parameters and returns nothing.
So this is a void class and then print the value of clock MD that year.
So you complete the program by incrementing and printing once more.