Difference between revisions of "C-and-C++/C2/Arithmetic-Operators/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
 
{| border=1
 
{| border=1
|| ''Time'''
+
|| Time
|| '''Narration'''
+
|| Narration
  
  
 
|-
 
|-
|00.01
+
|00:01
 
| Welcome to the spoken tutorial on '''Arithmetic Operators in C ''''''C++'''.
 
| Welcome to the spoken tutorial on '''Arithmetic Operators in C ''''''C++'''.
  
 
|-
 
|-
| 00.07
+
| 00:07
 
| In this tutorial, we will learn about  
 
| In this tutorial, we will learn about  
  
 
|-
 
|-
| 00.10
+
| 00:10
 
|Arithmetic operators like
 
|Arithmetic operators like
  
  
 
|-
 
|-
| 00.11
+
| 00:11
 
| + Addition: eg. a+b.
 
| + Addition: eg. a+b.
  
 
|-
 
|-
| 00.14
+
| 00:14
 
| - Subtraction: eg. a-b.
 
| - Subtraction: eg. a-b.
  
 
|-
 
|-
| 00.18
+
| 00:18
 
|/ Division: eg. a/b.
 
|/ Division: eg. a/b.
  
 
|-
 
|-
| 00.20
+
| 00:20
 
| *  Multiplication: eg. a*b.
 
| *  Multiplication: eg. a*b.
  
 
  |-
 
  |-
| 00.24
+
| 00:24
 
| % Modulus: eg. a%b.
 
| % Modulus: eg. a%b.
  
 
|-
 
|-
|  00.27
+
|  00:27
 
| To record this tutorial, I am using:'''Ubuntu 11.10''' as the operating system   
 
| To record this tutorial, I am using:'''Ubuntu 11.10''' as the operating system   
  
 
|-
 
|-
| 00.32
+
| 00:32
 
|'''gcc''' and '''g++ Compiler version 4.6.1 in Ubuntu'''.
 
|'''gcc''' and '''g++ Compiler version 4.6.1 in Ubuntu'''.
  
 
|-
 
|-
|00.38
+
|00:38
 
| I will now demonstrate the use of these arithmetic operations with the help of a '''C''' program.
 
| I will now demonstrate the use of these arithmetic operations with the help of a '''C''' program.
  
 
|-
 
|-
|  00.44
+
|  00:44
 
|  I have already written the program.
 
|  I have already written the program.
  
 
|-
 
|-
| 00.47
+
| 00:47
 
|So I will open the editor and explain the code.
 
|So I will open the editor and explain the code.
  
 
|-
 
|-
|  00.49
+
|  00:49
 
|  Here is the C program for arithmetic operators.
 
|  Here is the C program for arithmetic operators.
  
 
|-
 
|-
| 00.56
+
| 00:56
 
| the first two statements the variables are declared and defined.
 
| the first two statements the variables are declared and defined.
  
 
|-
 
|-
| 01.02
+
| 01:02
 
|In the next two statements,
 
|In the next two statements,
  
 
|-
 
|-
| 01.04
+
| 01:04
 
|'''a''' is assigned the value of 5.
 
|'''a''' is assigned the value of 5.
  
 
|-
 
|-
| 01.06
+
| 01:06
 
|'''b''' is assigned the value of 2.
 
|'''b''' is assigned the value of 2.
  
 
|-
 
|-
|  01.10
+
|  01:10
 
|  Now let's see how the addition operator works.
 
|  Now let's see how the addition operator works.
  
 
|-
 
|-
| 01.14
+
| 01:14
 
|'''c''' holds the sum of '''a''' and '''b'''.
 
|'''c''' holds the sum of '''a''' and '''b'''.
  
 
|-
 
|-
|  01.19
+
|  01:19
 
|  This '''printf''' statement displays the sum of a and b on the screen.
 
|  This '''printf''' statement displays the sum of a and b on the screen.
  
 
|-
 
|-
| 01.28
+
| 01:28
 
|Here % dot 2f provides the precision of two digits after the decimal point.
 
|Here % dot 2f provides the precision of two digits after the decimal point.
  
 
|-
 
|-
| 01.37
+
| 01:37
 
|  In the next statement, '''c''' holds the product of '''a''' and '''b'''.
 
|  In the next statement, '''c''' holds the product of '''a''' and '''b'''.
  
 
|-
 
|-
|  01.43
+
|  01:43
 
|  This '''printf''' statement displays the product of a and b on the screen.
 
|  This '''printf''' statement displays the product of a and b on the screen.
  
 
|-
 
|-
| 01.48
+
| 01:48
 
|Let's see how these two operators work.
 
|Let's see how these two operators work.
  
 
|-
 
|-
|  01.52
+
|  01:52
 
|  We will comment out the following lines
 
|  We will comment out the following lines
  
 
|-
 
|-
| 01.55
+
| 01:55
 
|Type  '''/*'''
 
|Type  '''/*'''
  
 
|-
 
|-
| 02.01
+
| 02:01
 
| '' */ ''
 
| '' */ ''
  
 
|-
 
|-
| 02.05
+
| 02:05
 
|  Click on '''Save''  
 
|  Click on '''Save''  
  
 
|-
 
|-
| 02.07
+
| 02:07
 
|Save the file with extension '''.c'''
 
|Save the file with extension '''.c'''
  
 
|-
 
|-
| 02.10
+
| 02:10
 
|I have saved my file as''' arithmetic.c'''
 
|I have saved my file as''' arithmetic.c'''
  
 
|-
 
|-
|  02.15
+
|  02:15
 
|  Open the terminal window by pressing '''Ctrl, Alt and T '''keys''' '''simultaneously.
 
|  Open the terminal window by pressing '''Ctrl, Alt and T '''keys''' '''simultaneously.
  
 
|-
 
|-
| 02.22
+
| 02:22
 
| To compile the code, type the following on the terminal.
 
| To compile the code, type the following on the terminal.
  
 
|-
 
|-
| 02.27
+
| 02:27
 
|'''gcc space arithmetic dot c space minus o space arith'''
 
|'''gcc space arithmetic dot c space minus o space arith'''
  
 
|-
 
|-
| 02.38
+
| 02:38
 
|'''Press Enter'''
 
|'''Press Enter'''
  
 
|-
 
|-
| 02.40
+
| 02:40
 
|To execute the code, type '''./arith'''
 
|To execute the code, type '''./arith'''
  
 
|-
 
|-
|  02.48
+
|  02:48
 
|  press '''Enter'''
 
|  press '''Enter'''
  
 
|-
 
|-
0250
+
02:50
 
|  The output is displayed on the screen.
 
|  The output is displayed on the screen.
  
 
|-
 
|-
| 02.53
+
| 02:53
 
|It shows,
 
|It shows,
  
 
|-
 
|-
| 02.54
+
| 02:54
 
|Sum of 5 and 2 is 7.00 and  
 
|Sum of 5 and 2 is 7.00 and  
  
 
|-
 
|-
| 02.59
+
| 02:59
 
|Product of 5and 2 is 10.00
 
|Product of 5and 2 is 10.00
  
 
|-
 
|-
|  03.03
+
|  03:03
 
|  Now you should try the subtraction operator on your own  
 
|  Now you should try the subtraction operator on your own  
  
 
|-
 
|-
| 03.08
+
| 03:08
 
|Try replacing the addition operator with subtraction operator.  
 
|Try replacing the addition operator with subtraction operator.  
  
 
|-
 
|-
| 03.13
+
| 03:13
 
|You should get the result as 3.
 
|You should get the result as 3.
  
 
|-
 
|-
|  03.18
+
|  03:18
 
|  Coming back to the program and the last set of statements.
 
|  Coming back to the program and the last set of statements.
  
 
|-
 
|-
| 03.23
+
| 03:23
 
|Now, I will explain the code for division.
 
|Now, I will explain the code for division.
  
 
|-
 
|-
| 03.26
+
| 03:26
 
|Remove the multi line comments  here and here.
 
|Remove the multi line comments  here and here.
  
 
|-
 
|-
|  03.34
+
|  03:34
 
|  In these statements, '''c''' holds the value of integer division of '''a''' by '''b'''.
 
|  In these statements, '''c''' holds the value of integer division of '''a''' by '''b'''.
  
 
|-
 
|-
| 03.40
+
| 03:40
 
|Please note that in integer division the fractional part is truncated.
 
|Please note that in integer division the fractional part is truncated.
  
 
|-
 
|-
|  03.47
+
|  03:47
 
| The '''printf '''statement displays the division output on the screen.
 
| The '''printf '''statement displays the division output on the screen.
  
 
|-
 
|-
|  03.57
+
|  03:57
 
|  In this statement we are performing real division.
 
|  In this statement we are performing real division.
  
 
|-
 
|-
| 04.02
+
| 04:02
 
|Here one of the operands has to be cast as '''float'''
 
|Here one of the operands has to be cast as '''float'''
 
|  
 
|  
 
|-
 
|-
|04.10  
+
|04:10  
 
| We have type-cast variable a.
 
| We have type-cast variable a.
 
|-
 
|-
| 04.13
+
| 04:13
 
|Now a will behave as a float variable for a single operation.
 
|Now a will behave as a float variable for a single operation.
  
Line 223: Line 223:
  
 
|-
 
|-
| 04.22
+
| 04:22
 
|The printf statement displays the output of real division on the screen.
 
|The printf statement displays the output of real division on the screen.
  
  
 
|-
 
|-
|04.30
+
|04:30
 
| Type '''return 0''' and close the ending curly bracket.
 
| Type '''return 0''' and close the ending curly bracket.
  
 
|-
 
|-
|  04.37
+
|  04:37
 
|  Click on '''Save.'''
 
|  Click on '''Save.'''
  
 
|-
 
|-
|   04.40
+
| 04:40
| Coming back to the terminal to compile and execute the code.
+
| Coming back to the terminal to compile and execute the code.
  
 
|-
 
|-
| 04.45
+
| 04:45
 
| | To compile, type'''gcc space arithmetic dot c minus o space arith'''. Press Enter
 
| | To compile, type'''gcc space arithmetic dot c minus o space arith'''. Press Enter
  
 
|-
 
|-
| 04.59
+
| 04:59
 
|To execute the code, type '''./arith'''Press Enter
 
|To execute the code, type '''./arith'''Press Enter
  
  
 
|-
 
|-
|  05.05
+
|  05:05
 
| The output is displayed on the screen:
 
| The output is displayed on the screen:
  
 
|-
 
|-
| 05.08
+
| 05:08
 
|We have the previous outputs of addition and multiplication operators.
 
|We have the previous outputs of addition and multiplication operators.
 
|-
 
|-
|  05.16
+
|  05:16
 
|we have the integer Division of 5 by 2 is 2.  
 
|we have the integer Division of 5 by 2 is 2.  
  
  
 
|-
 
|-
|05.22
+
|05:22
 
|We can see  that  in integer division the fractional part is truncated.
 
|We can see  that  in integer division the fractional part is truncated.
  
  
 
|-
 
|-
| 05.29
+
| 05:29
 
|then we have  the real division of 5 by 2 is 2.5.
 
|then we have  the real division of 5 by 2 is 2.5.
  
 
|-
 
|-
| 05.35
+
| 05:35
 
|In real division the result is as expected.  
 
|In real division the result is as expected.  
  
 
|-
 
|-
| 05.37
+
| 05:37
 
|We  used type-casting to obtain these result.
 
|We  used type-casting to obtain these result.
  
 
|-
 
|-
| 05.45
+
| 05:45
 
|  Now suppose, I want to write the same program in C++.
 
|  Now suppose, I want to write the same program in C++.
  
 
|-
 
|-
| 05.50
+
| 05:50
 
|Let see  if i can use the same code in C++, too?  
 
|Let see  if i can use the same code in C++, too?  
  
 
|-
 
|-
| 05.54
+
| 05:54
 
|  Let's find out.
 
|  Let's find out.
  
 
|-
 
|-
| 05.56
+
| 05:56
 
|Let me go back to the editor.  
 
|Let me go back to the editor.  
  
 
|-
 
|-
| 06.00  
+
| 06:00  
 
|  Here is a C++  code.
 
|  Here is a C++  code.
  
 
|-
 
|-
|  06.05
+
|  06:05
 
|  Notice that the header is different from the C file header.
 
|  Notice that the header is different from the C file header.
  
 
|-
 
|-
| 06.12
+
| 06:12
 
|'''namespace''' is also used here.
 
|'''namespace''' is also used here.
  
 
|-
 
|-
|  06.18
+
|  06:18
 
|  Also, notice that the output statement in C++ is '''cout'''.
 
|  Also, notice that the output statement in C++ is '''cout'''.
  
 
|-
 
|-
|  06.25
+
|  06:25
 
|  So, apart from these differences, the two codes are very similar.
 
|  So, apart from these differences, the two codes are very similar.
  
 
|-
 
|-
|  06.32   
+
|  06:32   
 
| Click on '''Save'''.
 
| Click on '''Save'''.
  
 
|-
 
|-
| 06.33
+
| 06:33
 
|Make sure the file is saved with the extension '''.cpp'''
 
|Make sure the file is saved with the extension '''.cpp'''
  
 
|-
 
|-
| 06.37
+
| 06:37
 
|I have saved my file as''' arithmetic.cpp'''
 
|I have saved my file as''' arithmetic.cpp'''
  
 
|-
 
|-
| 06.41
+
| 06:41
 
| Let's execute the code and see what results we get.
 
| Let's execute the code and see what results we get.
  
 
|-
 
|-
| 06.49
+
| 06:49
 
|Open the terminal and type  '''g++ space arithmetic dot cpp space  minus o arith'' .'''Press Enter'''
 
|Open the terminal and type  '''g++ space arithmetic dot cpp space  minus o arith'' .'''Press Enter'''
  
 
|-
 
|-
| 07.09
+
| 07:09
 
| To  execute the  code Type  '''./ arith'''Press Enter'''
 
| To  execute the  code Type  '''./ arith'''Press Enter'''
  
Line 340: Line 340:
  
 
|-
 
|-
| 07.16
+
| 07:16
 
| Here the output is displayed:  
 
| Here the output is displayed:  
 
   
 
   
 
|-
 
|-
| 07.19
+
| 07:19
 
|So, we see that  the results are similar to the C program.
 
|So, we see that  the results are similar to the C program.
  
 
|-
 
|-
| 07.23
+
| 07:23
 
|The only difference is in the precisions of outputs.
 
|The only difference is in the precisions of outputs.
  
 
|-
 
|-
|  07.29
+
|  07:29
 
|  Let us now summarize the tutorial.  
 
|  Let us now summarize the tutorial.  
  
 
|-
 
|-
| 07.32
+
| 07:32
 
|In this tutorial we learnt how to use the arithmetic operators.
 
|In this tutorial we learnt how to use the arithmetic operators.
  
 
|-
 
|-
|  07.36
+
|  07:36
 
|  As an assignment:
 
|  As an assignment:
  
 
|-
 
|-
| 07.38
+
| 07:38
 
|Write a program to demonstrate the use of modulus operator.
 
|Write a program to demonstrate the use of modulus operator.
  
 
|-
 
|-
| 07.42
+
| 07:42
 
|Please note that Modulus operator finds the remainder of division.  eg. c = a % b;
 
|Please note that Modulus operator finds the remainder of division.  eg. c = a % b;
  
 
|-
 
|-
| 07.50
+
| 07:50
 
|You should obtain the result as 1.
 
|You should obtain the result as 1.
  
 
|-
 
|-
| 07.55
+
| 07:55
 
|  Watch the video available at the following link  
 
|  Watch the video available at the following link  
  
 
|-
 
|-
| 07.57
+
| 07:57
 
|It summarises the Spoken Tutorial project  
 
|It summarises the Spoken Tutorial project  
  
 
|-
 
|-
| 08.00
+
| 08:00
 
|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  
  
Line 390: Line 390:
  
 
|-
 
|-
| 08.05   
+
| 08:05   
 
| The Spoken Tutorial Project Team . Conducts workshops using spoken tutorials  
 
| The Spoken Tutorial Project Team . Conducts workshops using spoken tutorials  
  
 
|-
 
|-
| 08.09
+
| 08:09
 
| Gives certificates for those who pass an online test  
 
| Gives certificates for those who pass an online test  
  
 
|-
 
|-
| 08.14
+
| 08:14
 
| For more details, please write to contact at spoken hyphen tutorial dot org  
 
| For more details, please write to contact at spoken hyphen tutorial dot org  
  
  
 
|-
 
|-
|  08.20
+
|  08:20
 
| 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  
 
|-
 
|-
| 08.25
+
| 08:25
 
| 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
  
 
  |-
 
  |-
| 08.30
+
| 08:30
 
| More information on this Mission is available at  
 
| More information on this Mission is available at  
  
 
|-
 
|-
| 08.33
+
| 08:33
 
| spoken hyphen tutorial dot org slash NMEICT hyphen Intro  
 
| spoken hyphen tutorial dot org slash NMEICT hyphen Intro  
  
Line 420: Line 420:
  
 
|-
 
|-
|  08.41
+
|  08:41
 
|  This is Ritwik Joshi from IIT Bombay.  
 
|  This is Ritwik Joshi from IIT Bombay.  
  

Revision as of 12:29, 23 June 2014

Time Narration


00:01 Welcome to the spoken tutorial on Arithmetic Operators in C 'C++'.
00:07 In this tutorial, we will learn about
00:10 Arithmetic operators like


00:11 + Addition: eg. a+b.
00:14 - Subtraction: eg. a-b.
00:18 / Division: eg. a/b.
00:20 * Multiplication: eg. a*b.
00:24  % Modulus: eg. a%b.
00:27 To record this tutorial, I am using:Ubuntu 11.10 as the operating system
00:32 gcc and g++ Compiler version 4.6.1 in Ubuntu.
00:38 I will now demonstrate the use of these arithmetic operations with the help of a C program.
00:44 I have already written the program.
00:47 So I will open the editor and explain the code.
00:49 Here is the C program for arithmetic operators.
00:56 the first two statements the variables are declared and defined.
01:02 In the next two statements,
01:04 a is assigned the value of 5.
01:06 b is assigned the value of 2.
01:10 Now let's see how the addition operator works.
01:14 c holds the sum of a and b.
01:19 This printf statement displays the sum of a and b on the screen.
01:28 Here % dot 2f provides the precision of two digits after the decimal point.
01:37 In the next statement, c holds the product of a and b.
01:43 This printf statement displays the product of a and b on the screen.
01:48 Let's see how these two operators work.
01:52 We will comment out the following lines
01:55 Type /*
02:01 */
02:05 Click on 'Save
02:07 Save the file with extension .c
02:10 I have saved my file as arithmetic.c
02:15 Open the terminal window by pressing Ctrl, Alt and T keys simultaneously.
02:22 To compile the code, type the following on the terminal.
02:27 gcc space arithmetic dot c space minus o space arith
02:38 Press Enter
02:40 To execute the code, type ./arith
02:48 press Enter
02:50 The output is displayed on the screen.
02:53 It shows,
02:54 Sum of 5 and 2 is 7.00 and
02:59 Product of 5and 2 is 10.00
03:03 Now you should try the subtraction operator on your own
03:08 Try replacing the addition operator with subtraction operator.
03:13 You should get the result as 3.
03:18 Coming back to the program and the last set of statements.
03:23 Now, I will explain the code for division.
03:26 Remove the multi line comments here and here.
03:34 In these statements, c holds the value of integer division of a by b.
03:40 Please note that in integer division the fractional part is truncated.
03:47 The printf statement displays the division output on the screen.
03:57 In this statement we are performing real division.
04:02 Here one of the operands has to be cast as float
04:10 We have type-cast variable a.
04:13 Now a will behave as a float variable for a single operation.


04:22 The printf statement displays the output of real division on the screen.


04:30 Type return 0 and close the ending curly bracket.
04:37 Click on Save.
04:40 Coming back to the terminal to compile and execute the code.
04:45 To compile, typegcc space arithmetic dot c minus o space arith. Press Enter
04:59 To execute the code, type ./arithPress Enter


05:05 The output is displayed on the screen:
05:08 We have the previous outputs of addition and multiplication operators.
05:16 we have the integer Division of 5 by 2 is 2.


05:22 We can see that in integer division the fractional part is truncated.


05:29 then we have the real division of 5 by 2 is 2.5.
05:35 In real division the result is as expected.
05:37 We used type-casting to obtain these result.
05:45 Now suppose, I want to write the same program in C++.
05:50 Let see if i can use the same code in C++, too?
05:54 Let's find out.
05:56 Let me go back to the editor.
06:00 Here is a C++ code.
06:05 Notice that the header is different from the C file header.
06:12 namespace is also used here.
06:18 Also, notice that the output statement in C++ is cout.
06:25 So, apart from these differences, the two codes are very similar.
06:32 Click on Save.
06:33 Make sure the file is saved with the extension .cpp
06:37 I have saved my file as arithmetic.cpp
06:41 Let's execute the code and see what results we get.
06:49 Open the terminal and type g++ space arithmetic dot cpp space minus o arith .'Press Enter
07:09 To execute the code Type ./ arithPress Enter


07:16 Here the output is displayed:
07:19 So, we see that the results are similar to the C program.
07:23 The only difference is in the precisions of outputs.
07:29 Let us now summarize the tutorial.
07:32 In this tutorial we learnt how to use the arithmetic operators.
07:36 As an assignment:
07:38 Write a program to demonstrate the use of modulus operator.
07:42 Please note that Modulus operator finds the remainder of division. eg. c = a % b;
07:50 You should obtain the result as 1.
07:55 Watch the video available at the following link
07:57 It summarises the Spoken Tutorial project
08:00 If you do not have good bandwidth, you can download and watch it


08:05 The Spoken Tutorial Project Team . Conducts workshops using spoken tutorials
08:09 Gives certificates for those who pass an online test
08:14 For more details, please write to contact at spoken hyphen tutorial dot org


08:20 Spoken Tutorial Project is a part of the Talk to a Teacher project
08:25 It is supported by the National Mission on Education through ICT, MHRD, Government of India
08:30 More information on this Mission is available at
08:33 spoken hyphen tutorial dot org slash NMEICT hyphen Intro


08:41 This is Ritwik Joshi from IIT Bombay.

Thank you for joining.

Contributors and Content Editors

Ashwini, Krupali, PoojaMoolya, Pratik kamble, Sandhya.np14