Difference between revisions of "Advanced-C++/C2/Abstract-Class/English-timed"
From Script | Spoken-Tutorial
(Created page with ' {| border=1 | '''Time''' | '''Narration''' |- | 00.01 | Welcome to the spoken tutorial on '''abstract class''' and '''pure virtual function''' in '''C++.''' |- | 00.08 |In…') |
|||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
{| border=1 | {| border=1 | ||
| '''Time''' | | '''Time''' | ||
Line 7: | Line 4: | ||
|- | |- | ||
− | | 00 | + | | 00:01 |
− | | Welcome to the spoken tutorial on '''abstract class''' and '''pure virtual function''' in '''C++.''' | + | | Welcome to the '''spoken-tutorial''' on '''abstract class''' and '''pure virtual function''' in '''C++.''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | | 00 | + | | 00:08 |
− | | | + | |In this tutorial, we will learn: |
|- | |- | ||
− | | 00 | + | | 00:10 |
− | | | + | | Abstract Classes, Pure virtual function. |
|- | |- | ||
− | | 00 | + | | 00:13 |
− | | | + | |We will do this through an example. |
|- | |- | ||
− | | 00 | + | | 00:16 |
− | | To record this tutorial, I am using | + | | To record this tutorial, I am using: |
|- | |- | ||
− | | 00 | + | | 00:19 |
− | | | + | |'''Ubuntu OS '''version '''11.10''' |
|- | |- | ||
− | | 00 | + | | 00:23 |
− | | | + | |'''g++ compiler '''version '''4.6.1''' |
|- | |- | ||
− | | 00 | + | | 00:27 |
| Let us start with an introduction to '''abstract class.''' | | Let us start with an introduction to '''abstract class.''' | ||
|- | |- | ||
− | | 00 | + | | 00:31 |
|'''Abstract class '''is always a '''base class'''. | |'''Abstract class '''is always a '''base class'''. | ||
|- | |- | ||
− | | 00 | + | | 00:35 |
|It contains at least one '''pure virtual function.''' | |It contains at least one '''pure virtual function.''' | ||
|- | |- | ||
− | | 00 | + | | 00:39 |
− | |We cannot create an instance of '''abstract class.''' | + | |We cannot create an '''instance''' of '''abstract class.''' |
|- | |- | ||
− | | 00 | + | | 00:43 |
| Let us see '''pure virtual function'''. | | Let us see '''pure virtual function'''. | ||
|- | |- | ||
− | | 00 | + | | 00:45 |
|A '''pure virtual function''' is a function with no '''body'''. | |A '''pure virtual function''' is a function with no '''body'''. | ||
|- | |- | ||
− | | 00 | + | | 00:49 |
|It is not defined in the '''base class'''. | |It is not defined in the '''base class'''. | ||
|- | |- | ||
− | | 00 | + | | 00:52 |
|It is declared as: | |It is declared as: | ||
|- | |- | ||
− | | 00 | + | | 00:54 |
|'''virtual void virtualfunname()=0;''' | |'''virtual void virtualfunname()=0;''' | ||
|- | |- | ||
− | | 01 | + | | 01:00 |
|A '''derived class''' must override the '''function'''. | |A '''derived class''' must override the '''function'''. | ||
|- | |- | ||
− | | 01 | + | | 01:04 |
− | |Otherwise the '''compiler''' will give an error. | + | |Otherwise the '''compiler''' will give an '''error'''. |
|- | |- | ||
− | | 01 | + | | 01:07 |
− | |It is | + | |It is up to a '''derived class''' to implement the '''function'''. |
|- | |- | ||
− | | 01 | + | | 01:11 |
− | | Let us look at an example | + | | Let us look at an example. |
|- | |- | ||
− | | 01 | + | | 01:13 |
− | |I have already typed the code on the editor. | + | |I have already typed the '''code''' on the '''editor'''. |
|- | |- | ||
− | | 01 | + | | 01:16 |
|I will open it. | |I will open it. | ||
|- | |- | ||
− | | 01 | + | | 01:18 |
− | |Note that our | + | |Note that our file name is '''abstract.cpp'''. |
|- | |- | ||
− | | 01 | + | | 01:22 |
|This example involves addition and subtraction of two numbers. | |This example involves addition and subtraction of two numbers. | ||
|- | |- | ||
− | | 01 | + | | 01:28 |
| Let us go through the code. | | Let us go through the code. | ||
|- | |- | ||
− | | 01 | + | | 01:30 |
− | | This is our header file as '''iostream.''' | + | | This is our '''header file''' as '''iostream.''' |
|- | |- | ||
− | | 01 | + | | 01:33 |
− | | Here are using '''std namespace.''' | + | | Here we are using the '''std namespace.''' |
|- | |- | ||
− | | 01 | + | | 01:36 |
| This is declaration for a '''class''' named '''abstractinterface.''' | | This is declaration for a '''class''' named '''abstractinterface.''' | ||
|- | |- | ||
− | | 01 | + | | 01:41 |
| Then we have '''public specifier'''. | | Then we have '''public specifier'''. | ||
|- | |- | ||
− | | 01 | + | | 01:44 |
− | | In this we have declared a''' virtual function''' named ''' | + | | In this, we have declared a''' virtual function''' named '''numbers().''' |
|- | |- | ||
− | | 01 | + | | 01:49 |
|It is initialized to '''0.''' | |It is initialized to '''0.''' | ||
|- | |- | ||
− | | 01 | + | | 01:51 |
| Then we have a '''non-virtual function'''. | | Then we have a '''non-virtual function'''. | ||
|- | |- | ||
− | | 01 | + | | 01:55 |
− | |And two '''integer variables''' as | + | |And two '''integer variables''' as 'a' and 'b'. |
|- | |- | ||
− | | 01 | + | | 01:59 |
− | | Here we access the '''input function.''' | + | | Here, we access the '''input function.''' |
|- | |- | ||
− | | 02 | + | | 02:01 |
− | |In this we accept the numbers | + | |In this, we accept the numbers 'a' and 'b'. |
|- | |- | ||
− | | 02 | + | | 02:05 |
| This is a''' derived class''' named''' add.''' | | This is a''' derived class''' named''' add.''' | ||
|- | |- | ||
− | | 02 | + | | 02:09 |
|It inherits the properties of the '''base class "abstractinterface".''' | |It inherits the properties of the '''base class "abstractinterface".''' | ||
|- | |- | ||
− | | 02 | + | | 02:14 |
− | | Here we override | + | | Here we '''override''' the function '''numbers()'''. |
|- | |- | ||
− | | 02 | + | | 02:18 |
− | |In this we perform addition of two numbers | + | |In this, we perform addition of two numbers 'a'and 'b' |
|- | |- | ||
− | | 02 | + | | 02:21 |
− | | | + | |and store the result in '''integer variable "sum".''' |
|- | |- | ||
− | | 02 | + | | 02:25 |
|Then we print the result. | |Then we print the result. | ||
|- | |- | ||
− | | 02 | + | | 02:27 |
| Here we have another '''derived class '''as '''sub.''' | | Here we have another '''derived class '''as '''sub.''' | ||
|- | |- | ||
− | | 02 | + | | 02:31 |
|This also inherits the''' base class "abstractinterface".''' | |This also inherits the''' base class "abstractinterface".''' | ||
|- | |- | ||
− | | 02 | + | | 02:35 |
− | | In this, again | + | | In this, again we override the function '''numbers()'''. |
|- | |- | ||
− | | 02 | + | | 02:39 |
− | |And here we calculate the difference of two numbers | + | |And here we calculate the difference of two numbers 'a' and 'b'. |
|- | |- | ||
− | | 02 | + | | 02:43 |
− | |Then we print the difference. | + | |Then we '''print''' the difference. |
|- | |- | ||
− | | 02 | + | | 02:45 |
− | | This is our '''main | + | | This is our '''main()''' function. |
|- | |- | ||
− | | 02 | + | | 02:48 |
| Here we create an '''object''' of '''class "add"''' as '''obj1.''' | | Here we create an '''object''' of '''class "add"''' as '''obj1.''' | ||
|- | |- | ||
− | | 02 | + | | 02:53 |
− | |Then we call both the ''' | + | |Then we call both the functions '''input() '''and''' numbers() '''using the '''object obj1.''' |
|- | |- | ||
− | | 02 | + | | 02:59 |
| Then we create another '''object''' of '''class "sub"''' as '''obj2.''' | | Then we create another '''object''' of '''class "sub"''' as '''obj2.''' | ||
|- | |- | ||
− | | 03 | + | | 03:04 |
− | |Again, we call the two | + | |Again, we call the two '''functions''' using the '''object obj2.''' |
|- | |- | ||
− | | 03 | + | | 03:08 |
− | | And this is our '''return statement'''. | + | | And this is our''' 'return' statement'''. |
|- | |- | ||
− | | 03 | + | | 03:10 |
− | | Now let us execute the program. | + | | Now let us '''execute''' the program. |
|- | |- | ||
− | | 03 | + | | 03:13 |
− | | 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 | + | | 03:21 |
| To compile, type: | | To compile, type: | ||
− | + | '''g++ space abstract dot cpp space hyphen o space abs''' | |
|- | |- | ||
− | | 03 | + | | 03:31 |
− | |''' | + | |press '''Enter'''.Type: '''dot slash abs''' |
|- | |- | ||
− | | 03 | + | | 03:34 |
− | | | + | |press '''Enter'''. |
− | + | ||
|- | |- | ||
− | | 03 | + | | 03:36 |
− | |''' | + | | It is displayed as '''Enter the numbers'''. |
|- | |- | ||
− | | 03 | + | | 03:38 |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|I will enter as '''9''' and '''4.''' | |I will enter as '''9''' and '''4.''' | ||
|- | |- | ||
− | | 03 | + | | 03:42 |
− | |The output is displayed as '''Sum is 13''' | + | |The '''output''' is displayed as '''Sum is 13'''. |
|- | |- | ||
− | | 03 | + | | 03:46 |
|Again we see '''Enter the numbers'''. | |Again we see '''Enter the numbers'''. | ||
|- | |- | ||
− | | 03 | + | | 03:49 |
|I will enter as '''8''' and '''3'''. | |I will enter as '''8''' and '''3'''. | ||
|- | |- | ||
− | | 03 | + | | 03:52 |
− | |The output is displayed as ''' | + | |The '''output''' is displayed as '''diff is 5'''. |
|- | |- | ||
− | | 03 | + | |03:56 |
− | | This brings us to the end of this tutorial. | + | |This brings us to the end of this tutorial. |
|- | |- | ||
− | | 03 | + | | 03:59 |
− | |Come back to our slides. | + | |Come back to our '''slides'''. |
|- | |- | ||
− | | 04 | + | | 04:01 |
| Let us summarize. | | Let us summarize. | ||
|- | |- | ||
− | | 04 | + | | 04:03 |
− | |In this tutorial we learnt | + | |In this tutorial, we learnt:'''Abstract class''' e.g. '''class abstractinterface'''. |
|- | |- | ||
− | | 04 | + | | 04:09 |
− | |''' | + | |'''Pure virtual function''' e.g. '''virtual void numbers()=0;''' |
|- | |- | ||
− | | 04 | + | | 04:14 |
− | |''' | + | | As an assignment- Create an '''abstract class''' '''student.''' |
|- | |- | ||
− | | 04 | + | | 04:17 |
− | | | + | |Create a '''pure virtual function''' as '''Info'''. |
− | + | ||
|- | |- | ||
− | | 04 | + | | 04:20 |
− | | | + | |Accept the '''name''' and '''roll no''' of the student in the function. |
|- | |- | ||
− | | 04 | + | | 04:25 |
− | | | + | |Create two '''derived class'''es '''marks''' and '''sports'''. |
|- | |- | ||
− | | 04 | + | | 04:29 |
− | | | + | |In marks, accept marks of three subjects. |
|- | |- | ||
− | | 04 | + | | 04:32 |
− | | | + | |In sports, enter marks scored in '''sports.''' |
|- | |- | ||
− | | 04 | + | | 04:35 |
− | | | + | |Calculate the '''total marks.''' |
|- | |- | ||
− | | 04 | + | | 04:38 |
− | | | + | |Then create another '''derived class''' as '''result.''' |
|- | |- | ||
− | | 04 | + | | 04:41 |
− | | | + | |In this, display the''' name, roll-no''' and '''total marks''' of the student. |
|- | |- | ||
− | | 04 | + | | 04:47 |
− | | | + | | Watch the video available at the link shown below. |
|- | |- | ||
− | | 04 | + | | 04:50 |
− | | | + | |It summarizes the Spoken-Tutorial project. |
|- | |- | ||
− | | 04 | + | | 04:53 |
− | | | + | |If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
− | | 04 | + | | 04:58 |
− | | | + | |The Spoken Tutorial Project team: Conducts workshops using spoken tutorials. |
|- | |- | ||
− | | | + | | 05:03 |
− | | | + | |Gives certificates to those who pass an online test. |
|- | |- | ||
− | | 05 | + | | 05:07 |
− | | | + | |For more details, please write to: contact@spoken-tutorial.org |
|- | |- | ||
− | | 05 | + | | 05:14 |
− | | | + | |Spoken-Tutorial Project is a part of the "Talk to a Teacher" project. |
|- | |- | ||
− | | 05 | + | | 05:18 |
− | | | + | |It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
|- | |- | ||
− | | 05 | + | | 05:25 |
− | | | + | |More information on this mission is available at the link shown below: http://spoken-tutorial.org/NMEICT-Intro |
|- | |- | ||
− | | 05 | + | | 05:30 |
− | + | |This is Ashwini Patil from IIT Bombay, signing off.Thank You for watching. | |
− | + | ||
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
− | Thank You for watching. | + | |
|} | |} |
Latest revision as of 15:04, 23 March 2017
Time | Narration |
00:01 | Welcome to the spoken-tutorial on abstract class and pure virtual function in C++. |
00:08 | In this tutorial, we will learn: |
00:10 | Abstract Classes, Pure virtual function. |
00:13 | We will do this through an example. |
00:16 | To record this tutorial, I am using: |
00:19 | Ubuntu OS version 11.10 |
00:23 | g++ compiler version 4.6.1 |
00:27 | Let us start with an introduction to abstract class. |
00:31 | Abstract class is always a base class. |
00:35 | It contains at least one pure virtual function. |
00:39 | We cannot create an instance of abstract class. |
00:43 | Let us see pure virtual function. |
00:45 | A pure virtual function is a function with no body. |
00:49 | It is not defined in the base class. |
00:52 | It is declared as: |
00:54 | virtual void virtualfunname()=0; |
01:00 | A derived class must override the function. |
01:04 | Otherwise the compiler will give an error. |
01:07 | It is up to a derived class to implement the function. |
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 | Note that our file name is abstract.cpp. |
01:22 | This example involves addition and subtraction of two numbers. |
01:28 | Let us go through the code. |
01:30 | This is our header file as iostream. |
01:33 | Here we are using the std namespace. |
01:36 | This is declaration for a class named abstractinterface. |
01:41 | Then we have public specifier. |
01:44 | In this, we have declared a virtual function named numbers(). |
01:49 | It is initialized to 0. |
01:51 | Then we have a non-virtual function. |
01:55 | And two integer variables as 'a' and 'b'. |
01:59 | Here, we access the input function. |
02:01 | In this, we accept the numbers 'a' and 'b'. |
02:05 | This is a derived class named add. |
02:09 | It inherits the properties of the base class "abstractinterface". |
02:14 | Here we override the function numbers(). |
02:18 | In this, we perform addition of two numbers 'a'and 'b' |
02:21 | and store the result in integer variable "sum". |
02:25 | Then we print the result. |
02:27 | Here we have another derived class as sub. |
02:31 | This also inherits the base class "abstractinterface". |
02:35 | In this, again we override the function numbers(). |
02:39 | And here we calculate the difference of two numbers 'a' and 'b'. |
02:43 | Then we print the difference. |
02:45 | This is our main() function. |
02:48 | Here we create an object of class "add" as obj1. |
02:53 | Then we call both the functions input() and numbers() using the object obj1. |
02:59 | Then we create another object of class "sub" as obj2. |
03:04 | Again, we call the two functions using the object obj2. |
03:08 | And this is our 'return' statement. |
03:10 | Now let us execute the program. |
03:13 | Open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard. |
03:21 | To compile, type:
g++ space abstract dot cpp space hyphen o space abs |
03:31 | press Enter.Type: dot slash abs |
03:34 | press Enter. |
03:36 | It is displayed as Enter the numbers. |
03:38 | I will enter as 9 and 4. |
03:42 | The output is displayed as Sum is 13. |
03:46 | Again we see Enter the numbers. |
03:49 | I will enter as 8 and 3. |
03:52 | The output is displayed as diff is 5. |
03:56 | This brings us to the end of this tutorial. |
03:59 | Come back to our slides. |
04:01 | Let us summarize. |
04:03 | In this tutorial, we learnt:Abstract class e.g. class abstractinterface. |
04:09 | Pure virtual function e.g. virtual void numbers()=0; |
04:14 | As an assignment- Create an abstract class student. |
04:17 | Create a pure virtual function as Info. |
04:20 | Accept the name and roll no of the student in the function. |
04:25 | Create two derived classes marks and sports. |
04:29 | In marks, accept marks of three subjects. |
04:32 | In sports, enter marks scored in sports. |
04:35 | Calculate the total marks. |
04:38 | Then create another derived class as result. |
04:41 | In this, display the name, roll-no and total marks of the student. |
04:47 | Watch the video available at the link shown below. |
04:50 | It summarizes the Spoken-Tutorial project. |
04:53 | If you do not have good bandwidth, you can download and watch it. |
04:58 | The Spoken Tutorial Project team: Conducts workshops using spoken tutorials. |
05:03 | Gives certificates to those who pass an online test. |
05:07 | For more details, please write to: contact@spoken-tutorial.org |
05:14 | Spoken-Tutorial Project is a part of the "Talk to a Teacher" project. |
05:18 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
05:25 | More information on this mission is available at the link shown below: http://spoken-tutorial.org/NMEICT-Intro |
05:30 | This is Ashwini Patil from IIT Bombay, signing off.Thank You for watching. |