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

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 7: Line 7:
 
|-
 
|-
 
| 00:01
 
| 00:01
| Welcome to the spoken tutorial on '''static members''' in C++.
+
| Welcome to the '''spoken tutorial''' on '''static members''' in '''C++'''.
  
 
|-
 
|-
 
| 00:06
 
| 00:06
|  In this tutorial we will learn,
+
|  In this tutorial, we will learn:
  
 
|-
 
|-
 
| 00:09
 
| 00:09
|'''Static keyoword.'''
+
|* '''Static keyoword.'''
  
 
|-
 
|-
 
| 00:10
 
| 00:10
|'''Static variable'''
+
|* '''Static variable'''
  
 
|-
 
|-
 
| 00:12
 
| 00:12
|'''Static function'''
+
|* '''Static function'''.
  
 
|-
 
|-
 
| 00:14
 
| 00:14
|We will do this through an examples.
+
|We will do this through an example.
  
 
|-
 
|-
 
|  00:17
 
|  00:17
|  To record this tutorial, I am using
+
|  To record this tutorial, I am using:
  
 
|-
 
|-
 
| 00:20
 
| 00:20
| '''Ubuntu OS '''version 11.10
+
|* '''Ubuntu OS '''version '''11.10'''
  
 
|-
 
|-
 
| 00:24
 
| 00:24
| '''g++ compiler '''v. 4.6.1
+
|* '''g++ compiler '''version '''4.6.1'''
  
 
|-
 
|-
Line 63: Line 63:
 
|-
 
|-
 
|00:52
 
|00:52
|  '''Static functions'''
+
|  '''Static functions'''-
  
 
|-
 
|-
 
| 00:54
 
| 00:54
| A static function may be called by itself without depending on any object.
+
| A '''static function''' may be called by itself without depending on any '''object'''.
  
 
|-
 
|-
 
| 01.00
 
| 01.00
| To access a static function we use,
+
| To access a static function, we use-
  
 
|-
 
|-
 
| 01.03
 
| 01.03
| classname :: (scope resolution operator) and the staticfunction();
+
| '''classname :: (scope resolution operator)''' and the '''staticfunction();'''
  
 
|-
 
|-
 
| 01:09
 
| 01:09
| Let us see an example on static memebers.
+
| Let us see an example on '''static memeber'''s.
  
 
|-
 
|-
 
| 01:13
 
| 01:13
| I have already typed the code on the editor.
+
| I have already typed the code on the '''editor'''.
  
 
|-
 
|-
 
| 01:17
 
| 01:17
|  Note that our file name is '''static dot cpp'''
+
|  Note that our file name is '''static dot cpp'''.
  
 
|-
 
|-
Line 95: Line 95:
 
|-
 
|-
 
|  01:24
 
|  01:24
|This is our headerfile as '''iostream'''
+
|This is our '''header file''' as '''iostream'''.
  
 
|-
 
|-
 
|01:27
 
|01:27
| Here we are using the '''std namespace'''
+
| Here we are using the '''std namespace'''.
  
 
|-
 
|-
Line 107: Line 107:
 
|-
 
|-
 
| 01:34
 
| 01:34
|  In this we have a non-static variable as x declared as '''private.'''
+
|  In this, we have a '''non-static variable''' as 'x' declared as '''private.'''
  
 
|-
 
|-
 
| 01:40
 
| 01:40
| Then we have a static variable '''sum''' declared as '''public.'''
+
| Then we have a '''static variable''' '''sum''' declared as '''public.'''
  
 
|-
 
|-
Line 119: Line 119:
 
|-
 
|-
 
| 01:48
 
| 01:48
| In this we have incremented''' sum.'''
+
| In this, we have incremented''' sum.'''
  
 
|-
 
|-
 
| 01:52
 
| 01:52
| Then the value of''' sum '''is stored in''' x.'''
+
| Then the value of''' sum '''is stored in 'x'.
  
 
|-
 
|-
 
| 01:55
 
| 01:55
|  Here we have a '''static function''' '''stat.'''
+
|  Here we have a '''static function''' '''stat'''.
  
 
|-
 
|-
 
| 01:58
 
| 01:58
| In this we print the''' sum.'''
+
| In this, we print the''' sum.'''
  
 
|-
 
|-
 
| 02:01
 
| 02:01
|Then we have''' function number.'''
+
|Then we have function '''number().'''
  
 
|-
 
|-
 
| 02:04
 
| 02:04
| Here we print the number''' x'''
+
| Here we print the number 'x'.
  
 
|-
 
|-
 
| 02:07
 
| 02:07
| The class is closed here.
+
| The '''class''' is closed here.
  
 
|-
 
|-
 
| 02:10
 
| 02:10
|  To declare the '''static variable''' globally we use '''scope resolution operator.'''
+
|  To declare the '''static variable''' globally, we use '''scope resolution operator.'''
  
 
|-
 
|-
Line 155: Line 155:
 
|-
 
|-
 
| 02:19
 
| 02:19
| '''datatype classname scope resolution operator''' and '''static variable name.'''
+
| '''datatype classname scope resolution operator''' and the '''static variable name.'''
  
 
|-
 
|-
Line 167: Line 167:
 
|-
 
|-
 
| 02:33
 
| 02:33
|  This is our '''main function.'''
+
|  This is our '''main()''' function.
  
 
|-
 
|-
 
| 02:35
 
| 02:35
|  Here we create objects of class '''statex.'''
+
|  Here, we create objects of '''class''' '''statex'''
  
 
|-
 
|-
 
| 02:39
 
| 02:39
| As '''o1''', '''o2''' and '''o3.'''
+
| as '''o1''', '''o2''' and '''o3.'''
  
 
|-
 
|-
 
| 02:42
 
| 02:42
|  Then we call the function number using the objects ''' o1, o2''' and '''o3.'''
+
|  Then we call the function '''number()''' using the objects '''o1, o2''' and '''o3.'''
  
 
|-
 
|-
 
| 02:49
 
| 02:49
| '''Static''' function '''stat''' is accessed here.
+
| '''Static''' function '''stat()''' is accessed here
  
 
|-
 
|-
 
| 02:52
 
| 02:52
| Using the '''class name '''and the ''' scope resolution operator.'''
+
| using the '''class name '''and the ''' scope resolution operator.'''
  
 
|-
 
|-
 
| 02:56
 
| 02:56
| Here we print the '''static variable sum.'''
+
| Here, we print the '''static variable sum.'''
  
 
|-
 
|-
 
| 03:00
 
| 03:00
|  And this is the '''return''' statement.
+
|  And this is our '''return''' statement.
  
 
|-
 
|-
 
| 03:03
 
| 03:03
|  Let us execute the program.
+
|  Let us '''execute''' the program.
  
 
|-
 
|-
 
| 03:05
 
| 03:05
|  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.
  
 
|-
 
|-
 
| 03:13
 
| 03:13
|  To compile type  
+
|  To compile, type:
  
 
|-
 
|-
 
| 03:15
 
| 03:15
| '''g++ space static dot cpp space hyphen o space stat'''. Press '''Enter'''
+
| '''g++ space static dot cpp space hyphen o space stat'''. Press '''Enter'''.
  
 
|-
 
|-
 
| 03:24
 
| 03:24
|  Type '''./stat''' (dot slash stat). Press Enter
+
|  Type: '''./stat''' (dot slash stat). Press '''Enter'''.
  
 
|-
 
|-
 
| 03:28
 
| 03:28
| The output is displayed as,
+
| The '''output''' is displayed as:
  
 
|-
 
|-
Line 231: Line 231:
 
|-
 
|-
 
| 03:35
 
| 03:35
| '''Now static var sum is 3'''
+
| '''Now static var sum is 3'''.
  
 
|-
 
|-
 
|03:38
 
|03:38
|  Now I will explain the output:
+
|  Now, I will explain the output.
  
 
|-
 
|-
 
| 03:39
 
| 03:39
| Let me resize the window.
+
| Let me resize the '''window'''.
  
 
|-
 
|-
 
| 03:42
 
| 03:42
| Here, First the value of''' number '''is''' 0''' ie.''' x''' is '''0.'''
+
| Here, first the value of''' number '''is''' 0''' i.e.' x' is '''0.'''
  
 
|-
 
|-
 
| 03:49
 
| 03:49
| The first object gives the value as''' 0'''
+
| The first '''object''' gives the '''value''' as''' 0'''.
  
 
|-
 
|-
 
| 03:53
 
| 03:53
| Then we have the value as '''1''' ie.''' x =1'''
+
| Then we have the value as '''1''' i.e.''' x =1'''.
  
 
|-
 
|-
 
| 03:58
 
| 03:58
| The second object gives the value as''' 1'''
+
| The second object gives the value as''' 1'''.
  
 
|-
 
|-
 
| 04:01
 
| 04:01
| And the third object gives the value as''' 2'''
+
| And the third object gives the value as''' 2'''.
  
 
|-
 
|-
 
| 04:05
 
| 04:05
| Then we call the '''stat''' function which gives the value of '''sum'''.
+
| Then we call the '''stat()''' function which gives the value of '''sum'''.
  
 
|-
 
|-
 
| 04:10
 
| 04:10
| '''Result is sum.'''
+
| '''Result is: sum.'''
  
 
|-
 
|-
 
| 04:13
 
| 04:13
| Here sum is incremented and stored in''' x.'''
+
| Here, '''sum''' is incremented and stored in 'x.'  
  
 
|-
 
|-
 
| 04:18
 
| 04:18
| Hence this will give the value as''' 3.'''
+
| Hence, this will give the value as''' 3.'''
  
 
|-
 
|-
Line 287: Line 287:
 
|-
 
|-
 
| 04:28
 
| 04:28
| Now let us create another object here as '''o4.'''
+
| Now, let us create another '''object''' here as '''o4.'''
  
 
|-
 
|-
 
| 04:34
 
| 04:34
|  I will call the function '''number''' using the''' object o4.'''
+
|  I will call the function '''number()''' using the''' object o4.'''
  
 
|-
 
|-
 
| 04:43
 
| 04:43
| Click on '''Save'''
+
| Click on '''Save'''.
  
 
|-
 
|-
 
| 04:45
 
| 04:45
|  Let us execute.
+
|  Let us '''execute'''.
  
 
|-
 
|-
 
| 04:48
 
| 04:48
| Press the up arrow key twice.
+
| Press the 'up arrow' key twice.
  
 
|-
 
|-
 
| 04:51
 
| 04:51
| Again Press the up arrow key twice.
+
| Again press the 'up arrow' key twice.
  
 
|-
 
|-
Line 315: Line 315:
 
|-
 
|-
 
| 04:57
 
| 04:57
| '''Now static var sum is 4'''
+
| '''Now static var sum is 4'''.
  
 
|-
 
|-
 
| 05:00
 
| 05:00
| As the 4th object is created.
+
| As the 4th '''object''' is created.
  
 
|-
 
|-
Line 327: Line 327:
 
|-
 
|-
 
| 05:06
 
| 05:06
| Come back to the slides.
+
| Come back to our '''slides'''.
  
 
|-
 
|-
 
|05:08
 
|05:08
| Let us summarize:
+
| Let us summarize.
  
 
|-
 
|-
 
| 05:10
 
| 05:10
| In this tutorial, we learned,
+
| In this tutorial, we learned:
  
 
|-
 
|-
 
| 05:12
 
| 05:12
| '''static keyword.'''
+
|* '''static keyword'''
  
 
|-
 
|-
 
| 05:13
 
| 05:13
| '''Static variable'''
+
|* '''static variable'''
  
 
|-
 
|-
Line 351: Line 351:
 
|-
 
|-
 
| 05:18
 
| 05:18
| '''Static function.'''
+
|* '''static function.'''
  
 
|-
 
|-
Line 359: Line 359:
 
|-
 
|-
 
| 05:22
 
| 05:22
|  As an assignment  
+
|  As an assignment-
  
 
|-
 
|-
 
| 05:23
 
| 05:23
| Create a class that declares a '''static variable.'''
+
| Create a '''class''' that declares a '''static variable''',
  
 
|-
 
|-
 
| 05:26
 
| 05:26
| Decrement the variable.
+
| decrement the variable,
  
 
|-
 
|-
Line 375: Line 375:
 
|-
 
|-
 
| 05:31
 
| 05:31
|  Watch the video available at the link shown  
+
|  Watch the video available at the link shown below.
  
 
|-
 
|-
 
| 05:34
 
| 05:34
| It summarizes the Spoken Tutorial project  
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
| 05:37
 
| 05:37
| 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:41
 
| 05:41
|  The Spoken Tutorial Project Team  
+
|  The Spoken Tutorial Project Team:
  
 
|-
 
|-
 
| 05:44
 
| 05:44
| Conducts workshops using spoken tutorials  
+
| Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 05:47
 
| 05:47
| Gives certificates to those who pass an online test  
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 403: Line 403:
 
|-
 
|-
 
| 05:58
 
| 05:58
|  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.
  
 
|-
 
|-
 
| 06:02
 
| 06:02
| 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.
  
 
|-
 
|-
 
| 06:08
 
| 06:08
| More information on this Mission is available at the link shown below  
+
| More information on this mission is available at the link shown below.
  
 
|-
 
|-
 
|06:13
 
|06:13
| 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 17:57, 27 June 2015


Time Narration
00:01 Welcome to the spoken tutorial on static members in C++.
00:06 In this tutorial, we will learn:
00:09 * Static keyoword.
00:10 * Static variable
00:12 * Static function.
00:14 We will do this through an example.
00:17 To record this tutorial, I am using:
00:20 * Ubuntu OS version 11.10
00:24 * g++ compiler version 4.6.1
00:29 Let us start with an introduction to static.
00:33 Static variables are initialized to zero before the first object is created.
00:39 Only one copy of the static variable exists for the whole program.
00:44 All the objects will share that variable.
00:47 It will remain in the memory till the end of the program.
00:52 Static functions-
00:54 A static function may be called by itself without depending on any object.
01.00 To access a static function, we use-
01.03 classname :: (scope resolution operator) and the staticfunction();
01:09 Let us see an example on static memebers.
01:13 I have already typed the code on the editor.
01:17 Note that our file name is static dot cpp.
01:21 Let me explain the code now.
01:24 This is our header file as iostream.
01:27 Here we are using the std namespace.
01:31 Then we have class statex.
01:34 In this, we have a non-static variable as 'x' declared as private.
01:40 Then we have a static variable sum declared as public.
01:45 This is our constructor statex.
01:48 In this, we have incremented sum.
01:52 Then the value of sum is stored in 'x'.
01:55 Here we have a static function stat.
01:58 In this, we print the sum.
02:01 Then we have function number().
02:04 Here we print the number 'x'.
02:07 The class is closed here.
02:10 To declare the static variable globally, we use scope resolution operator.
02:15 To access a static variable we write as:
02:19 datatype classname scope resolution operator and the static variable name.
02:26 Now the storage is allocated to variable sum.
02:31 It is initialized to 0.
02:33 This is our main() function.
02:35 Here, we create objects of class statex
02:39 as o1, o2 and o3.
02:42 Then we call the function number() using the objects o1, o2 and o3.
02:49 Static function stat() is accessed here
02:52 using the class name and the scope resolution operator.
02:56 Here, we print the static variable sum.
03:00 And this is our return statement.
03:03 Let us execute the program.
03:05 Open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
03:13 To compile, type:
03:15 g++ space static dot cpp space hyphen o space stat. Press Enter.
03:24 Type: ./stat (dot slash stat). Press Enter.
03:28 The output is displayed as:
03:30 Number is: 0, 1, 2
03:33 Result is: 3
03:35 Now static var sum is 3.
03:38 Now, I will explain the output.
03:39 Let me resize the window.
03:42 Here, first the value of number is 0 i.e.' x' is 0.
03:49 The first object gives the value as 0.
03:53 Then we have the value as 1 i.e. x =1.
03:58 The second object gives the value as 1.
04:01 And the third object gives the value as 2.
04:05 Then we call the stat() function which gives the value of sum.
04:10 Result is: sum.
04:13 Here, sum is incremented and stored in 'x.'
04:18 Hence, this will give the value as 3.
04:22 Thus the final output we have is.
04:25 Static var sum is 3.
04:28 Now, let us create another object here as o4.
04:34 I will call the function number() using the object o4.
04:43 Click on Save.
04:45 Let us execute.
04:48 Press the 'up arrow' key twice.
04:51 Again press the 'up arrow' key twice.
04:54 You can see that Result is 4.
04:57 Now static var sum is 4.
05:00 As the 4th object is created.
05:03 This brings us to the end of this tutorial.
05:06 Come back to our slides.
05:08 Let us summarize.
05:10 In this tutorial, we learned:
05:12 * static keyword
05:13 * static variable
05:15 eg. static int sum;
05:18 * static function.
05:19 eg. static void stat()
05:22 As an assignment-
05:23 Create a class that declares a static variable,
05:26 decrement the variable,
05:29 And print the value.
05:31 Watch the video available at the link shown below.
05:34 It summarizes the Spoken Tutorial project.
05:37 If you do not have good bandwidth, you can download and watch it.
05:41 The Spoken Tutorial Project Team:
05:44 Conducts workshops using spoken tutorials.
05:47 Gives certificates to those who pass an online test.
05:51 For more details, please write to, contact@spoken-tutorial.org
05:58 Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
06:02 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
06:08 More information on this mission is available at the link shown below.
06:13 This is Ashwini Patil from IIT Bombay, signing off.

Thank You for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Ranjana, Sandhya.np14