Difference between revisions of "Advanced-C++/C2/Polymorphism/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
   
+
  {| border=1
{| border=1
+
 
|| '''Time'''
 
|| '''Time'''
 
|| '''Narration'''
 
|| '''Narration'''
Line 6: Line 5:
 
|-
 
|-
 
|  00:02
 
|  00:02
|  Welcome to the spoken tutorial on '''Polymorphism'''in '''C++'''.
+
|  Welcome to the '''spoken tutorial''' on '''Polymorphism'''in '''C++'''.
  
 
|-
 
|-
 
|  00:07
 
|  00:07
|  In this tutorial we will learn,
+
|  In this tutorial, we will learn:
  
 
|-
 
|-
 
|  00:10
 
|  00:10
| '''Polymorphism.'''
+
|'''Polymorphism''' '''Virtual Function.'''
 
+
|-
+
|  00:11
+
| '''Virtual Function.'''
+
  
 
|-
 
|-
Line 26: Line 21:
 
|-
 
|-
 
|  00:16
 
|  00:16
| To record this tutorial, I am using '''Ubuntu OS '''version 11.10 '''g++ compiler '''v. 4.6.1'''
+
|To record this tutorial, I am using:
 +
'''Ubuntu OS '''version '''11.10'''
 +
'''g++ compiler '''version '''4.6.1'''
  
 
|-
 
|-
 
|  00:27
 
|  00:27
|  Let us start with the introduction to '''polymorphism.'''
+
|  Let us start with an introduction to '''polymorphism.'''
  
 
|-
 
|-
Line 38: Line 35:
 
|-
 
|-
 
|00:36   
 
|00:36   
| It is the mechanism to use a '''function with same name''' in different ways.
+
| It is the mechanism to use a '''function''' with same name in different ways.
  
 
|-
 
|-
 
|  00:42
 
|  00:42
|  Let us see virtual functions.
+
|  Let us see '''virtual functions'''.
  
 
|-
 
|-
 
|  00:45
 
|  00:45
| '''Virtual''' function is the member function of a class.  
+
| '''Virtual''' function is the '''member function''' of a '''class'''.  
  
 
|-
 
|-
 
|  00:49
 
|  00:49
| It can be overriden in its '''derived class.'''
+
| It can be overridden in its '''derived class.'''
  
 
|-
 
|-
Line 62: Line 59:
 
|-
 
|-
 
|  01:01
 
|  01:01
|  Now let us see an example on '''virtual functions.'''
+
|  Now, let us see an example on '''virtual functions.'''
  
 
|-
 
|-
 
|  01:06
 
|  01:06
| I have already written the code.
+
| I have already written the '''code'''.
  
 
|-
 
|-
Line 74: Line 71:
 
|-
 
|-
 
|  01:10
 
|  01:10
| Note that our filename is '''virtual.cpp'''
+
| Note that our file name is '''virtual.cpp'''.
  
 
|-
 
|-
 
|  01:15
 
|  01:15
| In this program:
+
| In this program,we will calculate the area of a rectangle, parallelogram and triangle.
 
+
|-
+
|  01:16
+
| We will calculate the area of a rectangle, parallelogram and triangle.
+
  
 
|-
 
|-
 
|  01:22
 
|  01:22
|  This is our header file as '''iostream.'''
+
|  This is our '''header file''' as '''iostream.'''
  
 
|-
 
|-
 
|  01:25
 
|  01:25
| Here we are using '''std namespace.'''
+
| Here we are using the '''std namespace.'''
  
 
|-
 
|-
 
|  01:29
 
|  01:29
| Then we have a '''class parallelogram'''  
+
| Then, we have a '''class Parallelogram'''.
  
 
|-
 
|-
Line 102: Line 95:
 
|-
 
|-
 
|  01:35
 
|  01:35
| '''In this '''we have declared''' integer variables as width,height''' and '''ar.'''
+
| In this, we have declared''' integer variables''' as '''width, height''' and '''ar.'''
  
 
|-
 
|-
 
|  01:42
 
|  01:42
| These are declared protected.
+
| These are declared '''protected.'''
  
 
|-
 
|-
 
|  01:45
 
|  01:45
'''Then we have function set_values''' declared as '''public.'''
+
|  Then we have function '''set_values()''', declared as '''public.'''
  
 
|-
 
|-
 
|  01:50
 
|  01:50
| Here we have passed two '''arguments''' as '''a ''' and''' b.'''
+
| Here, we have passed two '''arguments''' as '''a ''' and''' b.'''
  
 
|-
 
|-
| 01:55
+
|01:55
| Then we access the protected members using the public members.
+
| Then we access the '''protected members''' using the '''public members'''.
  
 
|-
 
|-
|   02:00
+
|02:00
|   '''This is our virtual function area.'''
+
|This is our '''virtual function area()'''.
  
 
|-
 
|-
Line 129: Line 122:
  
 
|-
 
|-
|   02:07
+
|02:07
|   Then we have class '''Rectangle''' as a '''derived class.'''
+
|Then we have '''class''' '''Rectangle''' as a '''derived class.'''
  
 
|-
 
|-
 
|  02:12
 
|  02:12
| It inherits the properties of base class '''parallelogram'''.
+
| It inherits the properties of '''base class''' '''Parallelogram'''.
  
 
|-
 
|-
 
|  02:17
 
|  02:17
|  Here we override the function '''area'''.
+
|  Here we '''override''' the function '''area()'''.
  
 
|-
 
|-
Line 146: Line 139:
 
|-
 
|-
 
|  02:23
 
|  02:23
| And print the value.
+
| And '''print''' the '''value'''.
  
 
|-
 
|-
 
|  02:25
 
|  02:25
|  Here we have another derived class as '''triangle'''.
+
|  Here we have another derived '''class''' as '''triangle'''.
  
 
|-
 
|-
 
|  02:29
 
|  02:29
| This also inherits the properties of the base class '''parallelogram'''.
+
| This also inherits the properties of the '''base class''' '''Parallelogram'''.
  
 
|-
 
|-
 
|  02:35
 
|  02:35
| Here again we override the function '''area'''.
+
| Here again we '''override''' the function '''area()'''.
 
   
 
   
 
|-
 
|-
 
|  02:39
 
|  02:39
|  Then we calculate the area of the triangle.
+
|  Then we calculate the area of the triangle
  
 
|-
 
|-
 
|  02:41
 
|  02:41
| And print the value.
+
| and '''print''' the '''value'''.
  
 
|-
 
|-
 
|  02:43
 
|  02:43
| This is our '''main function.'''
+
| This is our '''main()''' function.
  
 
|-
 
|-
 
|  02:46
 
|  02:46
|  Here we create an '''object'''of '''class parallelogram as p.'''
+
|  Here we create an '''object'''of '''class Parallelogram''' as '''p.'''
  
 
|-
 
|-
Line 190: Line 183:
 
|-
 
|-
 
|  03:03
 
|  03:03
| '''Pointer''' of base class can point to the object of the derived class.
+
| '''Pointer''' of '''base class''' can point to the '''object''' of the '''derived class'''.
  
 
|-
 
|-
Line 197: Line 190:
  
 
|-
 
|-
|   03:14  
+
|03:14  
| Here, '''Parallel is assigned to the address of p.'''
+
|Here, '''parallel''' is assigned to the address of '''p.'''
  
 
|-
 
|-
Line 206: Line 199:
 
|-
 
|-
 
|  03:23
 
|  03:23
| Then we call''' function area.'''
+
| Then we call the function '''area().'''
  
 
|-
 
|-
 
| 03:26
 
| 03:26
|  Here, '''Parallel''' is assigned to the address of '''rect'''
+
|  Here, '''parallel''' is assigned to the address of '''rect'''.
  
 
|-
 
|-
 
|  03:30
 
|  03:30
| '''rect''' is the object of class '''Rectangle.'''
+
| '''rect''' is the '''object''' of '''class''' '''Rectangle.'''
  
 
|-
 
|-
Line 222: Line 215:
 
|-
 
|-
 
|  03:37
 
|  03:37
| And we call the''' function area.'''
+
| And we call the function '''area().'''
  
 
|-
 
|-
 
|  03:40
 
|  03:40
|  And at last we assign '''Parallel''' to the address of '''Triangle '''
+
|  And, at last we assign '''parallel''' to the address of '''Triangle '''
  
 
|-
 
|-
Line 238: Line 231:
 
|-
 
|-
 
|  03:51
 
|  03:51
| Here we pass '''arguments '''as''' 6 '''and''' 5.'''
+
| Here, we pass '''arguments '''as''' 6 '''and''' 5'''
  
 
|-
 
|-
 
|  03:54
 
|  03:54
| And call''' function area.'''
+
| and call''' function area().'''
  
 
|-
 
|-
 
| 03:56
 
| 03:56
| And This is our '''return''' statement
+
| And this is our '''return''' statement.
  
 
|-
 
|-
 
| 03:59
 
| 03:59
| Now  let us execute the program
+
| Now, let us '''execute''' the program.
  
 
|-
 
|-
|   04:02
+
|04:02
| 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 '''keys simultaneously on your keyboard.
  
 
|-
 
|-
|   04:09
+
|04:09
| To compile type:  
+
|To compile, type: '''g++ space virtual.cpp space -o space vir''' press '''Enter'''.
 
+
|-
+
|  04:10
+
| '''g++ space virtual.cpp space -o space vir''' '''Press Enter'''
+
  
 
|-
 
|-
 
|  04:20
 
|  04:20
| Type: '''./vir ''' '''Press Enter'''
+
| Type: '''./vir ''' press '''Enter'''.
  
 
|-
 
|-
 
| 04:24
 
| 04:24
| You can see that, The output is displayed as:
+
| You can see that the '''output''' is displayed as:
  
 
|-
 
|-
Line 282: Line 271:
 
|-
 
|-
 
|  04:31
 
|  04:31
| and '''Area of triangle is 15'''
+
| and '''Area of triangle is 15'''.
  
 
|-
 
|-
 
| 04:34
 
| 04:34
|   Come back to  our slides.
+
| Come back to  our '''slides'''.
  
 
|-
 
|-
 
|  04:36
 
|  04:36
| Let us summarize.
+
| Let us summarize.In this tutorial, we learnt:
 
+
|-
+
|  04:37
+
In this tutorial, we learnt
+
  
 
|-
 
|-
 
|  04:39
 
|  04:39
| Polymorphism.
+
|'''Polymorphism'''
  
 
|-
 
|-
 
|  04:41
 
|  04:41
| Virtual function example '''Virtualint''' area
+
|'''Virtual function''', example '''Virtual int area()'''.
  
 
|-
 
|-
 
|  04:45
 
|  04:45
|  As an assignment  
+
|  As an assignment: Calculate the perimeter of rectangle, square and triangle.
 
+
|-
+
|  04:46
+
| Calculate the perimeter of rectangle, square and triangle.
+
  
 
|-
 
|-
 
|  04:50
 
|  04:50
| Create perimeter as a Virtual function.
+
|Create perimeter as a '''Virtual function.'''
  
 
|-
 
|-
 
|  04:54
 
|  04:54
| Watch the video available at the link shown below
+
| Watch the video available at the link shown below.
  
 
|-
 
|-
 
|  04:57
 
|  04:57
| It summarizes the Spoken Tutorial project  
+
| It summarizes the Spoken-Tutorial project.
  
 
|-
 
|-
 
|  05:00
 
|  05:00
| 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.
  
 
|-
 
|-
 
| 05:04
 
| 05:04
|  The Spoken Tutorial Project Team
+
|  The Spoken Tutorial Project team:
  
 
|-
 
|-
 
|  05:06
 
|  05:06
| Conducts workshops using spoken tutorials  
+
| Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
|  05:09
 
|  05:09
| Gives certificates to those who pass an Online test  
+
| Gives certificates to those who pass an Online test.
  
 
|-
 
|-
 
|  05:14
 
|  05:14
| For more details, please write to, contact@spoken-tutorial.org
+
| For more details, please write to: contact@spoken-tutorial.org
  
 
|-
 
|-
 
|  05:21
 
|  05:21
| 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.
  
 
|-
 
|-
 
| 05:25  
 
| 05:25  
| 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.
  
 
|-
 
|-
 
|  05:32
 
|  05:32
| More information on this Mission is available at link shown below : [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org\NMEICT-Intro]
+
| More information on this mission is available at link shown below : http://spoken-tutorial.org/NMEICT-Intro
  
 
|-
 
|-
 
|05:37
 
|05:37
|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 14:59, 23 March 2017

Time Narration
00:02 Welcome to the spoken tutorial on Polymorphismin C++.
00:07 In this tutorial, we will learn:
00:10 Polymorphism Virtual Function.
00:13 We will do this through an example.
00:16 To record this tutorial, I am using:

Ubuntu OS version 11.10 g++ compiler version 4.6.1

00:27 Let us start with an introduction to polymorphism.
00:31 Polymorphism is the ability to take different forms.
00:36 It is the mechanism to use a function with same name in different ways.
00:42 Let us see virtual functions.
00:45 Virtual function is the member function of a class.
00:49 It can be overridden in its derived class.
00:53 It is declared with virtual keyword.
00:57 Virtual function call is resolved at run-time.
01:01 Now, let us see an example on virtual functions.
01:06 I have already written the code.
01:08 Let us go through it.
01:10 Note that our file name is virtual.cpp.
01:15 In this program,we will calculate the area of a rectangle, parallelogram and triangle.
01:22 This is our header file as iostream.
01:25 Here we are using the std namespace.
01:29 Then, we have a class Parallelogram.
01:33 This is the base class.
01:35 In this, we have declared integer variables as width, height and ar.
01:42 These are declared protected.
01:45 Then we have function set_values(), declared as public.
01:50 Here, we have passed two arguments as a and b.
01:55 Then we access the protected members using the public members.
02:00 This is our virtual function area().
02:04 Here we calculate the area of parallelogram.
02:07 Then we have class Rectangle as a derived class.
02:12 It inherits the properties of base class Parallelogram.
02:17 Here we override the function area().
02:21 Then we calculate the area of the rectangle.
02:23 And print the value.
02:25 Here we have another derived class as triangle.
02:29 This also inherits the properties of the base class Parallelogram.
02:35 Here again we override the function area().
02:39 Then we calculate the area of the triangle
02:41 and print the value.
02:43 This is our main() function.
02:46 Here we create an objectof class Parallelogram as p.
02:52 We can see here pointer parallel.
02:56 This is the pointer of class parallelogram.
03:00 This is called as Base pointer.
03:03 Pointer of base class can point to the object of the derived class.
03:08 Here we create objects of class Rectangle and Triangle.
03:14 Here, parallel is assigned to the address of p.
03:18 Then we pass arguments as 3 and 2.
03:23 Then we call the function area().
03:26 Here, parallel is assigned to the address of rect.
03:30 rect is the object of class Rectangle.
03:33 Again we pass arguments as 4 and 5.
03:37 And we call the function area().
03:40 And, at last we assign parallel to the address of Triangle
03:45 trgl.
03:47 This is the object of class Triangle.
03:51 Here, we pass arguments as 6 and 5
03:54 and call function area().
03:56 And this is our return statement.
03:59 Now, let us execute the program.
04:02 Open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
04:09 To compile, type: g++ space virtual.cpp space -o space vir press Enter.
04:20 Type: ./vir press Enter.
04:24 You can see that the output is displayed as:
04:27 Area of parallelogram is 6
04:29 Area of rectangle is 20
04:31 and Area of triangle is 15.
04:34 Come back to our slides.
04:36 Let us summarize.In this tutorial, we learnt:
04:39 Polymorphism
04:41 Virtual function, example Virtual int area().
04:45 As an assignment: Calculate the perimeter of rectangle, square and triangle.
04:50 Create perimeter as a Virtual function.
04:54 Watch the video available at the link shown below.
04:57 It summarizes the Spoken-Tutorial project.
05:00 If you do not have good bandwidth, you can download and watch it.
05:04 The Spoken Tutorial Project team:
05:06 Conducts workshops using spoken tutorials.
05:09 Gives certificates to those who pass an Online test.
05:14 For more details, please write to: contact@spoken-tutorial.org
05:21 Spoken-Tutorial Project is a part of the "Talk to a Teacher" project.
05:25 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
05:32 More information on this mission is available at link shown below : http://spoken-tutorial.org/NMEICT-Intro
05:37 This is Ashwini Patil from IIT Bombay, signing off.Thank You for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Ranjana, Sandhya.np14, Sneha