Difference between revisions of "Advanced-C++/C2/Classes-And-Objects/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 94: Line 94:
 
|-
 
|-
 
| 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 102: Line 102:
 
|-
 
|-
 
|01:21
 
|01:21
|'''Public, private and protected''' are the access specifier.
+
|'''public, private''' and '''protected''' are the '''access specifier'''.
  
 
|-
 
|-
Line 110: Line 110:
 
|-
 
|-
 
| 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 130: Line 130:
 
|-
 
|-
 
| 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 142: Line 142:
 
|-
 
|-
 
|  02:02  
 
|  02:02  
|  Here we are using the '''std namespace'''
+
|  Here we are using the '''std namespace'''.
  
 
|-
 
|-
Line 150: Line 150:
 
|-
 
|-
 
| 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 178: Line 178:
 
|-
 
|-
 
| 02:36
 
| 02:36
| '''Public specifier'''
+
| '''Public specifier'''-
  
 
|-
 
|-
Line 190: Line 190:
 
|-
 
|-
 
| 02:49  
 
| 02:49  
| '''Private specifier'''
+
| '''Private specifier'''-
  
 
|-
 
|-
Line 202: Line 202:
 
|-
 
|-
 
| 03:03
 
| 03:03
|  '''Protected specifier'''
+
|  '''Protected specifier'''-
  
 
|-
 
|-
Line 218: Line 218:
 
|-
 
|-
 
| 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.
+
|the''' scope resolution operator''' and the function name.
  
 
|-
 
|-
Line 238: Line 238:
 
|-
 
|-
 
| 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 the slides to know more about the '''scope resolution operator.'''
+
| Now, let us switch back to the '''slide'''s to know more about the '''scope resolution operator.'''
  
 
|-
 
|-
Line 250: Line 250:
 
|-
 
|-
 
| 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 270: Line 270:
 
|-
 
|-
 
| 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 298: Line 298:
 
|-
 
|-
 
| 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 '''.(dot) operator'''.
+
|  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.  
+
|We set the value of 'x' as 4.  
  
 
|-
 
|-
 
| 04:57
 
| 04:57
| | This is our return statement
+
| | This is our '''return statement'''.
  
 
|-
 
|-
 
| 04:59
 
| 04:59
| Now Click on '''Save'''
+
| Now click on '''Save'''.
  
 
|-
 
|-
 
|  05:00
 
|  05:00
| Let us execute the program.
+
| Let us '''execute''' the program.
  
 
|-
 
|-
Line 334: Line 334:
 
|-
 
|-
 
| 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'''.
  
 
|-
 
|-
Line 358: Line 358:
 
|-
 
|-
 
| 05:30
 
| 05:30
| Now let us move back to our program.
+
| Now, let us move back to our program.
  
 
|-
 
|-
Line 366: Line 366:
 
|-
 
|-
 
| 05:37
 
| 05:37
| The data and '''functions''' combined together in a '''class.'''
+
| the '''data''' and '''functions''' combined together in a '''class.'''
  
 
|-
 
|-
 
| 05:41
 
| 05:41
|'''Class''' is a single unit.
+
|'''class''' is a single unit
  
 
|-
 
|-
 
| 05:44
 
| 05:44
|In which the data and the function using them is grouped.
+
|in which the '''data''' and the '''function''' using them is grouped.
  
 
|-
 
|-
Line 382: Line 382:
 
|-
 
|-
 
| 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 410: Line 410:
 
|-
 
|-
 
| 06:19
 
| 06:19
| Let us summarize
+
| 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
  
 
|-
 
|-
 
| 06:24
 
| 06:24
|Data Abstraction
+
|* Data Abstraction
  
 
|-
 
|-
 
| 06:25
 
| 06:25
|'''Private''' members
+
|* '''Private''' members
  
 
|-
 
|-
Line 434: Line 434:
 
|-
 
|-
 
| 06:29
 
| 06:29
|'''Public''' functions
+
|* '''Public''' functions
  
 
|-
 
|-
Line 442: Line 442:
 
|-
 
|-
 
| 06:32
 
| 06:32
|'''Classes'''
+
|* '''classes'''
  
 
|-
 
|-
Line 450: Line 450:
 
|-
 
|-
 
| 06:35
 
| 06:35
|To create object  
+
|* To create object,
  
 
|-
 
|-
Line 458: Line 458:
 
|-
 
|-
 
| 06:39
 
| 06:39
|To call a function using '''object sqr dot area();'''  
+
|* To call a '''function''' using '''object sqr dot area();'''  
  
 
|-
 
|-
 
| 06:43
 
| 06:43
|  As an assignment  
+
|  As an assignment:
  
 
|-
 
|-
Line 470: Line 470:
 
|-
 
|-
 
| 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  
+
|  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,|contact@spoken-tutorial.org
+
|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 Mission is available at the link shown below
+
|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.  
  
 
|}
 
|}

Revision as of 08:15, 27 June 2015

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
00:12 * 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 the 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.
04:59 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.
05:25 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.
06:19 Let us summarize.
06:20 In this tutorial, we have learnt:
06:23 * Encapsulation
06:24 * Data Abstraction
06:25 * Private members
06:27 int x;
06:29 * Public functions
06:30 int area(int);
06:32 * classes
06:33 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:
06:44 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.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14