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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
 
 
{| border=1
 
{| border=1
 
| '''Time'''
 
| '''Time'''
Line 7: Line 5:
 
|-
 
|-
 
| 00:01
 
| 00:01
| Welcome to the spoken tutorial on '''friend''' '''function '''in '''C++.'''
+
| Welcome to the '''spoken tutorial''' on '''Friend Function '''in '''C++.'''
  
 
|-
 
|-
 
| 00:06
 
| 00:06
| In this tutorial we will learn,
+
| In this tutorial, we will learn
  
 
|-
 
|-
Line 23: Line 21:
 
|-
 
|-
 
| 00:13
 
| 00:13
|  To record this tutorial, I am using
+
|  To record this tutorial, I am using:
  
 
|-
 
|-
 
| 00:15
 
| 00:15
| '''Ubuntu OS '''v. 11.10
+
|'''Ubuntu OS '''version '''11.10'''
  
 
|-
 
|-
 
| 00:19
 
| 00:19
| '''g++ compiler '''v. 4.6.1
+
|'''g++ compiler '''version '''4.6.1'''
  
 
|-
 
|-
 
| 00:24
 
| 00:24
| Let us start with the introduction to '''friend function.'''
+
| Let us start with an introduction to '''friend function.'''
  
 
|-
 
|-
 
| 00:27
 
| 00:27
| We know, the private data is not accessible outside the class.
+
| We know, the '''private''' data is not accessible outside the '''class'''.
  
 
|-
 
|-
 
| 00:33
 
| 00:33
| To access the private data we use '''friend function'''.
+
| To access the '''private data''', we use '''friend function'''.
  
 
|-
 
|-
 
| 00:37
 
| 00:37
| A '''friend function''' is not a member function of the class.
+
| A '''friend function''' is not a '''member function''' of the '''class'''.
  
 
|-
 
|-
 
| 00:42
 
| 00:42
| '''Friend function''' can be invoked without using an object.
+
| '''Friend function''' can be invoked without using an '''object'''.
  
 
|-
 
|-
 
| 00:46
 
| 00:46
| The argument passed in the '''friend function''' is used as its object.
+
| The '''argument''' passed in the '''friend function''' is used as its '''object'''.
  
 
|-
 
|-
Line 75: Line 73:
 
|-
 
|-
 
| 01:05
 
| 01:05
| Then we pass arguments as '''class_name''' and '''object''' of the class.
+
| Then we pass '''arguments''' as '''class_name''' and '''object''' of the '''class'''.
  
 
|-
 
|-
 
| 01:11
 
| 01:11
|  Let us look at an example
+
|  Let us look at an example.
  
 
|-
 
|-
 
| 01:13
 
| 01:13
| I have already typed the code on the editor.
+
| I have already typed the '''code''' on the '''editor'''.
  
 
|-
 
|-
Line 91: Line 89:
 
|-
 
|-
 
| 01:18
 
| 01:18
| In this program we will perform addition operation.
+
| In this program, we will perform addition operation.
  
 
|-
 
|-
 
| 01:22
 
| 01:22
|  Note that our filename is '''frnd.cpp'''
+
|  Note that our file-name is '''frnd.cpp'''.
  
 
|-
 
|-
 
| 01:27
 
| 01:27
| Let me explain the code now.
+
| Let me explain the '''code''' now.
  
 
|-
 
|-
Line 115: Line 113:
 
|-
 
|-
 
| 01:41
 
| 01:41
| In this we have declared variables '''a''' and '''b '''as '''private.'''
+
| In this, we have declared variables 'a' and 'b' as '''private.'''
  
 
|-
 
|-
 
| 01:46
 
| 01:46
|Here we have declared a '''function input''' as '''public'''  
+
|Here we have declared a function '''input()''' as '''public'''.
  
 
|-
 
|-
 
| 01:52
 
| 01:52
|  In this we take input from the user.
+
|  In this, we take input from the user.
  
 
|-
 
|-
 
| 01:55
 
| 01:55
| This is our '''friend function '''as''' compute'''.
+
| This is our '''friend function '''as''' compute()'''.
  
 
|-
 
|-
 
| 01:58
 
| 01:58
| Here, we have passed arguments as '''class_name''' '''frnd '''and''' object '''of the''' class f1'''.
+
| Here, we have passed '''arguments''' as '''class_name''' '''frnd '''and''' object '''of the''' class 'f1' '''.
  
 
|-
 
|-
Line 139: Line 137:
 
|-
 
|-
 
| 02:08
 
| 02:08
| Now we can access the private members of class '''frnd''' using the '''friend function.'''
+
| Now, we can access the '''private members''' of '''class''' '''frnd''' using the '''friend function.'''
  
 
|-
 
|-
 
| 02:16
 
| 02:16
|  Here we have used the '''compute function'''.
+
|  Here, we have used the '''compute()''' function.
  
 
|-
 
|-
 
| 02:19
 
| 02:19
| In this we will perform addition operation.
+
| In this, we will perform addition operation.
  
 
|-
 
|-
 
| 02:23
 
| 02:23
| We add the variables '''a and b'''
+
| We add the variables 'a' and 'b'.
  
 
|-
 
|-
 
| 02:26
 
| 02:26
| And then return the value.
+
| And then return the '''value'''.
  
 
|-
 
|-
 
| 02:28
 
| 02:28
| Here we access the private variables in non-member function using the '''object f1.'''
+
| Here, we access the '''private variables''' in non-member function using the '''object f1.'''
  
 
|-
 
|-
 
| 02:35
 
| 02:35
|  This is our '''main''' function.
+
|  This is our '''main()''' function.
  
 
|-
 
|-
 
| 02:38
 
| 02:38
|  In this we create an '''object''' of class '''frnd''' as '''f.'''
+
|  In this, we create an '''object''' of class '''frnd''' as '''f.'''
  
 
|-
 
|-
 
| 02:44
 
| 02:44
| Then we call the '''function input '''using the''' object f.'''
+
| Then we call the function '''input() '''using the''' object f.'''
  
 
|-
 
|-
 
| 02:48
 
| 02:48
|And here we call function '''compute '''and pass''' f '''as argument.  
+
|And here, we call function '''compute() '''and pass''' f '''as argument.  
  
 
|-
 
|-
 
| 02:54
 
| 02:54
| You can see that we have passed the argument as '''f''' in '''function compute.'''
+
| You can see that we have passed the '''argument''' as '''f''' in function '''compute()'''.
  
 
|-
 
|-
Line 195: Line 193:
 
|-
 
|-
 
| 03:09
 
| 03:09
|  Now let us execute the program.
+
|  Now, let us '''execute''' the program.
  
 
|-
 
|-
 
| 03:11
 
| 03:11
|  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.
  
 
|-
 
|-
Line 207: Line 205:
 
|-
 
|-
 
| 03:21
 
| 03:21
| '''g++ space frnd dot cpp space hyphen o space frnd'''.Press '''Enter'''.
+
| '''g++ space frnd dot cpp space hyphen o space frnd'''. Press '''Enter'''.
  
 
|-
 
|-
 
| 03:32
 
| 03:32
| Type:
+
| Type: '''dot slash frnd'''
'''dot slash frnd'''
+
  
 
|-
 
|-
 
| 03:36
 
| 03:36
| Press '''Enter'''
+
| press '''Enter'''.
  
 
|-
 
|-
 
| 03:38
 
| 03:38
|  Here it is displayed as:  '''Enter the value of a and b'''
+
|  Here, it is displayed as:  '''Enter the value of a and b'''.
  
 
|-
 
|-
 
| 03:41
 
| 03:41
| I will enter as: '''8''' and '''4'''
+
| I will enter as: '''8''' and '''4'''.
  
 
|-
 
|-
Line 232: Line 229:
 
|-
 
|-
 
| 03:48
 
| 03:48
| '''The result is: 12'''
+
| '''The result is: 12'''.
  
 
|-
 
|-
Line 240: Line 237:
 
|-
 
|-
 
| 03:54
 
| 03:54
| Let us move back to our slides.
+
| Let us move back to our '''slides'''.
  
 
|-
 
|-
 
| 03:56
 
| 03:56
|  Let us summarize:
+
|  Let us summarize.In this tutorial, we learned  '''Friend function.''' e.g. '''friend int compute class-name frnd''' and '''object 'f1' '''.
 
+
|-
+
| 03:57
+
| In this tutorial we learned  '''Friend function.''' '''eg. friend int compute class name frnd''' and '''object f1'''.
+
  
 
|-
 
|-
 
| 04:08
 
| 04:08
|  As an assignment,  Write a program to find out the square and cube of a number.
+
|  As an assignment,  write a program to find out the square and cube of a number.
  
 
|-
 
|-
 
| 04:14
 
| 04:14
|  Watch the video available at the link shown  
+
|  Watch the video available at the link shown below.
  
 
|-
 
|-
 
| 04:17
 
| 04:17
| It summarizes the Spoken Tutorial project  
+
| It summarizes the Spoken-Tutorial project.
  
 
|-
 
|-
 
| 04:20
 
| 04:20
| 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.
  
 
|-
 
|-
 
| 04:24
 
| 04:24
|  The Spoken Tutorial Project Team conducts workshops using spoken tutorials  
+
|  The Spoken-Tutorial Project team: conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 04:30
 
| 04:30
| Gives certificates to those who pass an online test  
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
 
| 04:33
 
| 04:33
| For more details, please write to, '''contact@spoken-tutorial.org'''
+
| For more details, please write to: '''contact@spoken-tutorial.org'''
  
 
|-
 
|-
 
| 04:40
 
| 04:40
|  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.
  
 
|-
 
|-
 
| 04:43
 
| 04:43
| 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.
  
 
|-
 
|-
 
| 04:51
 
| 04:51
| More information on this Mission is available at the shown below: [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org\NMEICT-Intro]
+
| More information on this mission is available at the link shown below: http://spoken-tutorial.org/NMEICT-Intro  
  
 
|-
 
|-
 
| 04:56
 
| 04:56
| 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 15:06, 23 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on Friend Function in C++.
00:06 In this tutorial, we will learn
00:08 Friend function.
00:10 We will do this with the help of an example.
00:13 To record this tutorial, I am using:
00:15 Ubuntu OS version 11.10
00:19 g++ compiler version 4.6.1
00:24 Let us start with an introduction to friend function.
00:27 We know, the private data is not accessible outside the class.
00:33 To access the private data, we use friend function.
00:37 A friend function is not a member function of the class.
00:42 Friend function can be invoked without using an object.
00:46 The argument passed in the friend function is used as its object.
00:51 Let us see the declaration of a friend function.
00:55 friend keyword is used to declare a friend function.
00:59 Then we give the return_type.
01:02 function_name is the name of the function.
01:05 Then we pass arguments as class_name and object of the class.
01:11 Let us look at an example.
01:13 I have already typed the code on the editor.
01:16 I will open it.
01:18 In this program, we will perform addition operation.
01:22 Note that our file-name is frnd.cpp.
01:27 Let me explain the code now.
01:30 This is our header file as iostream.
01:34 Here we are using std namespace.
01:37 Then we have declared a class frnd.
01:41 In this, we have declared variables 'a' and 'b' as private.
01:46 Here we have declared a function input() as public.
01:52 In this, we take input from the user.
01:55 This is our friend function as compute().
01:58 Here, we have passed arguments as class_name frnd and object of the class 'f1' .
02:06 Then we close the class.
02:08 Now, we can access the private members of class frnd using the friend function.
02:16 Here, we have used the compute() function.
02:19 In this, we will perform addition operation.
02:23 We add the variables 'a' and 'b'.
02:26 And then return the value.
02:28 Here, we access the private variables in non-member function using the object f1.
02:35 This is our main() function.
02:38 In this, we create an object of class frnd as f.
02:44 Then we call the function input() using the object f.
02:48 And here, we call function compute() and pass f as argument.
02:54 You can see that we have passed the argument as f in function compute().
02:58 This is done by using the method pass by value.
03:03 f is passed to the value of f1.
03:06 And this is our return statement.
03:09 Now, let us execute the program.
03:11 Open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
03:20 Now type:
03:21 g++ space frnd dot cpp space hyphen o space frnd. Press Enter.
03:32 Type: dot slash frnd
03:36 press Enter.
03:38 Here, it is displayed as: Enter the value of a and b.
03:41 I will enter as: 8 and 4.
03:46 The output is displayed as:
03:48 The result is: 12.
03:51 This brings us to the end of this tutorial.
03:54 Let us move back to our slides.
03:56 Let us summarize.In this tutorial, we learned Friend function. e.g. friend int compute class-name frnd and object 'f1' .
04:08 As an assignment, write a program to find out the square and cube of a number.
04:14 Watch the video available at the link shown below.
04:17 It summarizes the Spoken-Tutorial project.
04:20 If you do not have good bandwidth, you can download and watch it.
04:24 The Spoken-Tutorial Project team: conducts workshops using spoken tutorials.
04:30 Gives certificates to those who pass an online test.
04:33 For more details, please write to: contact@spoken-tutorial.org
04:40 Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
04:43 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
04:51 More information on this mission is available at the link shown below: http://spoken-tutorial.org/NMEICT-Intro
04:56 This is Ashwini Patil from IIT Bombay, signing off.Thank You for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14