1 00:00:01,600 --> 00:00:02,650 In this lecture. 2 00:00:03,450 --> 00:00:12,420 Firstly, we will start with fully featured cplusplus classes using it and we will get and write some 3 00:00:12,420 --> 00:00:19,800 practical examples about it so the pod classes can contain only data members and sometimes as you want 4 00:00:19,800 --> 00:00:20,730 from a class. 5 00:00:20,730 --> 00:00:26,850 So however, designing a program using only pods can create a lot of complexity. 6 00:00:26,850 --> 00:00:33,450 So you can fight such complexity with encapsulation, a design pattern that binds data with the functions 7 00:00:33,450 --> 00:00:34,680 that manipulate it. 8 00:00:34,770 --> 00:00:42,090 So placing related functions and data together helps to modify the code in at least two ways. 9 00:00:42,120 --> 00:00:49,860 The first, you can put related code in one place which helps you to reason about your program. 10 00:00:49,860 --> 00:00:56,490 You can understand how a code segment works because it describes in one place both program state and 11 00:00:56,490 --> 00:00:59,010 how your code modifies the state. 12 00:00:59,100 --> 00:01:06,280 The second you can hide some of the classes, code and data from the rest of your program using a practice 13 00:01:06,280 --> 00:01:08,770 called Information Hiding. 14 00:01:08,770 --> 00:01:17,650 So in Cplusplus you achieve encapsulation by adding methods and access controls to class definitions. 15 00:01:17,650 --> 00:01:20,050 So we have a methods in classes here. 16 00:01:20,050 --> 00:01:22,120 So methods are member functions. 17 00:01:22,120 --> 00:01:25,750 They create an explicit connection among a class. 18 00:01:25,930 --> 00:01:27,820 It's a data members and some code. 19 00:01:27,850 --> 00:01:37,060 So defining a method is as simple as adding function to just a class. 20 00:01:37,060 --> 00:01:41,500 So methods have to all of the class members. 21 00:01:41,500 --> 00:01:51,970 So consider let's for example, create another method here or first let's create struct date and my 22 00:01:52,090 --> 00:01:55,240 date and time. 23 00:01:55,990 --> 00:02:01,430 Here, then add a void method add year here. 24 00:02:02,080 --> 00:02:03,880 And here. 25 00:02:03,910 --> 00:02:07,060 Year and increment year. 26 00:02:08,030 --> 00:02:09,170 By one. 27 00:02:10,740 --> 00:02:11,100 Here. 28 00:02:11,100 --> 00:02:15,630 And let's define the year variable here or define here. 29 00:02:16,550 --> 00:02:17,650 Integer here. 30 00:02:18,230 --> 00:02:18,790 Here. 31 00:02:19,280 --> 00:02:20,150 So. 32 00:02:21,090 --> 00:02:27,990 As you can see, the ad year method declaration looks like another function that takes no parameters 33 00:02:27,990 --> 00:02:29,460 and returns no value. 34 00:02:29,760 --> 00:02:35,640 Within the method, you increment the member year year by one. 35 00:02:36,730 --> 00:02:44,260 So let's create another example here, which we created our struct and methods and we're going to write 36 00:02:44,260 --> 00:02:47,590 some code in main function. 37 00:02:47,680 --> 00:02:53,890 So for example, my time or. 38 00:02:55,870 --> 00:02:58,300 My date here. 39 00:02:59,730 --> 00:03:02,570 Firstly, my date and time. 40 00:03:02,580 --> 00:03:05,010 My date here. 41 00:03:06,220 --> 00:03:09,850 AMD or for example, then. 42 00:03:11,440 --> 00:03:13,570 Indeed that year. 43 00:03:14,560 --> 00:03:17,560 Equals, for example, 2022. 44 00:03:19,310 --> 00:03:22,640 And then that add year. 45 00:03:24,390 --> 00:03:27,510 Here, we will call this function. 46 00:03:27,510 --> 00:03:29,670 As you can see, this takes no parameters. 47 00:03:29,670 --> 00:03:39,900 So if you put anything here, integer, for example, we will get an error and let's end that. 48 00:03:39,900 --> 00:03:45,780 Let's print the firstly, print our MDR here. 49 00:03:46,970 --> 00:03:47,590 Here. 50 00:03:48,020 --> 00:03:48,570 Here. 51 00:03:50,320 --> 00:03:53,650 The and new line we will pass. 52 00:03:54,490 --> 00:03:55,060 Yea. 53 00:03:55,280 --> 00:03:56,020 Yea. 54 00:03:56,890 --> 00:03:57,610 Yea. 55 00:03:57,640 --> 00:04:03,040 And then after calling this function we will use printf. 56 00:04:03,080 --> 00:04:04,240 Yea again. 57 00:04:04,480 --> 00:04:04,990 Yea. 58 00:04:05,020 --> 00:04:05,580 Yea. 59 00:04:05,980 --> 00:04:09,010 And the year m-dot. 60 00:04:09,040 --> 00:04:09,520 Yea. 61 00:04:11,260 --> 00:04:12,880 So let's run our program. 62 00:04:15,660 --> 00:04:18,570 As you can see, we got this output here. 63 00:04:18,720 --> 00:04:22,020 So you declare the. 64 00:04:23,520 --> 00:04:28,860 My date and time aimed instance here. 65 00:04:28,860 --> 00:04:36,840 So and then set the year of set the year variable here to 2022. 66 00:04:37,020 --> 00:04:43,530 Next you call the add your method on the clock here. 67 00:04:43,590 --> 00:04:45,270 Actually, firstly, you print it. 68 00:04:45,270 --> 00:04:51,810 As you can see this is the output and then you call the method here add year, which takes no parameters 69 00:04:51,810 --> 00:04:52,770 and returns nothing. 70 00:04:52,770 --> 00:04:59,250 So this is a void class and then print the value of clock m'dear. 71 00:04:59,250 --> 00:05:06,330 So you complete the program by incrementing and printing once more.