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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''Title of script''': Objects and Classes in C++
 
 
'''Author: '''Ashwini Patil
 
 
'''Keywords: Inheritance, Single level Inheritance, Multilevel Inheritance, Multiple Inheritance, Video tutorial.'''
 
 
 
 
 
{| border=1
 
{| border=1
 
| '''Time'''
 
| '''Time'''
Line 17: Line 9:
 
|-
 
|-
 
| 00:06
 
| 00:06
| In this tutorial we will learn,
+
| In this tutorial, we will learn:
  
 
|-
 
|-
 
| 00:09
 
| 00:09
| '''Inheritance'''
+
|'''Inheritance''' Types of '''inheritance'''.
 
+
|-
+
| 00:10
+
|'''Types of inheritance'''
+
  
 
|-
 
|-
Line 33: Line 21:
 
|-
 
|-
 
| 00:16
 
| 00:16
| To record this tutorial, I am using
+
| To record this tutorial, I am using:
  
 
|-
 
|-
 
| 00:19
 
| 00:19
|'''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'''
  
 
|-
 
|-
 
| 00:28
 
| 00:28
|  Let us start with an Introduction to Inheritance
+
|  Let us start with an introduction to Inheritance.
  
 
|-
 
|-
 
| 00:32
 
| 00:32
|When one object acquires the property of another it is called as '''inheritance.'''
+
|When one '''object''' acquires the property of another, it is called as '''inheritance.'''
  
 
|-
 
|-
 
| 00:38
 
| 00:38
|It is the process of reusing the existing class without modifying them.
+
|It is the process of reusing the existing '''class''' without modifying them.
  
 
|-
 
|-
 
| 00:44
 
| 00:44
| '''Types of Inheritance'''
+
| Types of '''Inheritance'''- '''Single level inheritance'''
 
+
|-
+
| 00:45
+
|'''Single level inheritance'''
+
  
 
|-
 
|-
Line 73: Line 57:
 
|-
 
|-
 
| 00:52
 
| 00:52
|'''Multilevel inheritance'''
+
|'''Multilevel inheritance''' and
  
 
|-
 
|-
 
| 00:55
 
| 00:55
|'''Hybrid Inheritance'''
+
|'''Hybrid Inheritance'''.
  
 
|-
 
|-
 
|00:57
 
|00:57
| First let us know about the base class and the derived class.
+
| First, let us know about the '''base class''' and the '''derived class.'''
  
 
|-
 
|-
 
| 01:02
 
| 01:02
|The base class has its own properties and functionality.
+
|The '''base class''' has its own properties and functionality.
  
 
|-
 
|-
 
| 01:06
 
| 01:06
|It is also called as parent class.
+
|It is also called as '''parent class.'''
  
 
|-
 
|-
Line 97: Line 81:
 
|-
 
|-
 
| 01:14
 
| 01:14
|The derived class is the child class.
+
|The derived class is the '''child class.'''
  
 
|-
 
|-
 
| 01:18
 
| 01:18
|Derived class inherits the properties and functionality of the base class.
+
|'''Derived class''' inherits the properties and functionality of the '''base class.'''
  
 
|-
 
|-
 
| 01:23
 
| 01:23
|Let us see what is single level inheritance.
+
|Let us see what is '''single level inheritance.'''
  
 
|-
 
|-
 
| 01:27
 
| 01:27
| In single level inheritance only one base class and one derived class is needed.
+
| In '''single level inheritance''' only one '''base class''' and '''one derived''' class is needed.
  
 
|-
 
|-
 
| 01:34  
 
| 01:34  
| Multiple inheritance
+
| '''Multiple inheritance'''-
  
 
|-
 
|-
 
| 01:37
 
| 01:37
|In multiple inheritance derived class inherits from more than one base class.
+
|In '''multiple inheritance''', '''derived class''' inherits from more than one '''base class'''.
  
 
|-
 
|-
 
|01:44
 
|01:44
| '''Hierarchical Inheritance'''
+
| '''Hierarchical Inheritance'''-
  
 
|-
 
|-
 
|01:47
 
|01:47
| In Hierarchical Inheritance multiple derived classes inherits from one base class.
+
| In '''Hierarchical Inheritance''', multiple '''derived classes''' inherit from one '''base class.'''
  
 
|-
 
|-
 
| 01:55
 
| 01:55
| '''Multilevel inheritance'''
+
| '''Multilevel inheritance'''-
  
 
|-
 
|-
 
| 01:57
 
| 01:57
| In Multilevel inheritance the subclass acts as the base class for other classes.
+
| In '''Multilevel inheritance''', the '''subclass''' acts as the '''base class''' for other classes.
  
 
|-
 
|-
 
|  02:05
 
|  02:05
| and Hybrid inheritance  
+
| And '''Hybrid inheritance'''-
  
 
|-
 
|-
 
|  02:08
 
|  02:08
|  In hybrid inheritance more than one form of inheritance is combined.
+
|  In '''hybrid inheritance''', more than one form of '''inheritance''' is combined.
  
 
|-
 
|-
 
|  02:14  
 
|  02:14  
|  Now let us see an example on single level inheritance.
+
|  Now let us see an example on '''single level inheritance.'''
  
 
|-
 
|-
 
| 02:18
 
| 02:18
|I have already typed the code on the editor.
+
|I have already typed the code on the '''editor'''.
  
 
|-
 
|-
Line 157: Line 141:
 
|-
 
|-
 
| 02:23
 
| 02:23
|Note that our file name is  '''exam_inherit.cpp'''
+
|Note that our file name is  '''exam_inherit.cpp'''.
 
+
  
 
|-
 
|-
Line 166: Line 149:
 
|-
 
|-
 
| 02:35
 
| 02:35
| This is our header file as iostream
+
| This is our '''header file''' as '''iostream'''.
  
 
|-
 
|-
 
| 02:38
 
| 02:38
|  Here we are using the '''std namespace'''
+
|  Here, we are using the '''std namespace'''.
  
 
|-
 
|-
 
| 02:42
 
| 02:42
|  Here we have class '''student.'''
+
|  Here, we have class '''student.'''
  
 
|-
 
|-
 
| 02:44
 
| 02:44
|  Then we have an integer variable '''roll_no''' and '''character array name.
+
|  Then we have an '''integer variable''' '''roll_no''' and '''character array name''', as '''private''' members of '''class student'''.
 
+
|-
+
| 02:50
+
| As private members of '''class student'''.
+
  
 
|-
 
|-
 
| 02:53
 
| 02:53
|  Function '''input '''and function''' display '''are the public functions of class student.
+
|  Function '''input()''' and function''' display()''' are the '''public''' functions of '''class student'''.
 
+
  
 
|-
 
|-
 
| 02:59
 
| 02:59
| Here we are using the '''input''' function to accept the roll no. and name of the student.
+
| Here we are using the '''input()''' function to accept the roll no. and name of the student.
 
+
  
 
|-
 
|-
 
| 03:06
 
| 03:06
|  Then we have the '''display''' function to display the roll_no and name.
+
|  Then we have the '''display()''' function to display the roll_no and name.
 
+
  
 
|-
 
|-
 
| 03:11
 
| 03:11
|  Here we have another class as '''exam_inherit.'''
+
|  Here we have another '''class''' as '''exam_inherit.'''
  
 
|-
 
|-
 
| 03:16
 
| 03:16
|This is the derived class.
+
|This is the '''derived class.'''
  
 
|-
 
|-
 
| 03:18
 
| 03:18
|It inherits the function and data of class student.
+
|It inherits the function and data of '''class''' '''student.'''
  
 
|-
 
|-
 
| 03:23
 
| 03:23
|  Then we have declared ''' sub1, sub2, sub3 and total.'''
+
|  Then we have declared '''sub1, sub2, sub3''' and '''total'''
  
 
|-
 
|-
 
| 03:28
 
| 03:28
|As private variables of '''class exam_inherit.'''
+
|as '''private variables''' of '''class exam_inherit.'''
  
 
|-
 
|-
 
| 03:33
 
| 03:33
|  Here we have '''input_exam''' and '''display_exam as public functions.'''
+
|  Here we have '''input_exam()''' and '''display_exam()''' as '''public functions.'''
  
 
|-
 
|-
 
| 03:41
 
| 03:41
|Here we close the class '''exam_inherit.'''
+
|Here we close the '''class''' '''exam_inherit.'''
  
 
|-
 
|-
 
| 03:44
 
| 03:44
| Now we are using '''input_exam '''function to accept the marks of three''' '''subject.
+
| Now, we are using '''input_exam() '''function to accept the marks of three subjects.
 
+
  
 
|-
 
|-
 
| 03:52
 
| 03:52
|  Here, we are using display_exam function to calculate the total of three subjects.
+
|  Here, we are using '''display_exam()''' function to calculate the total of three subjects.
  
 
|-
 
|-
 
| 03:59
 
| 03:59
|Then we print a total.
+
|Then we '''print''' a total.
  
 
|-
 
|-
 
| 04:01
 
| 04:01
|  This is our '''main function.'''
+
|  This is our '''main()''' function.
  
 
|-
 
|-
 
| 04:03
 
| 04:03
|  Here we create an object of class exam_inherit as '''ex'''
+
|  Here we create an '''object''' of '''class''' '''exam_inherit''' as '''ex'''.
  
 
|-
 
|-
 
| 04:10
 
| 04:10
| | Then we call all the functions using the object '''ex'''
+
| Then we call all the functions using the object '''ex'''.
  
 
|-
 
|-
 
| 04:15
 
| 04:15
| And this is our return statement.
+
| And this is our '''return''' statement.
 
+
 
+
  
 
|-
 
|-
 
|  04:18
 
|  04:18
|  Let us execute the program
+
|  Let us execute the program.
  
 
|-
 
|-
 
| 04:20
 
| 04:20
| 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:30
 
| 04:30
|  To compile, type
+
|  To compile, type:
  
 
|-
 
|-
 
| 04:31
 
| 04:31
|'''g++ (space)exam_inherit.cpp (space)-o (space) exam'''
+
|'''g++ (space) exam_inherit.cpp (space)-o (space) exam'''.
  
 
|-
 
|-
 
| 04:41
 
| 04:41
| Press Enter.
+
| Press '''Enter'''.Type:'''./ (dot slash) exam'''. Press '''Enter'''.
 
+
|-
+
| 04:42
+
|Type
+
 
+
|-
+
| 04:43
+
|'''./exam''' Press Enter.
+
  
 
|-
 
|-
 
| 04:46
 
| 04:46
|  Here it is displayed as,
+
|  Here it is displayed as:'''Enter Roll no.:'''
 
+
|-
+
| 04:47
+
|'''Enter Roll no.:'''
+
  
 
|-
 
|-
 
| 04:49
 
| 04:49
|'''I will give as 1'''
+
|I will give as 1.
  
 
|-
 
|-
 
| 04:51
 
| 04:51
|'''Enter Name:'''
+
|'''Enter Name:'''I will enter as '''Arya'''.
 
+
|-
+
| 04:52
+
|'''I will enter as Arya'''
+
  
 
|-
 
|-
Line 312: Line 269:
 
|-
 
|-
 
| 04:57
 
| 04:57
|'''I will give as 60'''
+
|I will give as '''60''',
  
 
|-
 
|-
 
|  05:00
 
|  05:00
| '''subject 2 as 70'''
+
| '''subject 2''' as 70'''
  
 
|-
 
|-
 
|  05:02
 
|  05:02
| And '''subjec 3 as 80'''
+
| and '''subjec 3''' as 80'''.
  
 
|-
 
|-
 
| 05:06
 
| 05:06
| The output is displayed as  
+
| The '''output''' is displayed as:
  
 
|-
 
|-
 
| 05:08
 
| 05:08
|'''Roll no is: 1'''
+
|'''Roll no is: 1''''''Name is: Arya''' and
 
+
|-
+
| 05:09
+
|'''Name is: Arya''' and,
+
  
 
|-
 
|-
 
| 05:11
 
| 05:11
|'''Total is: 210'''
+
|'''Total is: 210'''.
  
 
|-
 
|-
 
| 05:13
 
| 05:13
|  Now we will see multilevel inheritance in the same example.
+
|  Now, we will see '''multilevel inheritance''' in the same example.
  
 
|-
 
|-
Line 348: Line 301:
 
|-
 
|-
 
| 05:20
 
| 05:20
|Let's switch back to our editor.
+
|Let's switch back to our '''editor'''.
  
 
|-
 
|-
 
| 05:22
 
| 05:22
|Note that our filename is '''multilevel.cpp'''
+
|Note that our file name is '''multilevel.cpp'''.
  
 
|-
 
|-
 
| 05:28
 
| 05:28
| Here we have declared the variable total.
+
| Here, we have declared the variable '''total'''.
  
 
|-
 
|-
 
| 05:32
 
| 05:32
|As public variable of class exam_inherit.
+
|as '''public variable''' of '''class''' '''exam_inherit.'''
  
 
|-
 
|-
 
| 05:38
 
| 05:38
|This is because the private members are not accessed by the derived class.
+
|This is because the '''private''' members are not accessed by the '''derived class.'''
  
 
|-
 
|-
 
| 05:44
 
| 05:44
|  Here we have another class as '''grade.'''
+
|  Here we have another '''class''' as '''grade.'''
  
 
|-
 
|-
Line 376: Line 329:
 
|-
 
|-
 
| 05:53
 
| 05:53
|Class '''grade''' is the derived class  
+
|Class '''grade''' is the '''derived class'''
  
 
|-
 
|-
 
| 05:56
 
| 05:56
| And class '''exam_inherit''' is the base class for class '''grade'''.
+
| and class '''exam_inherit''' is the '''base class''' for class '''grade'''.
  
 
|-
 
|-
 
| 06:02
 
| 06:02
| All the functions and data of class '''exam_inherit''' will be inherited to class '''grade'''.
+
| All the '''function'''s and '''data''' of class '''exam_inherit''' will be inherited to class '''grade'''.
  
 
|-
 
|-
 
| 06:11
 
| 06:11
| Here we have declared '''avg''' as private member of class '''grade.'''  
+
| Here, we have declared '''avg''' as '''private''' member of '''class grade'''  
  
 
|-
 
|-
 
| 06:17
 
| 06:17
|And function '''average''' as public function.
+
|and function '''average()''' as '''public''' function.
  
 
|-
 
|-
 
| 06:21
 
| 06:21
|Then we close the class.
+
|Then we close the '''class'''.
  
 
|-
 
|-
 
| 06:23
 
| 06:23
| Here we use the average function to calculate the average.
+
| Here we use the '''average()''' function to calculate the average.
  
 
|-
 
|-
 
| 06:27
 
| 06:27
|Then we print the average.
+
|Then we print the '''average.'''
  
 
|-
 
|-
 
| 06:30
 
| 06:30
| Inside the main function we create an object of class grade as '''gd.'''
+
| Inside the main function, we create an '''object''' of '''class grade''' as '''gd.'''
  
 
|-
 
|-
Line 416: Line 369:
 
|-
 
|-
 
| 06:40
 
| 06:40
|gd.input()
+
|'''gd.input()'''
  
 
|-
 
|-
 
| 06:42
 
| 06:42
|input_exam
+
|'''input_exam()'''
  
 
|-
 
|-
 
| 06:44
 
| 06:44
|display
+
|'''display()''''''display_exam()'''
 
+
|-
+
| 06:45
+
|display_exam
+
  
 
|-
 
|-
 
| 06:46
 
| 06:46
|and the average function.
+
|and the '''average()''' function.
  
 
|-
 
|-
 
| 06:49
 
| 06:49
|  And this is our return statement.
+
|  And this is our '''return''' statement.
  
 
|-
 
|-
 
|  06:52
 
|  06:52
|  Now you can see that class grade is the derived class.
+
|  Now you can see that class '''grade''' is the '''derived class.'''
  
 
|-
 
|-
 
|  06:56
 
|  06:56
| And exam_inherit is the base class for class grade.
+
| and '''exam_inherit''' is the '''base class''' for class '''grade.'''
  
 
|-
 
|-
 
| 07:01
 
| 07:01
| And here class exam_inherit is the derived class.
+
| And here class '''exam_inherit''' is the '''derived class.'''
  
 
|-
 
|-
 
| 07:06
 
| 07:06
| And class student is the base class for class exam_inherit.
+
| And class '''student''' is the '''base class''' for class '''exam_inherit.'''
  
 
|-
 
|-
 
| 07:12
 
| 07:12
| Let us execute the program.
+
| Let us '''execute''' the program.
  
 
|-
 
|-
 
| 07:14
 
| 07:14
| Come back to our terminal.
+
| Come back to our '''terminal'''.
  
 
|-
 
|-
 
| 07:17
 
| 07:17
| To compile, type
+
| To compile, type:'''g++ (space) multilevel.cpp (space) -o (space) mul'''
 
+
|-
+
| 07:17
+
|'''g++ (space) multilevel.cpp (space) -o (space) mul'''
+
  
 
|-
 
|-
 
| 07:26
 
| 07:26
|'''Press Enter'''
+
|Press '''Enter'''.Type '''./mul'''
 
+
|-
+
| 07:27
+
|Type
+
 
+
'''./mul'''
+
  
 
|-
 
|-
 
| 07:30
 
| 07:30
|'''Press Enter'''
+
|Press '''Enter'''.
  
 
|-
 
|-
 
| 07:32
 
| 07:32
| Here we see,
+
| Here we see, '''Enter Roll no.:'''
 
+
'''Enter Roll no.:'''
+
  
 
|-
 
|-
 
| 07:34
 
| 07:34
|I will enter as '''2'''
+
|I will enter as '''2'''.
  
 
|-
 
|-
Line 500: Line 437:
 
|-
 
|-
 
| 07:38
 
| 07:38
|I will enter as '''Pratham'''
+
|I will enter as '''Pratham'''.
  
 
|-
 
|-
Line 508: Line 445:
 
|-
 
|-
 
| 07:43
 
| 07:43
|I will give as '''65'''
+
|I will give as '''65''',
  
 
|-
 
|-
 
| 07:46
 
| 07:46
|'''subject2 as 67''' and,
+
|subject2 as '''67''' and
  
 
|-
 
|-
 
| 07:48
 
| 07:48
|'''subject3 as 82'''
+
|subject3 as '''82'''.
 
+
  
 
|-
 
|-
 
| 07:52
 
| 07:52
| The output is displayed as:
+
| The '''output''' is displayed as:
  
 
|-
 
|-
Line 529: Line 465:
 
|-
 
|-
 
| 07:56
 
| 07:56
|'''Name is: Pratham '''
+
|'''Name is: Pratham ''''''Total is: 214 ''' and  
 
+
|-
+
| 07:57
+
|'''Total is: 214 ''' and,
+
  
 
|-
 
|-
 
| 07:59
 
| 07:59
|'''Average is: 71'''  
+
|'''Average is: 71'''.
  
 
|-
 
|-
Line 545: Line 477:
 
|-
 
|-
 
|  08:05
 
|  08:05
|Let us move back to our slides.
+
|Let us move back to our '''slides'''. Let us summarize.
 
+
|-
+
|  08:07
+
| Let us summarize
+
  
 
|-
 
|-
 
|  08:08
 
|  08:08
|In this tutorial, we learnt,
+
|In this tutorial, we learnt:
  
 
|-
 
|-
 
|  08:10
 
|  08:10
|Inheritance and,
+
|'''Inheritance''' and * Types of '''inheritance.'''
 
+
|-
+
|  08:11
+
| Types of inheritance.
+
  
 
|-
 
|-
 
| 08:14
 
| 08:14
|  As an assignment  
+
|  As an assignment- write a program to create a '''class''' '''Shape'''.
 
+
 
+
|-
+
| 08:15
+
| Write a program to Create a class Shape.
+
  
 
|-
 
|-
 
| 08:18
 
| 08:18
| Then Create two functions of the class as Area and Perimeter.
+
| Then create two '''function'''s of the '''class''' as '''Area''' and '''Perimeter'''.
  
 
|-
 
|-
Line 582: Line 501:
 
|-
 
|-
 
|  08:31
 
|  08:31
| Watch the video available at the link shown below
+
| Watch the video available at the link shown below.
  
 
|-
 
|-
 
|  08:34
 
|  08:34
|It summarizes the Spoken Tutorial project  
+
|It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
|  08:37
 
|  08: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.
  
 
|-
 
|-
 
| 08:42
 
| 08:42
|  The Spoken Tutorial Project Team  
+
|  The Spoken Tutorial Project Team:
  
 
|-
 
|-
 
| 08:44
 
| 08:44
|Conducts workshops using spoken tutorials  
+
|Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 08:47
 
| 08:47
|Gives certificates to those who pass an online test  
+
|Gives certificates to those who pass an online test.
  
 
|-
 
|-
 
| 08:51
 
| 08:51
|For more details, please write to,
+
|For more details, please write to:
  
 
|-
 
|-
Line 614: Line 533:
 
|-
 
|-
 
| 08:58
 
| 08: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.
  
 
|-
 
|-
Line 622: Line 541:
 
|-
 
|-
 
| 09:09
 
| 09:09
|More information on this Mission is available at the link shown below
+
|More information on this mission is available at the link shown below.
  
 
|-
 
|-
 
| 09:13  
 
| 09: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.  
+
  
 
|}
 
|}

Latest revision as of 13:17, 23 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on Inheritance in C++.
00:06 In this tutorial, we will learn:
00:09 Inheritance Types of inheritance.
00:12 We will do this with the help of examples.
00:16 To record this tutorial, I am using:
00:19 Ubuntu OS version 11.10
00:24 g++ compiler version 4.6.1
00:28 Let us start with an introduction to Inheritance.
00:32 When one object acquires the property of another, it is called as inheritance.
00:38 It is the process of reusing the existing class without modifying them.
00:44 Types of Inheritance- Single level inheritance
00:48 Multiple level inheritance
00:50 Hierarchical Inheritance
00:52 Multilevel inheritance and
00:55 Hybrid Inheritance.
00:57 First, let us know about the base class and the derived class.
01:02 The base class has its own properties and functionality.
01:06 It is also called as parent class.
01:09 It has the common qualities that all the objects can inherit.
01:14 The derived class is the child class.
01:18 Derived class inherits the properties and functionality of the base class.
01:23 Let us see what is single level inheritance.
01:27 In single level inheritance only one base class and one derived class is needed.
01:34 Multiple inheritance-
01:37 In multiple inheritance, derived class inherits from more than one base class.
01:44 Hierarchical Inheritance-
01:47 In Hierarchical Inheritance, multiple derived classes inherit from one base class.
01:55 Multilevel inheritance-
01:57 In Multilevel inheritance, the subclass acts as the base class for other classes.
02:05 And Hybrid inheritance-
02:08 In hybrid inheritance, more than one form of inheritance is combined.
02:14 Now let us see an example on single level inheritance.
02:18 I have already typed the code on the editor.
02:21 I will explain it.
02:23 Note that our file name is exam_inherit.cpp.
02:28 The example involves to display the name, roll no and marks of the student.
02:35 This is our header file as iostream.
02:38 Here, we are using the std namespace.
02:42 Here, we have class student.
02:44 Then we have an integer variable roll_no and character array name, as private members of class student.
02:53 Function input() and function display() are the public functions of class student.
02:59 Here we are using the input() function to accept the roll no. and name of the student.
03:06 Then we have the display() function to display the roll_no and name.
03:11 Here we have another class as exam_inherit.
03:16 This is the derived class.
03:18 It inherits the function and data of class student.
03:23 Then we have declared sub1, sub2, sub3 and total
03:28 as private variables of class exam_inherit.
03:33 Here we have input_exam() and display_exam() as public functions.
03:41 Here we close the class exam_inherit.
03:44 Now, we are using input_exam() function to accept the marks of three subjects.
03:52 Here, we are using display_exam() function to calculate the total of three subjects.
03:59 Then we print a total.
04:01 This is our main() function.
04:03 Here we create an object of class exam_inherit as ex.
04:10 Then we call all the functions using the object ex.
04:15 And this is our return statement.
04:18 Let us execute the program.
04:20 Open the terminal window by pressing Ctrl, Alt and T keys simultaneously, on your keyboard.
04:30 To compile, type:
04:31 g++ (space) exam_inherit.cpp (space)-o (space) exam.
04:41 Press Enter.Type:./ (dot slash) exam. Press Enter.
04:46 Here it is displayed as:Enter Roll no.:
04:49 I will give as 1.
04:51 Enter Name:I will enter as Arya.
04:55 Enter marks of subject1
04:57 I will give as 60,
05:00 subject 2 as 70
05:02 and subjec 3 as 80.
05:06 The output is displayed as:
05:08 'Roll no is: 1'Name is: Arya and
05:11 Total is: 210.
05:13 Now, we will see multilevel inheritance in the same example.
05:18 I have already typed the code.
05:20 Let's switch back to our editor.
05:22 Note that our file name is multilevel.cpp.
05:28 Here, we have declared the variable total.
05:32 as public variable of class exam_inherit.
05:38 This is because the private members are not accessed by the derived class.
05:44 Here we have another class as grade.
05:49 This inherits the class exam_inherit.
05:53 Class grade is the derived class
05:56 and class exam_inherit is the base class for class grade.
06:02 All the functions and data of class exam_inherit will be inherited to class grade.
06:11 Here, we have declared avg as private member of class grade
06:17 and function average() as public function.
06:21 Then we close the class.
06:23 Here we use the average() function to calculate the average.
06:27 Then we print the average.
06:30 Inside the main function, we create an object of class grade as gd.
06:36 Then we call all the functions using the object gd.
06:40 gd.input()
06:42 input_exam()
06:44 'display()'display_exam()
06:46 and the average() function.
06:49 And this is our return statement.
06:52 Now you can see that class grade is the derived class.
06:56 and exam_inherit is the base class for class grade.
07:01 And here class exam_inherit is the derived class.
07:06 And class student is the base class for class exam_inherit.
07:12 Let us execute the program.
07:14 Come back to our terminal.
07:17 To compile, type:g++ (space) multilevel.cpp (space) -o (space) mul
07:26 Press Enter.Type ./mul
07:30 Press Enter.
07:32 Here we see, Enter Roll no.:
07:34 I will enter as 2.
07:36 Enter Name:
07:38 I will enter as Pratham.
07:41 Enter marks of subject1
07:43 I will give as 65,
07:46 subject2 as 67 and
07:48 subject3 as 82.
07:52 The output is displayed as:
07:54 Roll no is: 2
07:56 'Name is: Pratham 'Total is: 214 and
07:59 Average is: 71.
08:01 This brings us to the end of this tutorial.
08:05 Let us move back to our slides. Let us summarize.
08:08 In this tutorial, we learnt:
08:10 Inheritance and * Types of inheritance.
08:14 As an assignment- write a program to create a class Shape.
08:18 Then create two functions of the class as Area and Perimeter.
08:23 Then find the area and perimeter of various shapes like square, rectangle and circle.
08:31 Watch the video available at the link shown below.
08:34 It summarizes the Spoken Tutorial project.
08:37 If you do not have good bandwidth, you can download and watch it.
08:42 The Spoken Tutorial Project Team:
08:44 Conducts workshops using spoken tutorials.
08:47 Gives certificates to those who pass an online test.
08:51 For more details, please write to:
08:53 contact@spoken-tutorial.org
08:58 Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
09:02 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
09:09 More information on this mission is available at the link shown below.
09:13 This is Ashwini Patil from IIT Bombay, signing off. Thank You for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Ranjana, Sandhya.np14