Difference between revisions of "C-and-C++/C2/Nested-If-And-Switch-Statement/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(14 intermediate revisions by 5 users not shown)
Line 4: Line 4:
 
|-
 
|-
 
|  00:01
 
|  00:01
|  Welcome to the spoken tutorial on Nested if & Switch statements in C and C++.
+
|  Welcome to the spoken tutorial on '''Nested if''' and '''Switch statements in C and C++'''.
  
 
|-
 
|-
 
| 00:07
 
| 00:07
|  In this tutorial we will learn ,  
+
|  In this tutorial we will learn,  
  
 
|-
 
|-
 
|  00:09
 
|  00:09
| How to use nested if statement. And
+
| how to use '''nested if''' statement and
  
 
|-
 
|-
 
|  00:12
 
|  00:12
| switch statement.
+
| '''switch''' statement.We will do this with the help of some examples.
 
+
|-
+
|  00:13
+
| We will do this with the help of some examples.
+
  
 
|-
 
|-
 
|  00:17
 
|  00:17
|  To record this tutorial, I am using,
+
|  To record this tutorial, I am using
  
 
|-
 
|-
 
|  00:20
 
|  00:20
| Ubuntu operating system version 11.10
+
| '''Ubuntu operating system version 11.10''',
  
 
|-
 
|-
 
|  00:24
 
|  00:24
| gcc and g++ Compiler version 4.6.1 on Ubuntu.
+
| '''gcc and g++ Compiler version 4.6.1 on Ubuntu'''.
  
 
|-
 
|-
 
| 00:30
 
| 00:30
|   First we will learn, how to write '''nested if and switch statement''' with an example.
+
| First we will learn how to write '''nested if''' and '''switch''' statements with an example.
  
 
|-
 
|-
 
|  00:36
 
|  00:36
| I have already written the program  
+
| I have already written the program.
  
 
|-
 
|-
 
| 00:39
 
| 00:39
|  Let’s have a look  
+
|  Let’s have a look. In this program we will learn to check the range of integers.
|-
+
 
|  00:40
+
In this program ,we will learn to check the range of integers.
+
 
|-
 
|-
 
|  00:45
 
|  00:45
|  Note that our file name is '''nested-if.c'''
+
|  Note that our file name is '''nested-if.c'''.
  
 
|-
 
|-
Line 59: Line 53:
 
|  00:52
 
|  00:52
 
|  This is our Header file.
 
|  This is our Header file.
 
  
 
|-
 
|-
|   00:54
+
| 00:54
|   This is our  main function.
+
| This is our  main() function.
 
   
 
   
 
 
|-
 
|-
 
|  00:56
 
|  00:56
| Inside the main function we have declared two integer variables ''''x and y''''
+
| Inside the main() function we have declared two integer variables ''''x and y''''.
  
 
|-
 
|-
Line 75: Line 67:
 
|-
 
|-
 
| 01:08
 
| 01:08
we take the value of '''y''' as input from the user.
+
We take the value of '''y''' as input from the user.
  
 
|-
 
|-
 
|  01:12
 
|  01:12
| This is our if condition  
+
| This is our '''if''' condition.
  
 
|-
 
|-
 
|  01:14
 
|  01:14
| Here, we will check whether y/10=0
+
| Here, we will check whether y/10=0.
  
 
|-
 
|-
 
|  01:19
 
|  01:19
| If the condition is true
+
| If the condition is true, we print '''"you have entered the number in the range of 0-9".'''
 
+
|-
+
|  01:20
+
| We print '''"you have entered a number in the range of 0-9.'''
+
  
 
|-
 
|-
 
| 01:25
 
| 01:25
| This is our else-if condition.
+
| This is our '''else-if''' condition.
  
 
|-
 
|-
 
|  01:28
 
|  01:28
|  Here we check that y/10=1.
+
|  Here we check that y/10 equals to 1.
 
|-
 
|-
 
|  01:32
 
|  01:32
|If the condition is true.
+
|If the condition is true,
  
 
|-
 
|-
 
|  01:34
 
|  01:34
| We print '''you have entered a number in the range of 10-19.'''
+
| we print ''' "you have entered a number in the range of 10-19".'''
  
 
|-
 
|-
 
|  01:39
 
|  01:39
|In this else if condition we check whether the number is in the range of 20-29.
+
|In this '''else if''' condition we check whether the number is in the range of 20-29.
 
|-
 
|-
 
|  01:45
 
|  01:45
Line 116: Line 104:
 
|-
 
|-
 
|  01:51
 
|  01:51
|  This is our else condition.
+
|  This is our '''else''' condition.
 
+
  
 
|-
 
|-
 
|  01:53
 
|  01:53
|  If all of the above conditions are false
+
|  If all of the above conditions are false,
  
 
|-
 
|-
02:24
+
01:55
| We print''' number not in range.'''
+
| we print''' "number not in range".'''
  
 
|-
 
|-
02:28
+
01:58
| And this is our return statement
+
| And this is our '''return''' statement.
 
|-
 
|-
|  02:31
+
|  02:01
 
|  Now let us execute the program.
 
|  Now let us execute the program.
  
 
|-
 
|-
|     02:35
+
| 02:03
| Please open the terminal window , by pressing Ctrl+Alt+T keys simultaneously on your keyboard.
+
| Please open the terminal window by pressing '''Ctrl+Alt''' and '''T''' keys simultaneously on your keyboard.
  
 
|-
 
|-
| 02:45
+
| 02:12
|To execute , Type “gcc” space “nested-if.c” space hyphen “-o” space “nested”. Press '''Enter'''
+
|To execute, type '''gcc space nested-if.c space hyphen o space nested'''. Press '''Enter'''.
  
 
|-
 
|-
| 02:57
+
| 02:23
| type dot slash “nested”. Press '''Enter'''
+
| Type dot slash “nested” (./nested). Press '''Enter'''.
  
 
|-
 
|-
03:01
+
02:28
| We see,Enter a number between 0 to 39.  
+
| We see '''Enter a number between 0 to 39'''.  
  
 
|-
 
|-
| 03:06  
+
| 02:32  
| I will Enter  '''12'''
+
| I will enter '''12'''.
  
 
|-
 
|-
| 03:09
+
| 02:34
 
| | The output is displayed as:
 
| | The output is displayed as:
  
 
|-
 
|-
03:11
+
02:35
 
|''' you have entered the  number  in the range of 10-19'''.
 
|''' you have entered the  number  in the range of 10-19'''.
  
 
|-
 
|-
03:17
+
02:40
 
| Let us enter another number.
 
| Let us enter another number.
 
|-
 
|-
03:21
+
02:42
|  Let's execute again. Press the up arrow key, press enter.
+
|  Let's execute again. Press the up arrow key, press '''Enter'''.
  
 
|-
 
|-
03:28
+
02:48
 
| I will give ''' 5''' this time.
 
| I will give ''' 5''' this time.
  
 
|-
 
|-
03:34
+
02:50
 
| We see the output as :
 
| We see the output as :
  
 
|-
 
|-
03:35
+
02:52
|  you have entered the number in the range of 0-9.
+
'''you have entered the number in the range of 0-9'''.
 +
 
 
|-
 
|-
03:42
+
02:56
 
|  The conditional execution can also be done in another way.
 
|  The conditional execution can also be done in another way.
  
 
|-
 
|-
|  03:46
+
|  03:00
| By using '''switch statement. '''
+
| By using '''switch''' statement.
  
 
|-
 
|-
|  03:49
+
|  03:02
 
| Let’s see how it is done.
 
| Let’s see how it is done.
  
 
|-
 
|-
| 03:51
+
| 03:05
 
| We will see  the same program using '''switch'''.
 
| We will see  the same program using '''switch'''.
  
 
|-
 
|-
|  03:57
+
|  03:08
 
| I have already opened the program.
 
| I have already opened the program.
 
  
 
|-
 
|-
|  03:59
+
|  03:10
|  Let's switch back to our text editor
+
|  Let's switch back to our text editor.
 
|-
 
|-
04:07
+
03:13
 
|I have explained this in the previous program.     
 
|I have explained this in the previous program.     
  
 
|-
 
|-
| 04:11
+
| 03:16
|So i will move on to the '''Switch statements'''
+
|So I will move on to the '''switch''' statements.
+
 
    
 
    
 
|-
 
|-
| 04:16
+
| 03:20
||Here, we divide the inputs i.e '''y'''   by 10 and the result  is  stored in  the variable '''x'''.
+
||Here, we divide the inputs i.e '''y''' by 10 and the result  is  stored in  the variable '''x'''.
  
 
|-
 
|-
|04:24  
+
|03:28  
 
| That means the quotient will be stored in x.
 
| That means the quotient will be stored in x.
  
 
|-
 
|-
04:28
+
03:32
 
| With the help of the quotient we can identify the range of the number.
 
| With the help of the quotient we can identify the range of the number.
  
 
|-
 
|-
04:37
+
03:36
 
|  Here, we tell the switch command that the variable to be checked is '''x'''.
 
|  Here, we tell the switch command that the variable to be checked is '''x'''.
  
 
|-
 
|-
04:47
+
03:41
|This is '''case 0''' . If case 0 is satisfied.
+
|This is '''case 0''' . If case 0 is satisfied  
  
 
|-
 
|-
04:50
+
03:45
| Then we print '''you have entered  the number in the range of 0-9.'''
+
| then we print '''you have entered  the number in the range of 0-9.'''
  
 
|-
 
|-
| 04:58
+
| 03:51
 
| We add '''break '''to come out of the loop if the case is satisfied.
 
| We add '''break '''to come out of the loop if the case is satisfied.
  
 
|-
 
|-
05:03
+
|  03:55
 
| We need to '''break '''the loop each time.  
 
| We need to '''break '''the loop each time.  
  
 
|-
 
|-
05:05
+
03:58
 
| It is because only one condition can be true at a time.
 
| It is because only one condition can be true at a time.
  
 
|-
 
|-
| 05:11
+
| 04:03
|This is “case 1” . “case 1” means “if the value of '''x '''is 1”
+
|This is “case 1”. “case 1” means “if the value of '''x '''is 1”.
 
+
 
   
 
   
 
|-
 
|-
05:17
+
04:08
 
| We print '''you have entered a number in the range of 10-19.'''
 
| We print '''you have entered a number in the range of 10-19.'''
  
 
|-
 
|-
05:24
+
04:12
 
| This is  “case 2” .  
 
| This is  “case 2” .  
  
 
|-
 
|-
05:26
+
04:14
 
|Here  we print '''you have entered a number in the range of 20-29.'''
 
|Here  we print '''you have entered a number in the range of 20-29.'''
  
 
|-
 
|-
| 05:33
+
| 04:20
 
| And this is case 3. Here we check whether the number is in the range of 30-39.
 
| And this is case 3. Here we check whether the number is in the range of 30-39.
  
 
|-
 
|-
| 05:43
+
| 04:26
 
| This is the default case. Default case specifies what needs to be done if none of the above cases are satisfied.
 
| This is the default case. Default case specifies what needs to be done if none of the above cases are satisfied.
  
 
|-
 
|-
05:52
+
04:36
| Here we print number not in range.
+
| Here we print "number not in range".
 
+
  
 
|-
 
|-
05:57
+
04:39
| And This is our return statement.
+
| And This is our '''return''' statement.
  
 
|-
 
|-
05:59
+
04:41
 
| Let us execute the program.
 
| Let us execute the program.
 
  
 
|-
 
|-
06:02
+
04:43
 
|Switch back to the terminal.
 
|Switch back to the terminal.
  
 
|-
 
|-
06:06
+
04:46
|Type:gcc switch.c -o switch. Press Enter
+
|Type '''gcc space switch.c space -o space switch'''. Press Enter.
  
 
|-
 
|-
| 06:16
+
| 04:55
| Type:./switch. Press Enter
+
| Type '''./switch'''(dot slash switch). Press Enter.
 
+
  
 
|-
 
|-
06:21
+
05:00
| Enter a number between   of 0 to  39. I willl enter 35
+
| Enter a number between 0 to  39. I will enter 35.
  
 
|-
 
|-
06:28
+
05:06
|  The output is displayed as,“you have entered the number in the range of 30 to 39”.
+
|  The output is displayed as “you have entered the number in the range of 30 to 39”.
  
 
|-
 
|-
06:35
+
05:10
 
| Now we will see how to execute the programs  in C++.
 
| Now we will see how to execute the programs  in C++.
 +
 
|-
 
|-
| 06:44
+
| 05:16
 
|Switch back to the text editor.
 
|Switch back to the text editor.
 +
 
|-
 
|-
06:47
+
05:18
| Note that our filename is nested-if.cpp
+
| Note that our file name is '''nested-if.cpp'''.
 +
 
 
|-
 
|-
06:55
+
05:23
| Here the logic and implementation are same
+
| Here the logic and implementation are same.
  
 
|-
 
|-
06:59
+
05:27
 
|  There are a few changes like:
 
|  There are a few changes like:
 +
 
|-
 
|-
07:03
+
05:30
|The header file as iostream in place of stdio.h
+
|The header file as "iostream" in place of "stdio.h".
 +
 
 
|-
 
|-
07:08
+
05:35
|Here we have included the using statement.
+
|Here we have included the '''using''' statement
 +
 
 
|-
 
|-
07:11
+
05:39
|Using namespace std
+
|'''Using namespace std'''.
  
 
|-
 
|-
07:14
+
05:41
|And the  cout and cin function in place of printf and scanf.
+
|And the  '''cout''' and '''cin''' function in place of '''printf''' and '''scanf'''.
 +
 
 
|-
 
|-
07:23
+
05:46
 
|You can see that the rest of the code is similar to our C program.
 
|You can see that the rest of the code is similar to our C program.
  
 
|-
 
|-
07:29
+
05:51
 
|Let’s execute the code.
 
|Let’s execute the code.
 +
 
|-
 
|-
07:31
+
05:53
 
|Come back to the terminal.
 
|Come back to the terminal.
 +
 
|-
 
|-
07:34
+
05:56
|Typeg++ nested-if.cpp -o nested1. Press Enter.
+
|Type '''g++ space nested-if.cpp space -o space nested1'''. Press Enter.
 +
 
 
|-
 
|-
07:45
+
06:07
|Type./nested1. Press Enter
+
|Type '''./nested1'''. Press Enter.
 +
 
 
|-
 
|-
07:50
+
06:11
| enter a number between 0 and 39. I will enter 40.
+
| Enter a number between 0 to 39. I will enter 40.
 +
 
 
|-
 
|-
07:53
+
06:16
 
| The output is displayed as: “number not in range”
 
| The output is displayed as: “number not in range”
 +
 
|-
 
|-
08:06
+
|  06:20
|Now let’s see the switch program in C++
+
|Now let’s see the switch program in C++.
 +
 
 
|-
 
|-
08:10
+
06:24
|   Come back to the text editor.
+
| Come back to our text editor.
 
   
 
   
 
|-
 
|-
08:14
+
06:27
|   Here also the logic and implementation are same.
+
| Here also the logic and implementation are same.
 +
 
 
|-
 
|-
08:19
+
06:31
| You can see that the  header file is iostream
+
| You can see that the  header file is '''iostream'''.
 +
 
 
|-
 
|-
08:23
+
06:34
| Here is the using statement.
+
| Here is the '''using''' statement.
 +
 
 
|-
 
|-
08:25
+
06:37
| And we have changed the cout and cin function.
+
| And we have changed the '''cout''' and '''cin''' function.
 +
 
 
|-
 
|-
08:33
+
06:41
| Rest of the code is similar to our switch.c program
+
| Rest of the code is similar to our switch.c program.
 +
 
 
|-
 
|-
08:38
+
06:45
| Let us execute.
+
| Let us execute.Come back to our terminal.
 
|-
 
|-
08:40
+
06:48
|Come back to the terminal.
+
|Type '''g++ space switch.cpp space -o space switch1'''. Press Enter.
 
|-
 
|-
08:42
+
06:58
|Type:g++ switch.cpp -o switch1 Press Enter
+
| Type '''./switch1'''. Press Enter.
 
|-
 
|-
08:52
+
07:02
| Type ./switch1. Press Enter
+
| Enter a number between 0 to 39.
|-
+
|  08:57
+
| Enter a number between 0 and 39.
+
 
|-
 
|-
09:00
+
07:05
 
|  I will enter 25.
 
|  I will enter 25.
 
|-
 
|-
09:04
+
07:09
 
|  The output is displayed as:
 
|  The output is displayed as:
 
|-
 
|-
09:06
+
07:11
 
|  “you have entered  the number in the range of 20-29”
 
|  “you have entered  the number in the range of 20-29”
  
 
|-
 
|-
09:11
+
07:15
 
|  Now let us switch back to our slides.
 
|  Now let us switch back to our slides.
 
|-
 
|-
| 09:16
+
| 07:18
|We will see the comparison between   switch and nested-if statement.
+
|We will see the comparison between switch and nested-if statements.
|-
+
  
 
|-
 
|-
09:21
+
07:23
 
|  Switch statement is evaluated according to the result of the expression.
 
|  Switch statement is evaluated according to the result of the expression.
 
|-
 
|-
09:28
+
07:28
|Netsed-if statement is run, only if the result of the expression is true.
+
|Netsed-if statement is run only if the result of the expression is true.
 
|-
 
|-
09:35
+
07:34
|In switch we treat various values of the variable as cases.  
+
|In '''switch''', we treat various values of the variable as '''cases'''.  
 
|-
 
|-
09:41
+
07:39
 
|In nested-if we have to write the conditional statement for each value of the variable.
 
|In nested-if we have to write the conditional statement for each value of the variable.
  
 
|-
 
|-
09:49
+
07:45
|  Switch statement can only check the integer values
+
|  Switch statement can only check the integer values.
 
|-
 
|-
09:54
+
07:50
|  Nested if can check for both integer and fractional values.
+
|  Nested if can check for both, integer and fractional values.
 
|-
 
|-
10:00
+
07:55
 
|  This brings us to the end of this tutorial.
 
|  This brings us to the end of this tutorial.
 
   
 
   
 
|-
 
|-
| 10:03
+
| 07:58
 
|Let us summarize.
 
|Let us summarize.
 
   
 
   
 
|-
 
|-
| 10:05
+
| 08:00
|  In this tutorial we learnt, nested if statement.
+
|  In this tutorial, we learnt * 'nested if' statement. e.g. else if( y/10 equals to 0)  
 
+
Ex: else if( y/10==0)  
+
  
 
|-
 
|-
| 10:13    
+
|08:08    
| switch statement.
+
|switch statement. e.g. switch(x) and
e.g. Switch(x)
+
  
 
|-
 
|-
10:16
+
08:12
|And Difference between nested-if and switch statements.
+
|Difference between nested-if and switch statements.
 
+
 
   
 
   
 
|-
 
|-
10:22
+
08:16
| As an assignment,
+
| As an assignment,write a program to check whether the age of the employee is between 20 to 60.
  
 
|-
 
|-
| 10:23
+
| 08:23
| Write a program to check whether the age of the employee is between 20 to 60.
+
| Watch the video available at the link shown http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial.
  
 
|-
 
|-
|   10:30
+
| 08:26
| | Watch the video available at the link shown http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
10:33
+
08:29
| It summarizes the Spoken Tutorial project
+
 
+
|-
+
|  10:36
+
 
| 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.
  
 
|-
 
|-
10:40
+
08:33
|  The Spoken Tutorial Project Team,
+
|  The Spoken Tutorial Project Team, Conducts workshops using spoken tutorials.
  
 
|-
 
|-
10:42
+
08:38
| Conducts workshops using spoken tutorials.
+
 
+
|-
+
|  10:45
+
 
| Gives certificates to those who pass an online test.
 
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
| 10:49
+
| 08:42
| For more details please write to   contact @spoken-tutorial.org
+
| For more details please write to contact @spoken-tutorial.org
  
 
|-
 
|-
| 10:56
+
| 08:49
|  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.
  
 
|-
 
|-
11:00
+
08:52
| 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.
  
 
|-
 
|-
11:08
+
|  08:58
| More information on this Mission is available at: [http://spoken-tutorial.org/ http://spoken-tutorial.org]\NMEICT-Intro
+
| More information on this Mission is available at: [http://spoken-tutorial.org/ http://spoken-tutorial.org]\NMEICT-Intro.
  
 
|-
 
|-
| 11:13
+
| 09:04
 
|  The script is contributed by Chaitanya Mokashi. This is Ashwini patil from IIT Bombay signing off. Thank you for joining.
 
|  The script is contributed by Chaitanya Mokashi. This is Ashwini patil from IIT Bombay signing off. Thank you for joining.
  
 
|}
 
|}

Latest revision as of 13:04, 24 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on Nested if and Switch statements in C and C++.
00:07 In this tutorial we will learn,
00:09 how to use nested if statement and
00:12 switch statement.We will do this with the help of some examples.
00:17 To record this tutorial, I am using
00:20 Ubuntu operating system version 11.10,
00:24 gcc and g++ Compiler version 4.6.1 on Ubuntu.
00:30 First we will learn how to write nested if and switch statements with an example.
00:36 I have already written the program.
00:39 Let’s have a look. In this program we will learn to check the range of integers.
00:45 Note that our file name is nested-if.c.
00:50 Let me explain the code now.
00:52 This is our Header file.
00:54 This is our main() function.
00:56 Inside the main() function we have declared two integer variables 'x and y'.
01:02 Here we prompt the users to enter a number between the range of 0 to 39.
01:08 We take the value of y as input from the user.
01:12 This is our if condition.
01:14 Here, we will check whether y/10=0.
01:19 If the condition is true, we print "you have entered the number in the range of 0-9".
01:25 This is our else-if condition.
01:28 Here we check that y/10 equals to 1.
01:32 If the condition is true,
01:34 we print "you have entered a number in the range of 10-19".
01:39 In this else if condition we check whether the number is in the range of 20-29.
01:45 And here we will see that the number is in the range of 30 to 39.
01:51 This is our else condition.
01:53 If all of the above conditions are false,
01:55 we print "number not in range".
01:58 And this is our return statement.
02:01 Now let us execute the program.
02:03 Please open the terminal window by pressing Ctrl+Alt and T keys simultaneously on your keyboard.
02:12 To execute, type gcc space nested-if.c space hyphen o space nested. Press Enter.
02:23 Type dot slash “nested” (./nested). Press Enter.
02:28 We see Enter a number between 0 to 39.
02:32 I will enter 12.
02:34 The output is displayed as:
02:35 you have entered the number in the range of 10-19.
02:40 Let us enter another number.
02:42 Let's execute again. Press the up arrow key, press Enter.
02:48 I will give 5 this time.
02:50 We see the output as :
02:52 you have entered the number in the range of 0-9.
02:56 The conditional execution can also be done in another way.
03:00 By using switch statement.
03:02 Let’s see how it is done.
03:05 We will see the same program using switch.
03:08 I have already opened the program.
03:10 Let's switch back to our text editor.
03:13 I have explained this in the previous program.
03:16 So I will move on to the switch statements.
03:20 Here, we divide the inputs i.e y by 10 and the result is stored in the variable x.
03:28 That means the quotient will be stored in x.
03:32 With the help of the quotient we can identify the range of the number.
03:36 Here, we tell the switch command that the variable to be checked is x.
03:41 This is case 0 . If case 0 is satisfied
03:45 then we print you have entered the number in the range of 0-9.
03:51 We add break to come out of the loop if the case is satisfied.
03:55 We need to break the loop each time.
03:58 It is because only one condition can be true at a time.
04:03 This is “case 1”. “case 1” means “if the value of x is 1”.
04:08 We print you have entered a number in the range of 10-19.
04:12 This is “case 2” .
04:14 Here we print you have entered a number in the range of 20-29.
04:20 And this is case 3. Here we check whether the number is in the range of 30-39.
04:26 This is the default case. Default case specifies what needs to be done if none of the above cases are satisfied.
04:36 Here we print "number not in range".
04:39 And This is our return statement.
04:41 Let us execute the program.
04:43 Switch back to the terminal.
04:46 Type gcc space switch.c space -o space switch. Press Enter.
04:55 Type ./switch(dot slash switch). Press Enter.
05:00 Enter a number between 0 to 39. I will enter 35.
05:06 The output is displayed as “you have entered the number in the range of 30 to 39”.
05:10 Now we will see how to execute the programs in C++.
05:16 Switch back to the text editor.
05:18 Note that our file name is nested-if.cpp.
05:23 Here the logic and implementation are same.
05:27 There are a few changes like:
05:30 The header file as "iostream" in place of "stdio.h".
05:35 Here we have included the using statement
05:39 Using namespace std.
05:41 And the cout and cin function in place of printf and scanf.
05:46 You can see that the rest of the code is similar to our C program.
05:51 Let’s execute the code.
05:53 Come back to the terminal.
05:56 Type g++ space nested-if.cpp space -o space nested1. Press Enter.
06:07 Type ./nested1. Press Enter.
06:11 Enter a number between 0 to 39. I will enter 40.
06:16 The output is displayed as: “number not in range”
06:20 Now let’s see the switch program in C++.
06:24 Come back to our text editor.
06:27 Here also the logic and implementation are same.
06:31 You can see that the header file is iostream.
06:34 Here is the using statement.
06:37 And we have changed the cout and cin function.
06:41 Rest of the code is similar to our switch.c program.
06:45 Let us execute.Come back to our terminal.
06:48 Type g++ space switch.cpp space -o space switch1. Press Enter.
06:58 Type ./switch1. Press Enter.
07:02 Enter a number between 0 to 39.
07:05 I will enter 25.
07:09 The output is displayed as:
07:11 “you have entered the number in the range of 20-29”
07:15 Now let us switch back to our slides.
07:18 We will see the comparison between switch and nested-if statements.
07:23 Switch statement is evaluated according to the result of the expression.
07:28 Netsed-if statement is run only if the result of the expression is true.
07:34 In switch, we treat various values of the variable as cases.
07:39 In nested-if we have to write the conditional statement for each value of the variable.
07:45 Switch statement can only check the integer values.
07:50 Nested if can check for both, integer and fractional values.
07:55 This brings us to the end of this tutorial.
07:58 Let us summarize.
08:00 In this tutorial, we learnt * 'nested if' statement. e.g. else if( y/10 equals to 0)
08:08 switch statement. e.g. switch(x) and
08:12 Difference between nested-if and switch statements.
08:16 As an assignment,write a program to check whether the age of the employee is between 20 to 60.
08:23 Watch the video available at the link shown http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial.
08:26 It summarizes the Spoken Tutorial project.
08:29 If you do not have good bandwidth, you can download and watch it.
08:33 The Spoken Tutorial Project Team, Conducts workshops using spoken tutorials.
08:38 Gives certificates to those who pass an online test.
08:42 For more details please write to contact @spoken-tutorial.org
08:49 Spoken Tutorial Project is a part of the Talk to a Teacher project.
08:52 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
08:58 More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro.
09:04 The script is contributed by Chaitanya Mokashi. This is Ashwini patil from IIT Bombay signing off. Thank you for joining.