Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 05 ARRAY 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Chapter 7: Arrays In this chapter, you will learn about
Arrays.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
1 Arrays in JavaScript Name of array (Note that all elements of this array have the same name, c ) Position number of the element within array c c[6] c[0]
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
1 Lecture 9  Arrays  Declaration  Initialization  Applications  Pointers  Declaration  The & and * operators  NULL pointer  Initialization  Readings:
 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.
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Arrays--data structure. Arrays 7 zConsider how you would store five integer values in the memory of the computer. zOne way to do this is to create five.
Arrays in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR
 2006 Pearson Education, Inc. All rights reserved Arrays.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Chapter 7 One-Dimensional Arrays 7.1 Arrays in C One of the more useful features of C is the ability to create arrays for storing a collection of related.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
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.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
Computer Programming Lecture 8 Arrays. 2 switch-statement Example (3) If use press left arrowIf use press right arrow If use press up arrow If use press.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 07 classes 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 06 FUNCTIONS 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
FP201 - PROGRAMMING FUNDAMENTALS Unit Understand the use of array PREPARED BY: MAZNAH AHMAD, JTMK PSIS.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Arrays.
Arrays.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 04 loops 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
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.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Introduction to programming in java Lecture 21 Arrays – Part 1.
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.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Array in C# Array in C# RIHS Arshad Khan
Two-Dimensional Arrays
Computer Programming BCT 1113
Two Dimensional Array Mr. Jacobs.
Lecture 12 Oct 16, 02.
Introduction To Programming Information Technology , 1’st Semester
Multidimensional Arrays
MSIS 655 Advanced Business Applications Programming
Arrays Arrays A few types Structures of related data items
C++ Array 1.
Presentation transcript:

Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 05 ARRAY 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1

ARRAYS An array is a sequence of objects of same data type. The objects in array are also called elements of array. Array is represented in the computer memory by consecutive group of storage location. These location are referred by single variable called array name. Each element of an array is referred by its position in the array. 2

Continue…… The position of an element in an array is represented by an index value or subscript. in an array with ‘n’ elements, the index value are 0,1,2….n-1. where 0 represent the index value of first element and n-1 represent the index value of last value. 3

Conti….. An element of an array is accessed by its subscript value. The subscript or index value is written inside a pair of square brackets [ ] with the name of the array. An element of the array is referred by specifying name of the array and the index value of the element. 4

Continue…. Array are used to process a large amount of data of same type. The data is stored in an array. The array is accessed by a single variable name. The index value are used to access individual elements of the array. A few statements are required to process data in an array. Therefore,the use of arrays in a program reduce size of the program. 5

Continue……. Arrays are divided into two types. These are 1.One-dimensional array. 2.Multidimensional array. 6

One dimensional array.. One dimensional array is also known as a list or a linear array. It consists of only one column or one row. For example,the temperature of each hour of a day is stored in an array.The name of array ia “temp” and its elements are temp[0],temp[1],temp[2] temp[3]…………temp[23]. 7

Continue…….. Temp[0]22.3 Temp[1]23.1 Temp[2]19.2 Temp[3] Temp[23]20.0 8

Declaring one dimensional array Like the variable,an array is also declared. Defining the name of array, its type and total number of elements of an array is called declaring of array. when an array is declared,a memory block with required number of location is reserved in the computer memory for storing the data into elements of the array. 9

Continue….. The general syntax to declare a one dimensional array is : type array-name [n]; where “n” is an unsigned integer value. It represents the total number of elements of array. To declare an array of 24 elements the statement is int temp[24]; 10

Accessing data in array Each element of an array is referred by its index. In an array of n elements,each element has an index value. the index of the first element is 0 and of the last element is n-1. The index value is written within square bracket after the array name. 11

Conti…. Thus the first element of an array temp is referred as temp [0].similarly,the element of an array temp of n elements is referenced as temp[n-1]. 12

Input /output data in arrays Input/output statements is used to access data in each element of the array, the statement is written once and loop structure is used to repeat the input/output statement to access data of the elements of the array. 13

Initializing array Like the variable the value in the elements of an array can also be assigned when the array is declared. The assigning of value to the elements of the array at the time of its declaration is called initializing of array. 14

Conti… For example,to declare an array “temp” of type double with 5 elements with values 66.3,77.7,99.8,63.9 and 59.3 in elements temp[0],temp[1],temp[2],temp[3],temp [4] respectively. The statement is written as: double temp[5]= {66.3,77.7,99.8,63.9,59.3 } 15

program #include Void main() { int a[5]; int i; a[0]=6; a[1]=45; a[2]=33; a[3]=56; a[4]=45; for (i=0;i<=4;i++) cout<<“value in a [i]=“<<a [i]; getch(); } 16

Program #include Void main() { int temp[7]; int sum; int days; for (day=0;day<7;day++) { cout<<“Enter temperature for day:”<<endl; cin>>days; } sum=0; for (day=0;day<7;day++) sum+=temp[day]; cout<<“average temperature is ”<<sum/7; getch(); } 17

program #include void main() { clrscr(); double temp[5]= {66.3,77.7,99.8,63.9,59.3 } int i; for (i=0;i<=4;i++) cout<<temp[i]; getch(); } 18

Two dimensional array A two dimensional array consists of column and row. Each element of the two dimensional array is referenced by its index values or subscripts. The index value of two dimensional array consists of two subscripts. One subscript represents the row number and the second subscript represents the column number. 19

Declaration of two dimensional array A two dimensional array is declared by giving two indexed values enclosed in square brackets. the first value represents the total number of rows and the second represents the total number of columns. 20

conti……… The syntax to declare a two dimensional array. type array name [r][c]; type: represent data type of array. array name: represent the name array. r: represents total number of rows of table. c: represents the total number of columns. int abc [12][3]; 21

#include void main() { int xyz[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; clrscr(); int r,c; for ( r=0; r <=2; r++) { for ( c=0; c<=3; c++) { cout<<xyz[r][c]<<"\t"; } cout<<endl; } getch(); } 22

Program to input data into array of strings #include Void main() {clrscr(); char A[5][5]; int c; for (c=0;c<4;c++) { cout<<“Enter string ”<<c+1<<“:”; cin>>A[c]; } for(c=0;c<4;c++) cout<<A[c]<<endl; getch(); } 23

. 24