C-and-C++/C3/Working-With-2D-Arrays/English-timed
From Script | Spoken-Tutorial
Revision as of 14:29, 24 March 2017 by Pratik kamble (Talk | contribs)
Time | Narration |
00:01 | Welcome to the spoken-tutorial on 2 Dimensional Arrays in C and C++. |
00:08 | In this tutorial, we will learn- |
00:10 | what is a 2 Dimensional array. |
00:13 | We will do this through an example. |
00:16 | To record this tutorial, I am using |
00:18 | Ubuntu Operating System version 11.10, |
00:22 | gcc and g++ Compiler version 4.6.1 on Ubuntu. |
00:29 | Let us start with the introduction to 2 dimensional Array. |
00:33 | 2D arrays are stored in a row column matrix. |
00:38 | The left index indicates the row. |
00:41 | The right index indicates the column. |
00:44 | Starting index of a matrix or array in C and C++ is always 0. |
00:52 | Here, we see a 2 Dimensional array in a row column matrix. |
00:58 | Starting index is 0. |
01:01 | Now, let us see how to declare 2 dimensional array. |
01:04 | The Syntax for this is: |
01:07 | data-type ,array name, row and column. |
01:13 | example, here we have declared a 2 dimensional array num with 2 rows and 3 columns. |
01:21 | Now let us see an example. |
01:23 | I have already typed the program, let me open it. |
01:28 | Note that our file name is 2d hyphen array dot c. |
01:33 | In this program, we will calculate the sum of the elements of the 2 dimensional array. |
01:41 | Let me explain the code now. |
01:44 | This is our header file. |
01:46 | This is our main() function. |
01:49 | Here we have declared variables i and j. |
01:53 | Then we have declared num1 with 3 rows and 4 columns. |
01:58 | And num2, again with 3 rows and 4 columns. |
02:03 | num1 and num2 are 2 dimensional arrays. |
02:07 | Here, we take elements of the matrix num1 as input from the user. |
02:13 | The elements are stored row-wise. |
02:16 | We have considered i for rows and j for columns. |
02:22 | This for loop will check the condition that i runs from 0 to 2. |
02:28 | This for loop will check the condition that j runs from 0 to 3. |
02:33 | Similarly, here we take elements of the matrix num2 as input from the user. |
02:40 | Here we display the matrix num1. |
02:43 | Here percent 3d is used to align the matrix on the terminal. |
02:49 | Now, here we display the matrix num2. |
02:52 | Then we add the num1 matrix and the num2 matrix and display the result. |
02:59 | This is our return statement. |
03:01 | Now, click on Save. |
03:05 | Let us execute the program. |
03:07 | Please open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard. |
03:15 | To compile, type gcc space 2d hyphen array dot c space hyphen o space arr and press Enter. |
03:28 | To execute, type dot slash arr (./arr), now press Enter . |
03:34 | Here we see Enter the elements of 3 into 4 array num1. |
03:39 | I will enter the values now. |
03:52 | Now we can see Enter the elements of 3 into 4 array num2. |
03:57 | I will enter the values. |
04:10 | The output is displayed. |
04:13 | Here we can see the num1 matrix. |
04:16 | Here we can see the num2 matrix. |
04:20 | And this is the sum of num1 and num2. |
04:24 | Now we will see how to execute the same program in C++. |
04:29 | I have already made the program. I will open it and explain. |
04:34 | This is the program for 2 Dimensional arrays in C++. |
04:38 | Note that our file name is 2d hyphen array dot cpp. |
04:43 | The extension is dot cpp (.cpp). |
04:47 | Let me explain the code now. |
04:50 | This is our header file as iostream. |
04:53 | This is our using statement. |
04:56 | This is our main() function. |
04:58 | Here we have cout function as we use cout to print the output in C++. |
05:06 | Then we have cin function. We use cin to read a line in C++. |
05:13 | Here, we use / t bit mean horizontal tab that is equivalent to 4 spaces. |
05:21 | Rest of the code is similar to our C code. |
05:25 | Now click on Save. |
05:27 | Let us execute. Come back to a terminal. |
05:31 | Let me clear the prompt. |
05:33 | To compile, type g++ space 2d hyphen array dot cpp hyphen o space arr1 and press Enter. |
05:47 | To execute, type dot slash arr1, now press Enter. |
05:52 | Here we see Enter the elements of 3 into 4 array num1. |
05:57 | I will enter the values. |
06:07 | Now, we see Enter the elements of 3 into 4 array num2. |
06:13 | I will give the values as: |
06:24 | The output is displayed. |
06:26 | We can see the num1 matrix, the num2 matrix. |
06:31 | And this is the sum of num1 and num2. |
06:36 | This brings us to the end of this tutorial. |
06:39 | Come back to our slide. Let us Summarize. |
06:43 | In this tutorial we learnt: |
06:45 | To add elements in a 2D array. |
06:48 | To print 2D array. |
06:50 | And to calculate the sum of 2Dimensional array. |
06:54 | As an assignment: Write the program that takes two 2Dimensional arrays as input from the user. |
07:01 | Subtract them and find the result. |
07:05 | Watch the video available at the link shown below: |
07:08 | It summarizes the Spoken Tutorial project. |
07:11 | If you do not have good bandwidth, you can download and watch it. |
07:15 | The Spoken Tutorial Project Team: |
07:17 | Conducts workshops using spoken tutorials. |
07:21 | Gives certificates to those who pass an online test. |
07:25 | For more details, please write to, contact@spoken-tutorial.org. |
07:32 | Spoken Tutorial Project is a part of Talk to a Teacher project. |
07:36 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
07:43 | More information on this mission is available at the link shown below. |
07:48 | The script is contributed by Ritwik Joshi. This is Ashwini Patil from IIT Bombay. |
07:54 | Thank you for watching. |