Dynamic Array Multidimensional Array Matric Operation with Array

Slides:



Advertisements
Similar presentations
Section 13-4: Matrix Multiplication
Advertisements

Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Matrix Multiplication To Multiply matrix A by matrix B: Multiply corresponding entries and then add the resulting products (1)(-1)+ (2)(3) Multiply each.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
1 Matrix Addition, C = A + B Add corresponding elements of each matrix to form elements of result matrix. Given elements of A as a i,j and elements of.
Table of Contents Matrices - Multiplication Assume that matrix A is of order m  n and matrix B is of order p  q. To determine whether or not A can be.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
February 11, 2005 More Pointers Dynamic Memory Allocation.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Defining a 2d Array A 2d array implements a MATRIX. Example: #define NUMROWS 5 #define NUMCOLS 10 int arr[NUMROWS][NUMCOLS];
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
POINTERS.
How to Multiply Two Matrices. Steps for Matrix Multiplication 1.Determine whether the matrices are compatible. 2.Determine the dimensions of the product.
8.2 Operations With Matrices
Arrays Dr. Jose Annunziato. Arrays Up to this point we have been working with individual primitive data types Arrays allow working with multiple instances.
Pointers It provides a way of accessing a variable without referring to its name. The mechanism used for this is the address of the variable.
 In this lesson we will go over how to solve a basic matrix equation such as the following: These are matrices, not variables.
Warm Up Perform the indicated operations. If the matrix does not exist, write impossible
Example 7 Multiplying with Technology Chapter 7.3 Use technology to compute BA and AB if and.  2009 PBLPathways.
MATRIX A set of numbers arranged in rows and columns enclosed in round or square brackets is called a matrix. The order of a matrix gives the number of.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
Matrix Multiplication The Introduction. Look at the matrix sizes.
3.6 Multiplying Matrices Homework 3-17odd and odd.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Notes Over 4.2 Finding the Product of Two Matrices Find the product. If it is not defined, state the reason. To multiply matrices, the number of columns.
4-3 Matrix Multiplication Objective: To multiply a matrix by a scalar multiple.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Windows Programming Lecture 03. Pointers and Arrays.
Pointers and Dynamic Arrays
13.4 Product of Two Matrices
12-1 Organizing Data Using Matrices
I/O Streams File I/O 2-D array review
2-D Array.
Introduction to Programming
1.5 Matricies.
Multidimensional Arrays
Lecture 7 Arrays, Dynamic Arrays & Copy Constructors “Absolute C++”
Matrix Multiplication
MULTI-DIMENSIONAL ARRAY
Multi-dimensional Array
CS 213: Data Structures and Algorithms
WarmUp 2-3 on your calculator or on paper..
Hw 5 Hints.
Counting Loops.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
MATRICES MATRIX OPERATIONS.
2.2 Introduction to Matrices
Objectives Multiply two matrices.
Multidimensional array
Multidimensional Arrays
CHAPTER 2 Arrays and Vectors.
Lets Play with arrays Singh Tripty
Arrays Arrays A few types Structures of related data items
Multi-Dimensional Arrays
CHAPTER 2 Arrays and Vectors.
Dimensions matching Rows times Columns
Determinants 2 x 2 and 3 x 3 Matrices.
3.6 Multiply Matrices.
Determinants 2 x 2 and 3 x 3 Matrices.
Matrix Addition, C = A + B Add corresponding elements of each matrix to form elements of result matrix. Given elements of A as ai,j and elements of B as.
Multiplying Whole Numbers
Arrays and Matrices Prof. Abdul Hameed.
Dynamic Objects.
Matrix Multiplication Sec. 4.2
Introduction to Matrices
Chapter 6 - Arrays Outline Multiple-Subscripted Arrays.
Presentation transcript:

Dynamic Array Multidimensional Array Matric Operation with Array Arrays Dynamic Array Multidimensional Array Matric Operation with Array

Dynamic array

How do you create Dynamic Array A dynamic array is an array whose size is determined when the program is running, not when you write the program

Example int main () { int i,n; int * p; cout << "How many numbers would you like to type? "; cin >> i; p= new (nothrow) int[i]; if (p == 0) cout << "Error: memory could not be allocated"; else for (n=0; n<i; n++) cout << "Enter number: "; cin >> p[n]; } cout << "You have entered: "; cout << p[n] << ", "; delete[] p; return 0;

Multidimensional array

How do you create it? Declare it using:

How to read it/display it

Actually it is…

Example

Example: Output

Matric operation with array

How to do multiplication

Rules of Multiplication Number of COLUMN for First ARRAY must be the same with Number of ROW for Second ARRAY You must properly define who is the First Array and who is the Second Array Example: Matrix 3 x 5 with Matrix 5 x 1 = RIGHT Matrix 2 x 6 with Matrix 2 x 4 = WRONG

Example Let say you have From the example, we first take “1” from (First Array) the first row first column multiply with “2” from (Second Array) the first row first column. Then PLUS (+) with “2” from (First Array) the first row second column multiply with “0” from (Second Array) the second row first column. We will have 1 x 2 + 2 x 1 = 4

But how to do that in C++?

But how to do that in C++? We iterate first Array but according to “m” value (MAX ROW)

But how to do that in C++? We iterate second Array according to the “q” value (MAX COLUMN)

But how to do that in C++? We let all the content = 0 for the first time

But how to do that in C++? K is for storing the result of multiplication. P is MAX ROW for SECOND ARRAY

But how to do that in C++? Remember to add c[i][j] for next “k” iteration after multiplication

Matrix Operation with Array Refer source code explanation