Topic 2 Passing Two Dimensional Arrays and One Dimensional Arrays As Parameter to Functions By: Nor Zalina Ismail Faculty of Computer and Mathematical.

Slides:



Advertisements
Similar presentations
Let’s Look at Some Functions Boolean Functions – functions that return ‘true’ or ‘false’ Other Functions – some with arguments, some with none.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Topic 9C – Multiple Dimension Arrays. CISC105 – Topic 9C Multiple Dimension Arrays A multiple dimension array is an array that has two or more dimensions.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
TK1914: C++ Programming Array II. Objective In this chapter you will explore how to manipulate data in a two-dimensional array. 2FTSM :: TK1914,
1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
Array What it is. How to use it How to declare it How to initialize it.
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.
1 Lecture 21:Arrays and Strings(cont.) Introduction to Computer Science Spring 2006.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Multiple-Subscripted Array
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
Chapter 7 Arrays C++ Programming, Namiq Sultan1 Namiq Sultan University of Duhok Department of Electrical and Computer Engineering Reference: Starting.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
Pass by Reference. COMP104 Pass by Reference / Slide 2 Passing Parameters by Reference * To have a function with multiple outputs, we have to use pass.
Chapter 7: Arrays. Outline Array Definition Access Array Array Initialization Array Processing 2D Array.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Prepared by MURLI MANOHAR PGT (COMPUTER SCIENCE) KV,B.E.G., PUNE.
Java Unit 9: Arrays Declaring and Processing Arrays.
1 Arrays Chapter 13 Especially read 13.1 – 13.2 Text introduces vectors, which we will not cover, in 13.3.
Chapter 8 Arrays and Strings
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Objectives: In this chapter, you will: Know the different between struct and array.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
1 Chapter 7 Arrays. 2 Topics 7.1 Arrays Hold Multiple Values 7.2 Accessing Array Elements 7.3 No Bounds Checking in C Array Initialization 7.5 Processing.
Review for Final Exam. Contents 5 questions (20 points each) + 1 bonus question (20 points) – Basic concepts in Chapters 1-4 – Chapters 5-9 – Bonus: Chapter.
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
Arrays. Collections We would like to be able to keep lots of information at once Example: Keep all the students in the class Grade each one without writing.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 7.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 7 Arrays.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Arrays Chapter 7. Arrays Hold Multiple Values Array: variable that can store multiple values of the same type Values are stored in adjacent memory locations.
2D Arrays Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Spring 2006.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Opening Input/Output Files ifstream infile; ofstream outfile; char inFileName[40]; char outFileName[40]; coutinFileName;
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
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.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
1 A Pointer: an address, a reference, a location of the computer memory A pointer of what? int, char, bool, double, or any kind of data type need to know.
Arrays Chapter 12. One-Dimensional Arrays If you wanted to read in 1000 ints and print them in reverse order, it would take a program that’s over 3000.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Pointers  * symbol and & symbol  Pointer operations  Pointer.
Arrays. Arrays are objects that help us organize large amounts of information.
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
Arrays float Scores[9]; ? index: element // one dimensional array 1.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Chapter 8: Arrays. Arrays Hold Multiple Values Array: variable that can store multiple values of the same type Values are stored in adjacent memory locations.
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
1 Two-Dimensional Arrays. 2 Terminology Two-dimensional arrays represent matrices A matrix contains a number of values of the same data type The values.
Arrays float Scores[9]; ? index: element // one dimensional array 2.
Chapter 8: Arrays Starting Out with C++ Early Objects Ninth Edition
Computer Programming BCT 1113
Multidimensional Arrays
INC 161 , CPE 100 Computer Programming
Arrays.
NOR ZALINA ISMAIL FACULTY OF COMPUTER AND MATHEMATICAL SCIENCES1
Presentation transcript:

Topic 2 Passing Two Dimensional Arrays and One Dimensional Arrays As Parameter to Functions By: Nor Zalina Ismail Faculty of Computer and Mathematical Sciences www2.pahang.uitm.edu.my/nor_zalina

Objective : In this topic you will: Discover how to pass an array as a parameter to a function

Arrays as parameter Arrays are passing by using reference parameter but the & symbol is not used

Printing an Array(One Dimensional Array) using Function void printMatrix(int Matrix[],int size); void main() { const int size=4; int data[size]={3,1,7,10}; printMatrix(data,size); getch(); } void printMatrix(int Matrix[],int size) {for(int i=0;i<size;i++) cout<<setw(5)<<Matrix[i]; }

Exercise on Processing One Dimensional Array using Function By using a program in previous slide, add a function called findLowest that will receive an array and size and return the lowest number of an array. You should display an output in the main program.

Printing an Array(Two Dimensional Array) using Function void printMatrix(int Matrix[][numOfCol],int numOfRows,int NumOfCol); void main() {const int numOfRows=4; const int numOfCol=3; int data[numOfRows][numOfCol]={{3,1,7},{4,8,10}, {12,9,5},{7,1,4}}; printMatrix(data,numOfRows,numOfCol); getch(); }

Printing an Array(Two Dimensional Array) using Function(continued) void printMatrix(int Matrix[][numOfCol],int numOfRows,int numOfCol) { for(int r=0;r<numOfRows;r++) {for(int col=0;col<numOfCol;col++) cout<<setw(5)<<Matrix[r][col]; cout<<endl; }

Exercise on Processing Two Dimensional Array using Function Add a function called findAverage that will receive an array,number of rows and number of column and display the average for the second column(in the function).

Processing Two Dimensional Arrays (c-String) void printMatrix(char Matrix[][numOfCol],int numOfRows, int numOfCol); int calcNor(char Matrix[][numOfCol],int numOfRows, int numOfCol); void main() { const int numOfRows=3; const int numOfCol=10; char data[numOfRows][numOfCol]={{“narina”},{“nora”},{“ahmad”}}; int numOfNor; printMatrix(data,numOfRows, numOfCol); numOfNor=calcNor(data,numOfRows, numOfCol); cout<<"\nNumber of nor are:"<<numOfNor; getch(); } void printMatrix(char Matrix[][numOfCol],int numOfRows, int numOfCol) { for(int row=0;row<numOfRows;row++) cout<<Matrix[row]<<" "; } int calcNor(char Matrix[][numOfCol],int numOfRows, int numOfCol) { int countNor=0; for(int row=0;row<numOfRows;row++) if((Matrix[row][0]=='n')&& (Matrix[row][1]=='o')&& (Matrix[row][2]=='r')) countNor++; return countNor; }

Exercise on Processing Two Dimensional Arrays Write a program to declare an integer array declared as data[5][6] in main program. From the array, write a function that will: 1.Input all the data into an array. 2.Display all the content of an array. 3.Find and display the sum and average of the entire array. 4.Find and return the largest value in third row. 5.Find an display the sum value for each row. Call a function in main program and display an appropriate output.