Difference between revisions of "Advanced-C++/C2/Abstract-Class/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
|||
(4 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 '''abstract class''' and '''pure virtual function''' in '''C++.''' | + | | Welcome to the '''spoken-tutorial''' on '''abstract class''' and '''pure virtual function''' in '''C++.''' |
|- | |- | ||
| 00:08 | | 00:08 | ||
− | |In this tutorial we will learn | + | |In this tutorial, we will learn: |
|- | |- | ||
| 00:10 | | 00:10 | ||
− | | | + | | Abstract Classes, Pure virtual function. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 00:13 | | 00:13 | ||
− | | | + | |We will do this through an example. |
|- | |- | ||
| 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''' |
|- | |- | ||
| 00:23 | | 00:23 | ||
− | | | + | |'''g++ compiler '''version '''4.6.1''' |
|- | |- | ||
Line 51: | Line 45: | ||
|- | |- | ||
| 00:39 | | 00:39 | ||
− | |We cannot create an instance of '''abstract class.''' | + | |We cannot create an '''instance''' of '''abstract class.''' |
|- | |- | ||
Line 79: | Line 73: | ||
|- | |- | ||
| 01:04 | | 01:04 | ||
− | |Otherwise the '''compiler''' will give an error. | + | |Otherwise the '''compiler''' will give an '''error'''. |
|- | |- | ||
| 01:07 | | 01:07 | ||
− | |It is | + | |It is up to a '''derived class''' to implement the '''function'''. |
|- | |- | ||
| 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 99: | Line 93: | ||
|- | |- | ||
| 01:18 | | 01:18 | ||
− | |Note that our | + | |Note that our file name is '''abstract.cpp'''. |
|- | |- | ||
Line 111: | Line 105: | ||
|- | |- | ||
| 01:30 | | 01:30 | ||
− | | This is our header file as '''iostream.''' | + | | This is our '''header file''' as '''iostream.''' |
|- | |- | ||
| 01:33 | | 01:33 | ||
− | | Here we are using '''std namespace.''' | + | | Here we are using the '''std namespace.''' |
|- | |- | ||
Line 127: | Line 121: | ||
|- | |- | ||
| 01:44 | | 01:44 | ||
− | | In this we have declared a''' virtual function''' named ''' | + | | In this, we have declared a''' virtual function''' named '''numbers().''' |
|- | |- | ||
Line 139: | Line 133: | ||
|- | |- | ||
| 01:55 | | 01:55 | ||
− | |And two '''integer variables''' as | + | |And two '''integer variables''' as 'a' and 'b'. |
|- | |- | ||
| 01:59 | | 01:59 | ||
− | | Here we access the '''input function.''' | + | | Here, we access the '''input function.''' |
|- | |- | ||
| 02:01 | | 02:01 | ||
− | |In this we accept the numbers | + | |In this, we accept the numbers 'a' and 'b'. |
|- | |- | ||
Line 159: | Line 153: | ||
|- | |- | ||
| 02:14 | | 02:14 | ||
− | | Here we override | + | | Here we '''override''' the function '''numbers()'''. |
|- | |- | ||
| 02:18 | | 02:18 | ||
− | |In this we perform addition of two numbers | + | |In this, we perform addition of two numbers 'a'and 'b' |
|- | |- | ||
| 02:21 | | 02:21 | ||
− | | | + | |and store the result in '''integer variable "sum".''' |
|- | |- | ||
Line 183: | Line 177: | ||
|- | |- | ||
| 02:35 | | 02:35 | ||
− | | In this, again | + | | In this, again we override the function '''numbers()'''. |
|- | |- | ||
| 02:39 | | 02:39 | ||
− | |And here we calculate the difference of two numbers | + | |And here we calculate the difference of two numbers 'a' and 'b'. |
|- | |- | ||
| 02:43 | | 02:43 | ||
− | |Then we print the difference. | + | |Then we '''print''' the difference. |
|- | |- | ||
| 02:45 | | 02:45 | ||
− | | This is our '''main | + | | This is our '''main()''' function. |
|- | |- | ||
Line 203: | Line 197: | ||
|- | |- | ||
| 02:53 | | 02:53 | ||
− | |Then we call both the ''' | + | |Then we call both the functions '''input() '''and''' numbers() '''using the '''object obj1.''' |
|- | |- | ||
Line 215: | Line 209: | ||
|- | |- | ||
| 03:08 | | 03:08 | ||
− | | And this is our '''return statement'''. | + | | And this is our''' 'return' statement'''. |
|- | |- | ||
| 03:10 | | 03:10 | ||
− | | Now let us execute the program. | + | | Now let us '''execute''' the program. |
|- | |- | ||
| 03:13 | | 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:21 | | 03:21 | ||
| To compile, type: | | To compile, type: | ||
− | + | '''g++ space abstract dot cpp space hyphen o space abs''' | |
|- | |- | ||
| 03:31 | | 03:31 | ||
− | |''' | + | |press '''Enter'''.Type: '''dot slash abs''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 03:34 | | 03:34 | ||
− | |''' | + | |press '''Enter'''. |
|- | |- | ||
| 03:36 | | 03:36 | ||
− | | It is displayed as '''Enter the numbers''' | + | | It is displayed as '''Enter the numbers'''. |
|- | |- | ||
Line 253: | Line 242: | ||
|- | |- | ||
| 03:42 | | 03:42 | ||
− | |The output is displayed as '''Sum is 13''' | + | |The '''output''' is displayed as '''Sum is 13'''. |
|- | |- | ||
Line 265: | Line 254: | ||
|- | |- | ||
| 03:52 | | 03:52 | ||
− | |The output is displayed as ''' | + | |The '''output''' is displayed as '''diff is 5'''. |
|- | |- | ||
− | | 03:56 | + | |03:56 |
− | | This brings us to the end of this tutorial. | + | |This brings us to the end of this tutorial. |
|- | |- | ||
| 03:59 | | 03:59 | ||
− | |Come back to our slides. | + | |Come back to our '''slides'''. |
|- | |- | ||
Line 281: | Line 270: | ||
|- | |- | ||
| 04:03 | | 04:03 | ||
− | |In this tutorial we learnt | + | |In this tutorial, we learnt:'''Abstract class''' e.g. '''class abstractinterface'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 04:09 | | 04:09 | ||
− | |'''Pure virtual function''' ''' | + | |'''Pure virtual function''' e.g. '''virtual void numbers()=0;''' |
|- | |- | ||
| 04:14 | | 04:14 | ||
− | | As an assignment | + | | As an assignment- Create an '''abstract class''' '''student.''' |
− | + | ||
|- | |- | ||
| 04:17 | | 04:17 | ||
− | | | + | |Create a '''pure virtual function''' as '''Info'''. |
|- | |- | ||
| 04:20 | | 04:20 | ||
− | | | + | |Accept the '''name''' and '''roll no''' of the student in the function. |
|- | |- | ||
| 04:25 | | 04:25 | ||
− | | | + | |Create two '''derived class'''es '''marks''' and '''sports'''. |
|- | |- | ||
| 04:29 | | 04:29 | ||
− | | | + | |In marks, accept marks of three subjects. |
|- | |- | ||
| 04:32 | | 04:32 | ||
− | | | + | |In sports, enter marks scored in '''sports.''' |
|- | |- | ||
| 04:35 | | 04:35 | ||
− | | | + | |Calculate the '''total marks.''' |
|- | |- | ||
| 04:38 | | 04:38 | ||
− | | | + | |Then create another '''derived class''' as '''result.''' |
|- | |- | ||
| 04:41 | | 04:41 | ||
− | | | + | |In this, display the''' name, roll-no''' and '''total marks''' of the student. |
|- | |- | ||
| 04:47 | | 04:47 | ||
− | | Watch the video available at the link shown below | + | | Watch the video available at the link shown below. |
|- | |- | ||
| 04:50 | | 04:50 | ||
− | |It summarizes the Spoken Tutorial project | + | |It summarizes the Spoken-Tutorial project. |
|- | |- | ||
| 04:53 | | 04:53 | ||
− | |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:58 | | 04:58 | ||
− | | | + | |The Spoken Tutorial Project team: Conducts workshops using spoken tutorials. |
|- | |- | ||
| 05:03 | | 05:03 | ||
− | |Gives certificates to those who pass an online test | + | |Gives certificates to those who pass an online test. |
|- | |- | ||
| 05:07 | | 05:07 | ||
− | |For more details, please write to | + | |For more details, please write to: contact@spoken-tutorial.org |
|- | |- | ||
| 05:14 | | 05:14 | ||
− | | | + | |Spoken-Tutorial Project is a part of the "Talk to a Teacher" project. |
|- | |- | ||
| 05:18 | | 05:18 | ||
− | |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. |
|- | |- | ||
| 05:25 | | 05:25 | ||
− | |More information on this | + | |More information on this mission is available at the link shown below: http://spoken-tutorial.org/NMEICT-Intro |
|- | |- | ||
| 05:30 | | 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. |