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