Difference between revisions of "Advanced-C++/C2/Function-Overloading-And-Overriding/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with ' {| border=1 | '''Time''' | '''Narration''' |- |00:01 | Welcome to the spoken tutorial on '''function Overloading''' in '''C++.''' |- |00:09 | In this tutorial, we will learn,…')
 
Line 1: Line 1:
 
  
 
{| border=1
 
{| border=1
Line 7: Line 6:
 
|-
 
|-
 
|00:01
 
|00:01
| Welcome to the spoken tutorial on '''function Overloading''' in '''C++.'''
+
| Welcome to the spoken tutorial on '''function Overloading and Overriding''' in '''C++.'''
  
 
|-
 
|-
Line 39: Line 38:
 
|-
 
|-
 
|00:30
 
|00:30
|'''Let us start with an introduction to function overloading.'''
+
|Let us start with an introduction to '''function overloading.'''
  
 
|-
 
|-
Line 56: Line 55:
 
|00:53
 
|00:53
 
|Let us look at an example.
 
|Let us look at an example.
 +
  
 
|-
 
|-
 
|00:56
 
|00:56
|In this program we will perform addition operation.
+
|I have already typed the code on the editor.
 +
 
  
 
|-
 
|-
 
|00:59
 
|00:59
|I have already typed the code on the editor.
+
|In this program we will perform addition operations
  
 
|-
 
|-
 
|01:03
 
|01:03
|Note that I have saved the file with the name '''overload.cpp'''
+
|Note that our file name is '''overload.cpp'''
  
 
|-
 
|-
 
|01:08
 
|01:08
|Let me explain the code.
+
|Let me explain the code now.
  
 
|-
 
|-
 
|01:10
 
|01:10
|This is our '''header file iostream.'''
+
|This is our '''header file as iostream.'''
  
 
|-
 
|-
 
|01:13
 
|01:13
|Here we are using the std namespace.
+
|Here we are using the '''std namespace.'''
  
 
|-
 
|-
Line 95: Line 96:
 
|-
 
|-
 
|01:28
 
|01:28
|'''Then we perform addition of three numbers.''' '''And we return the value.'''
+
|Then we perform addition of three numbers. And we '''return''' the '''value.'''
  
 
|-
 
|-
Line 107: Line 108:
 
|-
 
|-
 
|01:38
 
|01:38
|We pass two arguments '''float d''' '''float e'''
+
|We pass two arguments '''float d''' and '''float e'''
  
 
|-
 
|-
Line 127: Line 128:
 
|-
 
|-
 
|01:58  
 
|01:58  
|'''Here we accept integer values from the user.'''
+
|Here we accept integer values from the user.
  
 
|-
 
|-
Line 135: Line 136:
 
|-
 
|-
 
|02:07
 
|02:07
|And store the''' '''result in variable''' sum.'''
+
|And store the result in variable''' sum.'''
  
 
|-
 
|-
Line 155: Line 156:
 
|-
 
|-
 
|02:23
 
|02:23
|And this is our return statement
+
|And this is our '''return''' statement
  
 
|-
 
|-
Line 167: Line 168:
 
|-
 
|-
 
|02:38
 
|02:38
|To execute type: '''g++ overload dot cpp space hyphen o ovr'''
+
|To execute type: '''g++ space overload dot cpp space hyphen o space over'''
  
 
|-
 
|-
Line 175: Line 176:
 
|-
 
|-
 
|02:51
 
|02:51
|Type '''dot slash ovr'''
+
|Type '''dot slash over'''
  
 
|-
 
|-
Line 187: Line 188:
 
|-
 
|-
 
|02:58
 
|02:58
|I will enter as:
+
|I will enter   '''10''', '''25''' and '''48'''
'''10''', '''25''' and '''48'''
+
  
 
|-
 
|-
 
|03:04
 
|03:04
|The output is displayed as:
+
|The output is displayed as: '''Sum of integers is 83'''
'''Sum of integers is 83'''
+
  
 
|-
 
|-
 
|03:09
 
|03:09
|Now we see:  
+
|Now we see:  '''Enter two floating point numbers'''
  '''Enter two floating point numbers'''
+
  
 
|-
 
|-
 
|03:13
 
|03:13
|I will enter as:
+
|I will enter as: '''4.5''' and '''8.9'''
'''4.5''' and '''8.9'''
+
 
|-
 
|-
 
|03:17
 
|03:17
|'''Press Enter'''
+
|Press '''Enter'''
  
 
|-
 
|-
Line 239: Line 236:
 
|-
 
|-
 
|03:47
 
|03:47
|Let us see an example on '''Function Overriding'''
+
|Let us see an example
  
 
|-
 
|-
Line 255: Line 252:
 
|-
 
|-
 
|04:00  
 
|04:00  
|This is our header file.
+
|This is our header file as '''iostream'''
  
 
|-
 
|-
Line 267: Line 264:
 
|-
 
|-
 
|04:09
 
|04:09
|In this we have declared integer variables''' '''as''' protected.'''
+
|In this we have declared integer variablesas  as '''protected.'''
  
 
|-
 
|-
|04:13
+
|04:14
 
|Then we have '''function values''' declared as '''public'''.
 
|Then we have '''function values''' declared as '''public'''.
  
Line 316: Line 313:
 
|-
 
|-
 
|04:57
 
|04:57
|In this we calculate the product of two''' '''numbers and display the product.
+
|In this we calculate the product of two numbers and display the product.
  
 
|-
 
|-
 
|05:03
 
|05:03
|Then we have '''class Divide '''this also''' '''inherits the''' base class arithmetic.'''
+
|Then we have '''class Divide '''this also inherits the''' base class arithmetic.'''
  
 
|-
 
|-
Line 328: Line 325:
 
|-
 
|-
 
|05:15
 
|05:15
|Note that the return type of the function is same and the arguments passed are also the same.
+
|Note that the return type of the function is same and the arguments passed are also same.
  
 
|-
 
|-
Line 356: Line 353:
 
|-
 
|-
 
|05:46
 
|05:46
|'''Here, p''' is set to the address of '''arith.Or arith is set to the address of p?
+
|Here, '''p''' is set to the address of '''arith.
  
 
|-
 
|-
Line 364: Line 361:
 
|-
 
|-
 
|05:56
 
|05:56
|Now we call''' the function operations.'''
+
|Now we call the '''function operations.'''
  
 
|-
 
|-
Line 388: Line 385:
 
|-
 
|-
 
|06:18
 
|06:18
|Now we set '''mult''' to the address of '''arith.'''
+
|Now,  here we set '''mult''' to the address of '''arith.'''
  
 
|-
 
|-
 
|06:22
 
|06:22
|And pass''' arguments '''as''' 6 '''and''' 5.'''
+
|And pass''' arguments '''as''' 6 '''and''' 5''' as argument
  
 
|-
 
|-
Line 408: Line 405:
 
|-
 
|-
 
|06:41
 
|06:41
|Now we''' call function operations.'''
+
|Now we call operations '''functions'''
  
 
|-
 
|-
Line 424: Line 421:
 
|-
 
|-
 
|06:54
 
|06:54
|Type:
+
|Type:  '''g++ space override dot cpp space hyphen o space over2'''
  '''g++ space override dot cpp hyphen o space over2'''
+
  
 
|-
 
|-
 
|07:04
 
|07:04
|'''Press Enter'''
+
|Press '''Enter'''
  
 
|-
 
|-
 
|07:06
 
|07:06
|Type:
+
|Type: '''dot slash over2'''
dot slash over2'''
+
  
 
|-
 
|-
Line 502: Line 497:
 
|-
 
|-
 
|08:13
 
|08:13
|In this tutorial we have seen
+
|In this tutorial learnt
  
 
|-
 
|-
Line 510: Line 505:
 
|-
 
|-
 
|08:16
 
|08:16
|'''eg. int add with three different arguments.''' and
+
|'''eg. int add''' with three different arguments and
  
 
|-
 
|-
 
|08:21
 
|08:21
|'''float add with two different arguments.'''
+
|'''float add''' with two different arguments.
  
 
|-
 
|-
Line 588: Line 583:
 
|-
 
|-
 
|09:27
 
|09:27
|More information on this Mission is available at he link shown below
+
|More information on this Mission is available at the link shown below
  
 
|-
 
|-

Revision as of 11:26, 16 July 2014

Time Narration
00:01 Welcome to the spoken tutorial on function Overloading and Overriding in C++.
00:09 In this tutorial, we will learn,
00:11 Function Overloading.
00:12 Function Overriding.
00:14 We will do this with the help of examples.
00:18 To record this tutorial, I am using
00:21 Ubuntu OS version 11.10
00:26 g++ compiler v. 4.6.1
00:30 Let us start with an introduction to function overloading.
00:34 Function Overloading means two or more functions can have same name.
00:41 The number of arguments and the data-type of the arguments will be different.
00:47 When a function is called it is selected based on the argument list.
00:53 Let us look at an example.


00:56 I have already typed the code on the editor.


00:59 In this program we will perform addition operations
01:03 Note that our file name is overload.cpp
01:08 Let me explain the code now.
01:10 This is our header file as iostream.
01:13 Here we are using the std namespace.
01:17 Then we have add function defined as int.
01:21 In this we have passed three arguments.
01:24 Int a, int b and int c;
01:28 Then we perform addition of three numbers. And we return the value.
01:33 Here we overload the function add.
01:36 It is declared as float.
01:38 We pass two arguments float d and float e
01:44 Then we perform the addition operation on two numbers.
01:48 This is our main function.
01:50 In function main we declare the add function with different arguments.
01:56 Then we declare the variables.
01:58 Here we accept integer values from the user.
02:03 Then we call the function add with three arguments.
02:07 And store the result in variable sum.
02:09 Here we print the result.
02:12 Now here we accept floating point numbers from the user.
02:17 Then we call the add function with two arguments.
02:21 And here we print the sum.
02:23 And this is our return statement
02:26 Now let us execute the program
02:29 Open the terminal by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
02:38 To execute type: g++ space overload dot cpp space hyphen o space over
02:49 Press Enter
02:51 Type dot slash over
02:53 Press Enter
02:55 It is displayed Enter three integers
02:58 I will enter 10, 25 and 48
03:04 The output is displayed as: Sum of integers is 83
03:09 Now we see: Enter two floating point numbers
03:13 I will enter as: 4.5 and 8.9
03:17 Press Enter
03:19 The output is displayed as:

Sum of floating point numbers is 13.4

03:25 Now we will see function overriding.
03:29 Let us switch back to our slides.
03:31 Redefining a base class function in the derived class.
03:36 The derived class function overrides the base class function.
03:40 But the arguments passed are same.
03:44 And the return-type is also same.
03:47 Let us see an example
03:49 Here is an example on function Overriding
03:53 Note that our filename is override.cpp.
03:57 Let us go through the code.
04:00 This is our header file as iostream
04:03 Here we have the std namespace.
04:06 Then we have class arithmetic.
04:09 In this we have declared integer variablesas as protected.
04:14 Then we have function values declared as public.
04:18 In these we have passed two arguments int x and int y.
04:23 Then we stored the value in a and b.


04:26 Here we have virtual function as operations.
04:30 In this we add the two numbers and print the sum.
04:34 Here we close the class.
04:37 Now we have class Subtract as derived class.
04:41 This inherits the base class arithmetic.
04:45 In this we calculate the difference of two numbers and we print the difference.
04:50 Now we have another derived class as Multiply.
04:54 This also inherits base class arithmetic.
04:57 In this we calculate the product of two numbers and display the product.
05:03 Then we have class Divide this also inherits the base class arithmetic.
05:09 In this we calculate the division of two numbers and then we display the division.
05:15 Note that the return type of the function is same and the arguments passed are also same.
05:23 Now this is our main function.
05:26 In this we create an object of class arithmetic as p.
05:31 arith is the pointer to the class arithmetic.
05:35 Then we have subt object of class Subtract.
05:39 mult object of class Multiply.
05:42 And divd object of class Divide.
05:46 Here, p is set to the address of arith.
05:50 Then we pass arguments as 30 and 12 in function values.
05:56 Now we call the function operations.
05:59 This will perform the addition operation.
06:02 Here we set subt to the address of arith.
06:07 And we pass 42 and 5 as arguments.
06:11 Again we call function operations.
06:14 This will perform subtraction of two numbers.
06:18 Now, here we set mult to the address of arith.
06:22 And pass arguments as 6 and 5 as argument
06:26 We call function operations.
06:29 This will perform multiplication of two numbers.
06:33 Atlast we set divd to the address of arith And we pass 6 and 3 as arguments.
06:41 Now we call operations functions
06:44 This will perform division of two numbers.
06:48 And this is our return statement.
06:50 Let us execute the program. Switch back to our terminal.
06:54 Type: g++ space override dot cpp space hyphen o space over2
07:04 Press Enter
07:06 Type: dot slash over2
07:09 Press Enter
07:11 The output is displayed as:
07:13 Addition of two numbers is 42
07:16 Difference of two numbers is 37
07:19 Product of two numbers is 30 and Division of two numbers is 2
07:25 Let us switch back to our slides.
07:27 Let us see the difference of overloading and overriding.
07:31 Overloading can occurs without inheritance.
07:35 Overriding occurs when one class is inherited from another.
07:41 In overloading the arguments and the return-type must differ.
07:46 In overriding the arguments and the return type must be same.
07:51 In overloading the function name is same.
07:55 But it behaves differently depending on the arguments passed to them.
08:01 In overriding the function name is same.
08:05 Derived class function can perform different operations from the base class.
08:11 Let us summarize:
08:13 In this tutorial learnt
08:15 Function overloading.
08:16 eg. int add with three different arguments and
08:21 float add with two different arguments.
08:24 Function Overriding.
08:26 eg. virtual int operations () and int operations ()
08:31 functions with the same argument and same return type and


08:36 Difference between both.
08:38 As an assignment
08:39 Write a program that will calculate the area of rectangle, square and circle
08:46 Using function overloading.


08:48 Watch the video available at the link shown below
08:52 It summarizes the Spoken Tutorial project
08:55 If you do not have good bandwidth, you can download and watch it
08:59 The Spoken Tutorial Project Team
09:02 Conducts workshops using spoken tutorials
09:05 Gives certificates to those who pass an online test
09:09 For more details, please write to,
09:12 contact@spoken-tutorial.org
09:16 Spoken Tutorial Project is a part of the Talk to a Teacher project
09:20 It is supported by the National Mission on Education through ICT, MHRD, Government of India
09:27 More information on this Mission is available at the link shown below
09:32 This is Ashwini Patil from IIT Bombay signing off
09:36 Thank You for joining.

Contributors and Content Editors

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