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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(12 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 '''and''' Objects''' in '''C++.'''
+
|  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:12
+
| '''Encapsulation.''' and
+
  
 
|-
 
|-
 
| 00:14
 
| 00:14
| '''Data abstraction.'''
+
|'''Data abstraction.'''
  
 
|-
 
|-
Line 37: 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 classes.
+
| 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 61: 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 objects.
+
|  Let us move on to '''object'''s.
  
 
|-
 
|-
Line 89: Line 82:
 
|-
 
|-
 
| 01:06
 
| 01:06
|'''Behavior''' is defined through member functions called '''methods'''.
+
|'''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 105: Line 98:
 
|-
 
|-
 
|01:21
 
|01:21
|'''Public, private and protected''' are the access specifier.
+
|'''public, private''' and '''protected''' are the '''access specifier'''.
  
 
|-
 
|-
 
| 01:26
 
| 01:26
|And here we have defined the Data members and the member functions as public, private and protected.
+
|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 129: Line 122:
 
|-
 
|-
 
| 01:44
 
| 01:44
| Note that our filename is name '''class hyphen obj dot cpp'''
+
| 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 145: Line 138:
 
|-
 
|-
 
|  02:02  
 
|  02:02  
|  Here we are using the '''std namespace'''
+
|  Here we are using the '''std namespace'''.
  
 
|-
 
|-
Line 153: 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 177: Line 170:
 
|-
 
|-
 
|02:31
 
|02:31
|Now let us move back to our slides to know more about the access specifiers.
+
|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 189: 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 201: Line 194:
 
|-
 
|-
 
| 02:57
 
| 02:57
|''Private''' members can be used only by the members of the '''class'''.
+
|'''private''' members can be used only by the members of the '''class'''.
  
 
|-
 
|-
 
| 03:03
 
| 03:03
| '''Protected specifier'''
+
| '''Protected specifier'''-
  
 
|-
 
|-
 
| 03:05
 
| 03:05
|'''Protected''' members cannot be accessed from outside the '''class'''.
+
|'''protected''' members cannot be accessed from outside the '''class'''.
  
 
|-
 
|-
Line 221: 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.
+
|the''' scope resolution operator''' and the function name.
  
 
|-
 
|-
Line 233: 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 241: 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 the slides to know more about the '''scope resolution operator.'''
+
| Now, let us switch back to our '''slide'''s to know more about the '''scope resolution operator.'''
  
 
|-
 
|-
Line 253: 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 269: 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 301: 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 (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'''.Now click on '''Save'''.
 
+
|-
+
| 04:59
+
| 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 '''keys simultaneously on your keyboard.
+
| 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:  
 
+
|-
+
|05:25
+
| The output is displayed as:  
+
  
 
|-
 
|-
Line 361: Line 346:
 
|-
 
|-
 
| 05:30
 
| 05:30
| Now let us move back to our program.
+
| Now, let us move back to our program.
 
+
  
 
|-
 
|-
Line 370: Line 354:
 
|-
 
|-
 
| 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 386: 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 410: Line 394:
 
|-
 
|-
 
| 06:17
 
| 06:17
|Let us move back to our slides.
+
|Let us move back to our '''slide'''s. Let us summarize.
 
+
|-
+
| 06:19
+
| 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
 
+
|-
+
| 06:24
+
|Data Abstraction
+
  
 
|-
 
|-
Line 434: Line 410:
 
|-
 
|-
 
| 06:27
 
| 06:27
| int x;
+
|''' int x;'''
  
 
|-
 
|-
 
| 06:29
 
| 06:29
|'''Public''' functions
+
|'''Public''' functions''' int area(int);'''
 
+
|-
+
| 06:30
+
| int area(int);
+
  
 
|-
 
|-
 
| 06:32
 
| 06:32
|'''Classes'''
+
|'''classes''' '''class square'''
 
+
|-
+
| 06:33
+
|class square
+
  
 
|-
 
|-
 
| 06:35
 
| 06:35
|To create object  
+
|To create object,
  
 
|-
 
|-
Line 462: Line 430:
 
|-
 
|-
 
| 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: write a program to find the perimeter of a given circle.
 
+
|-
+
| 06:44
+
|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
+
|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.  
+
  
 
|}
 
|}

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.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14