Difference between revisions of "Advanced-C++/C2/Classes-And-Objects/English-timed"
From Script | Spoken-Tutorial
(Created page with ' {| border = 1 |Time |Narration |- | 00:01 | Welcome to the spoken tutorial on '''Classes '''and''' Objects''' in '''C++.''' |- | 00:07 | In this tutorial we will learn, …') |
|||
(13 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
{| border = 1 | {| border = 1 | ||
− | |Time | + | |'''Time''' |
− | |Narration | + | |'''Narration''' |
− | + | ||
|- | |- | ||
| 00:01 | | 00:01 | ||
− | | Welcome to the spoken tutorial on '''Classes | + | | Welcome to the spoken tutorial on '''Classes and Objects''' in '''C++.''' |
|- | |- | ||
| 00:07 | | 00:07 | ||
− | | In this tutorial we will learn | + | | In this tutorial, we will learn: |
|- | |- | ||
| 00:09 | | 00:09 | ||
− | | '''Classes | + | |'''Classes''' |
|- | |- | ||
| 00:11 | | 00:11 | ||
− | | '''Objects | + | |'''Objects''' '''Encapsulation''' and |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 00:14 | | 00:14 | ||
− | | '''Data abstraction.''' | + | |'''Data abstraction.''' |
|- | |- | ||
Line 38: | Line 30: | ||
|- | |- | ||
| 00:20 | | 00:20 | ||
− | | To record this tutorial, I am using | + | | To record this tutorial, I am using: |
|- | |- | ||
| 00:23 | | 00:23 | ||
− | |'''Ubuntu OS '''version 11.10 | + | |'''Ubuntu OS '''version '''11.10''' |
|- | |- | ||
| 00:28 | | 00:28 | ||
− | |'''g++ compiler '''version 4.6.1 | + | |'''g++ compiler '''version '''4.6.1''' |
|- | |- | ||
| 00:32 | | 00:32 | ||
− | | Let us start with the introduction to | + | | Let us start with the introduction to '''class'''es. |
|- | |- | ||
| 00:36 | | 00:36 | ||
− | |'''Class is created using a keyword class''' | + | |'''Class''' is created using a '''keyword class'''. |
|- | |- | ||
Line 62: | Line 54: | ||
|- | |- | ||
| 00:42 | | 00:42 | ||
− | | Class links the '''code''' and '''data'''. | + | | '''Class''' links the '''code''' and '''data'''. |
|- | |- | ||
| 00:45 | | 00:45 | ||
− | | The '''data''' and '''functions''' of the class are called as members of the class. | + | | The '''data''' and '''functions''' of the '''class''' are called as members of the class. |
|- | |- | ||
| 00:51 | | 00:51 | ||
− | | Let us move on to | + | | Let us move on to '''object'''s. |
|- | |- | ||
Line 90: | Line 82: | ||
|- | |- | ||
| 01:06 | | 01:06 | ||
− | |''' | + | |'''behavior''' is defined through member functions called '''methods'''. |
|- | |- | ||
| 01:10 | | 01:10 | ||
− | | Now let us see the syntax for a class | + | | Now let us see the '''syntax''' for a class. |
|- | |- | ||
| 01:14 | | 01:14 | ||
− | |Here, '''class''' is a keyword used to define a class. | + | |Here, '''class''' is a keyword used to define a '''class'''. |
|- | |- | ||
Line 106: | Line 98: | ||
|- | |- | ||
|01:21 | |01:21 | ||
− | |''' | + | |'''public, private''' and '''protected''' are the '''access specifier'''. |
|- | |- | ||
| 01:26 | | 01:26 | ||
− | |And here we have defined the | + | |And here we have defined the data members and the member functions as '''public, private''' and '''protected'''. |
|- | |- | ||
| 01:34 | | 01:34 | ||
− | |This is how we close the class. | + | |This is how we close the '''class'''. |
|- | |- | ||
| 01:37 | | 01:37 | ||
− | | Now let us see an example | + | | Now let us see an example. |
− | + | ||
|- | |- | ||
| 01:39 | | 01:39 | ||
− | |I have already typed the code on the editor. | + | |I have already typed the code on the '''editor'''. |
|- | |- | ||
Line 131: | Line 122: | ||
|- | |- | ||
| 01:44 | | 01:44 | ||
− | | Note that our filename is | + | | Note that our filename is '''class hyphen obj dot cpp''' |
|- | |- | ||
| 01:50 | | 01:50 | ||
− | | In this example we will calculate the area of a square using class. | + | | In this example, we will calculate the area of a square using '''class'''. |
|- | |- | ||
Line 147: | Line 138: | ||
|- | |- | ||
| 02:02 | | 02:02 | ||
− | | Here we are using the '''std namespace''' | + | | Here we are using the '''std namespace'''. |
|- | |- | ||
Line 155: | Line 146: | ||
|- | |- | ||
| 02:10 | | 02:10 | ||
− | |Here I have not declared any '''access specifier'''. | + | |Here, I have not declared any '''access specifier'''. |
|- | |- | ||
| 02:14 | | 02:14 | ||
− | |So by default it is private. | + | |So, by default it is '''private.''' |
|- | |- | ||
| 02:17 | | 02:17 | ||
− | |Hence variable '''x''' is a '''private''' member of''' class square.''' | + | |Hence, variable '''x''' is a '''private''' member of''' class square.''' |
|- | |- | ||
| 02:22 | | 02:22 | ||
− | | This is the '''public specifier''' | + | | This is the '''public specifier'''. |
|- | |- | ||
|02:25 | |02:25 | ||
− | |Function '''area''' is a '''public''' function. | + | |Function '''area''' is a '''public''' '''function'''. |
|- | |- | ||
Line 179: | Line 170: | ||
|- | |- | ||
|02:31 | |02:31 | ||
− | |Now let us move back to our | + | |Now let us move back to our '''slide'''s to know more about the '''access specifiers'''. |
|- | |- | ||
| 02:36 | | 02:36 | ||
− | | '''Public specifier''' | + | | '''Public specifier'''- |
|- | |- | ||
Line 191: | Line 182: | ||
|- | |- | ||
| 02:44 | | 02:44 | ||
− | | A '''public''' member can be used anywhere in the program. | + | |A '''public''' member can be used anywhere in the program. |
|- | |- | ||
| 02:49 | | 02:49 | ||
− | | '''Private specifier''' | + | | '''Private specifier'''- |
|- | |- | ||
Line 203: | Line 194: | ||
|- | |- | ||
| 02:57 | | 02:57 | ||
− | |'' | + | |'''private''' members can be used only by the members of the '''class'''. |
|- | |- | ||
| 03:03 | | 03:03 | ||
− | | | + | | '''Protected specifier'''- |
|- | |- | ||
| 03:05 | | 03:05 | ||
− | |''' | + | |'''protected''' members cannot be accessed from outside the '''class'''. |
|- | |- | ||
Line 223: | Line 214: | ||
|- | |- | ||
| 03:16 | | 03:16 | ||
− | | Here in this statement we have the''' class''' name | + | | Here, in this statement we have the''' class''' name, |
|- | |- | ||
| 03:21 | | 03:21 | ||
− | | | + | |the''' scope resolution operator''' and the function name. |
|- | |- | ||
Line 235: | Line 226: | ||
|- | |- | ||
| 03:27 | | 03:27 | ||
− | | It specifies that function '''area''' is not a global function. | + | | It specifies that function '''area''' is not a '''global''' function. |
|- | |- | ||
Line 243: | Line 234: | ||
|- | |- | ||
| 03:36 | | 03:36 | ||
− | | Here we have passed an argument as '''int a | + | | Here, we have passed an '''argument''' as '''int a'''. |
|- | |- | ||
| 03:40 | | 03:40 | ||
− | | Now let us switch back to | + | | Now, let us switch back to our '''slide'''s to know more about the '''scope resolution operator.''' |
|- | |- | ||
Line 255: | Line 246: | ||
|- | |- | ||
| 03:49 | | 03:49 | ||
− | |To access the variable or function with the same name we use the scope resolution operator '''::'''. | + | |To access the '''variable''' or '''function''' with the same name, we use the scope resolution operator '''::'''. |
|- | |- | ||
Line 271: | Line 262: | ||
|- | |- | ||
| 04:10 | | 04:10 | ||
− | | Now switch to our program. | + | | Now, switch to our program. |
|- | |- | ||
| 04:12 | | 04:12 | ||
− | | Here the value of a is stored in x | + | | Here the value of '''a''' is stored in '''x'''. |
− | + | ||
|- | |- | ||
| 04:17 | | 04:17 | ||
− | | Then we return the area of the square | + | | Then we return the '''area''' of the square. |
|- | |- | ||
| 04:20 | | 04:20 | ||
− | | Here x is a '''private''' member. | + | | Here '''x''' is a '''private''' member. |
|- | |- | ||
| 04:22 | | 04:22 | ||
− | |To access the private parameter we used the public member '''a.''' | + | |To access the '''private parameter''', we used the '''public''' member '''a.''' |
|- | |- | ||
Line 304: | Line 294: | ||
|- | |- | ||
| 04:37 | | 04:37 | ||
− | | This is how we create an '''object''' | + | | This is how we create an '''object'''. |
|- | |- | ||
| 04:40 | | 04:40 | ||
− | |'''class-name '''followed by the '''object-name''' | + | |'''class-name '''followed by the '''object-name'''. |
|- | |- | ||
| 04:43 | | 04:43 | ||
− | | Here we call the function '''area '''using the''' object sqr '''and a | + | | Here, we call the '''function''' '''area '''using the''' object sqr '''and a '''.(dot) operator'''. |
|- | |- | ||
| 04:50 | | 04:50 | ||
− | |Then we pass an argument as 4. | + | |Then we pass an '''argument''' as 4. |
|- | |- | ||
| 04:53 | | 04:53 | ||
− | | | + | |We set the value of '''x''' as 4. |
|- | |- | ||
| 04:57 | | 04:57 | ||
− | + | |This is our '''return statement'''.Now click on '''Save'''. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 05:00 | | 05:00 | ||
− | | Let us execute the program. | + | | Let us '''execute''' the program. |
|- | |- | ||
| 05:03 | | 05:03 | ||
− | | Open the terminal window by pressing '''Ctrl, Alt and T ''' | + | | Open the terminal window by pressing '''Ctrl, Alt and T''' '''key'''s simultaneously on your keyboard. |
|- | |- | ||
| 05:11 | | 05:11 | ||
− | | To compile type '''g++ space class hyphen obj dot cpp space hyphen o space class''' | + | | To compile, type: '''g++ space class hyphen obj dot cpp space hyphen o space class''' |
|- | |- | ||
| 05:20 | | 05:20 | ||
− | |Press '''Enter''' | + | |Press '''Enter'''. |
|- | |- | ||
| 05:22 | | 05:22 | ||
− | |Type'''./class'''(dot slash class) | + | |Type'''./class'''(dot slash class). |
|- | |- | ||
| 05:24 | | 05:24 | ||
− | |Press '''Enter''' | + | |Press '''Enter'''.The output is displayed as: |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 364: | Line 346: | ||
|- | |- | ||
| 05:30 | | 05:30 | ||
− | | Now let us move back to our program. | + | | Now, let us move back to our program. |
− | + | ||
|- | |- | ||
Line 373: | Line 354: | ||
|- | |- | ||
| 05:37 | | 05:37 | ||
− | | | + | | the '''data''' and '''functions''' combined together in a '''class.''' |
|- | |- | ||
| 05:41 | | 05:41 | ||
− | |''' | + | |'''class''' is a single unit |
|- | |- | ||
| 05:44 | | 05:44 | ||
− | | | + | |in which the '''data''' and the '''function''' using them is grouped. |
|- | |- | ||
Line 389: | Line 370: | ||
|- | |- | ||
| 05:53 | | 05:53 | ||
− | |Then we have seen class with the ''' private '''and''' public '''members | + | |Then we have seen class with the ''' private '''and''' public '''members. |
|- | |- | ||
Line 413: | Line 394: | ||
|- | |- | ||
| 06:17 | | 06:17 | ||
− | |Let us move back to our | + | |Let us move back to our '''slide'''s. Let us summarize. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 06:20 | | 06:20 | ||
− | |In this tutorial we have learnt | + | |In this tutorial, we have learnt: |
|- | |- | ||
| 06:23 | | 06:23 | ||
− | |Encapsulation | + | | Encapsulation Data Abstraction |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 437: | Line 410: | ||
|- | |- | ||
| 06:27 | | 06:27 | ||
− | | int x; | + | |''' int x;''' |
|- | |- | ||
| 06:29 | | 06:29 | ||
− | |'''Public''' functions | + | |'''Public''' functions''' int area(int);''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 06:32 | | 06:32 | ||
− | |''' | + | |'''classes''' '''class square''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 06:35 | | 06:35 | ||
− | |To create object | + | |To create object, |
|- | |- | ||
Line 465: | Line 430: | ||
|- | |- | ||
| 06:39 | | 06:39 | ||
− | |To call a | + | | To call a '''function''' using '''object sqr dot area();''' |
|- | |- | ||
| 06:43 | | 06:43 | ||
− | | As an assignment | + | | As an assignment: write a program to find the perimeter of a given circle. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 06:49 | | 06:49 | ||
− | | Watch the video available at the link shown below | + | | Watch the video available at the '''link''' shown below. |
|- | |- | ||
| 06:52 | | 06:52 | ||
− | |It summarizes the Spoken Tutorial project | + | |It summarizes the '''Spoken Tutorial''' project. |
|- | |- | ||
| 06:55 | | 06:55 | ||
− | |If you do not have good bandwidth, you can download and watch it | + | |If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
| 07:00 | | 07:00 | ||
− | | | + | |The Spoken Tutorial Project team: |
|- | |- | ||
| 07:02 | | 07:02 | ||
− | | Conducts workshops using spoken tutorials | + | | Conducts workshops using spoken tutorials. |
|- | |- | ||
| 07:05 | | 07:05 | ||
− | |Gives certificates to those who pass an online test | + | |Gives certificates to those who pass an online test. |
|- | |- | ||
| 07:09 | | 07:09 | ||
− | |For more details, please write to | + | |For more details, please write to: contact@spoken-tutorial.org |
|- | |- | ||
| 07:16 | | 07:16 | ||
− | | Spoken Tutorial Project is a part of the Talk to a Teacher project | + | | Spoken Tutorial Project is a part of the "Talk to a Teacher" project. |
|- | |- | ||
| 07:20 | | 07:20 | ||
− | |It is supported by the National Mission on Education through ICT, MHRD, Government of India | + | |It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
|- | |- | ||
| 07:26 | | 07:26 | ||
− | |More information on this | + | |More information on this mission is available at the link shown below. |
|- | |- | ||
|07:31 | |07:31 | ||
− | | This is Ashwini Patil from IIT Bombay signing off | + | |This is Ashwini Patil from IIT Bombay, signing off. Thank You for joining. |
− | + | ||
− | Thank You for joining. | + | |
|} | |} |
Latest revision as of 12:43, 23 March 2017
Time | Narration |
00:01 | Welcome to the spoken tutorial on Classes and Objects in C++. |
00:07 | In this tutorial, we will learn: |
00:09 | Classes |
00:11 | Objects Encapsulation and |
00:14 | Data abstraction. |
00:16 | We will do this with the help of an example. |
00:20 | To record this tutorial, I am using: |
00:23 | Ubuntu OS version 11.10 |
00:28 | g++ compiler version 4.6.1 |
00:32 | Let us start with the introduction to classes. |
00:36 | Class is created using a keyword class. |
00:39 | It holds data and functions. |
00:42 | Class links the code and data. |
00:45 | The data and functions of the class are called as members of the class. |
00:51 | Let us move on to objects. |
00:53 | Objects are variables. |
00:55 | They are the copy of a class. |
00:58 | Each of them has properties and behavior. |
01:01 | Properties are defined through data elements and |
01:06 | behavior is defined through member functions called methods. |
01:10 | Now let us see the syntax for a class. |
01:14 | Here, class is a keyword used to define a class. |
01:18 | Class-name is the name of the class. |
01:21 | public, private and protected are the access specifier. |
01:26 | And here we have defined the data members and the member functions as public, private and protected. |
01:34 | This is how we close the class. |
01:37 | Now let us see an example. |
01:39 | I have already typed the code on the editor. |
01:42 | I will open it. |
01:44 | Note that our filename is class hyphen obj dot cpp |
01:50 | In this example, we will calculate the area of a square using class. |
01:56 | Let me explain the code now. |
01:58 | This is our header file as iostream. |
02:02 | Here we are using the std namespace. |
02:06 | This is declaration for a class named square. |
02:10 | Here, I have not declared any access specifier. |
02:14 | So, by default it is private. |
02:17 | Hence, variable x is a private member of class square. |
02:22 | This is the public specifier. |
02:25 | Function area is a public function. |
02:28 | And this is how we close the class. |
02:31 | Now let us move back to our slides to know more about the access specifiers. |
02:36 | Public specifier- |
02:39 | The public specifier allows the data to be accessed outside the class. |
02:44 | A public member can be used anywhere in the program. |
02:49 | Private specifier- |
02:51 | The members declared as private cannot be used or accessed outside the class. |
02:57 | private members can be used only by the members of the class. |
03:03 | Protected specifier- |
03:05 | protected members cannot be accessed from outside the class. |
03:10 | They can be accessed by a derived class. |
03:13 | Let us move back to our program. |
03:16 | Here, in this statement we have the class name, |
03:21 | the scope resolution operator and the function name. |
03:25 | We must use this operator. |
03:27 | It specifies that function area is not a global function. |
03:33 | It is a member function of class square. |
03:36 | Here, we have passed an argument as int a. |
03:40 | Now, let us switch back to our slides to know more about the scope resolution operator. |
03:46 | It is used to access the hidden data. |
03:49 | To access the variable or function with the same name, we use the scope resolution operator ::. |
03:56 | Suppose the local variable and the global variable have same name. |
04:01 | The local variable gets the priority. |
04:05 | We can access the global variable using ::(scope resolution operator.) |
04:10 | Now, switch to our program. |
04:12 | Here the value of a is stored in x. |
04:17 | Then we return the area of the square. |
04:20 | Here x is a private member. |
04:22 | To access the private parameter, we used the public member a. |
04:27 | private members are always hidden. |
04:30 | This is our main function. |
04:33 | Here, sqr is the object of class square. |
04:37 | This is how we create an object. |
04:40 | class-name followed by the object-name. |
04:43 | Here, we call the function area using the object sqr and a .(dot) operator. |
04:50 | Then we pass an argument as 4. |
04:53 | We set the value of x as 4. |
04:57 | This is our return statement.Now click on Save. |
05:00 | Let us execute the program. |
05:03 | Open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard. |
05:11 | To compile, type: g++ space class hyphen obj dot cpp space hyphen o space class |
05:20 | Press Enter. |
05:22 | Type./class(dot slash class). |
05:24 | Press Enter.The output is displayed as: |
05:28 | Area of the square is 16 |
05:30 | Now, let us move back to our program. |
05:35 | So far now we have seen, |
05:37 | the data and functions combined together in a class. |
05:41 | class is a single unit |
05:44 | in which the data and the function using them is grouped. |
05:49 | This mechanism is called as Encapsulation. |
05:53 | Then we have seen class with the private and public members. |
05:59 | The private data is hidden. |
06:02 | It cannot be accessed outside the class. |
06:05 | This mechanism is called as Data abstraction. |
06:09 | The interface is seen but the implementation is hidden. |
06:14 | This brings us to the end of this tutorial. |
06:17 | Let us move back to our slides. Let us summarize. |
06:20 | In this tutorial, we have learnt: |
06:23 | Encapsulation Data Abstraction |
06:25 | Private members |
06:27 | int x; |
06:29 | Public functions int area(int); |
06:32 | classes class square |
06:35 | To create object, |
06:37 | square sqr; |
06:39 | To call a function using object sqr dot area(); |
06:43 | As an assignment: write a program to find the perimeter of a given circle. |
06:49 | Watch the video available at the link shown below. |
06:52 | It summarizes the Spoken Tutorial project. |
06:55 | If you do not have good bandwidth, you can download and watch it. |
07:00 | The Spoken Tutorial Project team: |
07:02 | Conducts workshops using spoken tutorials. |
07:05 | Gives certificates to those who pass an online test. |
07:09 | For more details, please write to: contact@spoken-tutorial.org |
07:16 | Spoken Tutorial Project is a part of the "Talk to a Teacher" project. |
07:20 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
07:26 | More information on this mission is available at the link shown below. |
07:31 | This is Ashwini Patil from IIT Bombay, signing off. Thank You for joining. |