In this lecture.
Firstly, we will start with fully featured cplusplus 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 as you want
from a class.
So however, designing a program using only 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 put 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 Cplusplus 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 a 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 a void method add year here.
And here.
Year and increment year.
By one.
Here.
And let's define the year variable here or define here.
Integer here.
Here.
So.
As you can see, the ad year method declaration looks like another function that takes no parameters
and returns no value.
Within the method, you increment the member year year by one.
So let's create another example here, which we created our struct and methods and we're going to write
some code in main function.
So for example, my time or.
My date here.
Firstly, my date and time.
My date here.
AMD or for example, then.
Indeed that year.
Equals, for example, 2022.
And then that add year.
Here, we will call this function.
As you can see, this takes no parameters.
So if you put anything here, integer, for example, we will get an error and let's end that.
Let's print the firstly, print our MDR here.
Here.
The and new line we will pass.
Yea.
And then after calling this function we will use printf.
Yea again.
Yea.
And the year m-dot.
Yea.
So let's run our program.
As you can see, we got this output here.
So you declare the.
My date and time aimed instance here.
So and then set the year of set the year variable here to 2022.
Next you call the add 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 add year, which takes no parameters
and returns nothing.
So this is a void class and then print the value of clock m'dear.
So you complete the program by incrementing and printing once more.