Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.

Slides:



Advertisements
Similar presentations
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
Advertisements

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 29P. 1Winter Quarter Software Design Project.
An Introduction to Programming with C++ Fifth Edition
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition P. 1Winter Quarter Daily Assignment A21 A21 asks.
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
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.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 13P. 1Winter Quarter Scope of Variables.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review Topics.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 15P. 1Winter Quarter Arrays and Pointers.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
IE 212: Computational Methods for Industrial Engineering
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
A First Book of ANSI C Fourth Edition
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.
 Pearson Education, Inc. All rights reserved Arrays.
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.
 Pearson Education, Inc. All rights reserved 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.
Pemrograman Dasar Arrays PTIIK - UB. Arrays  An array is a container object that holds a fixed number of values of a single type.  The length of an.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
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.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 7P. 1Winter Quarter File I/O in C Lecture.
© 2004 Pearson Addison-Wesley. All rights reserved October 13, D Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor:
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration Lecture 23.
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.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions Lecture 12.
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.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
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.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Computer Programming for Engineers
Arrays.
Arrays An array is an indexed data structure which is used to store data elements of the same data type. An array is an indexed data structure which is.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
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.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Opening Input/Output Files ifstream infile; ofstream outfile; char inFileName[40]; char outFileName[40]; coutinFileName;
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
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.
Arrays. Arrays are objects that help us organize large amounts of information.
 2005 Pearson Education, Inc. All rights reserved 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)
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.
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.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Lesson 9 Arrays. Miscellaneous About Arrays An array is an object. Because of this, the array name is a reference variable Therefore, in order to start.
Presentation transcript:

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 2Winter Quarter What Is an Array? An array is a group of items of the same type under one variable name. It is an ordered list of elements where each is of the same data type. As an example, the days of the week can be represented as a one-dimensional array named day where Sunday is the first element, Monday the second, and so on.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 3Winter Quarter Representation

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 4Winter Quarter Thinking About Arrays The days of the month can be thought of as a two-dimensional array. Looking at a calendar, each row represents a week (which can be represented as a one-dimensional array), and the entire month is composed of an array of arrays, that is, a two-dimensional array.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 5Winter Quarter Arrays Taking the concept further, the days of the year can be represented as a three-dimensional array, that is, an array of arrays of arrays. The first dimension is the day of the week, the second the week of the month, and the third the month of the year.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 6Winter Quarter Declaring Arrays A one-dimensional array is represented by specifying the array name followed by a number in square brackets [ ] to indicate the array size (or number of elements). The statement: int day[ 7 ]; would declare a seven element array of integers. Declaring multi-dimensional arrays is similar: int month[ 4 ][ 7 ]; would declare an array of integers with 4 rows and 7 columns.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 7Winter Quarter Assigning Values to Arrays Once an array is declared, the elements are accessed by specifying the array name and the number of the element. In C, the first element is number 0, so a seven element array would have elements numbered 0 through 6. For the week of February 6th through the 12th, the array could be assigned as follows: day[0]=6; day[1]=7; day[2]=8; day[3]=9; day[4]=10; day[5]=11; day[6]=12; The number in the brackets is called an index (or a subscript).

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 8Winter Quarter Assigning Values to Arrays Optionally, the array can have values assigned to its elements when the array is declared. For example, the statement: int day[ 7 ] = {6, 7, 8, 9, 10, 11, 12} ; declares a seven element array day and initializes (assigns values to) all seven of the elements. The program on the next slide illustrates how that works.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 9Winter Quarter Program Example for Arrays /*The following program will declare the array day, assign values to the elements, and print the data to the screen. */ #include int main ( ) { int n, day[ 7 ] = {6, 7, 8, 9, 10, 11, 12} ; for (n = 0 ; n < 7 ; n++ ) { printf ("day[ %d ] is February %d, 2005 \n", n, day[n] ) ; }

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 10Winter Quarter Program Output of an Array When this program is run, it will produce the following output: day[0] is February 6, 2005 day[1] is February 7, 2005 day[2] is February 8, 2005 day[3] is February 9, 2005 day[4] is February 10, 2005 day[5] is February 11, 2005 day[6] is February 12, 2005

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 11Winter Quarter Another Program Example /* Program to generate an array of 10 random numbers */ #include #define SIZE 10/* SIZE defined as symbolic constant */ int main ( ) { int i, numbers [SIZE] ; for (i = 0 ; i < SIZE ; i++ ) { numbers[ i ] = rand ( ) ; printf ( "The number[ %d ] is %d \n", i, numbers[ i ]) ; }

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 12Winter Quarter Problem G10 There is a file in the common area (g10.dat) that you must copy to your directory. Your program will be reading wristpin diameters from that file. Your program must compute the average and the standard deviation for the wristpins. Suggestion: Copy the file and then write a short program in to read and display the data before working on the code for the average and the standard deviation

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 13Winter Quarter APPROACH Read in data from file and sum the values as read. Compute the average Use a 2 nd loop to compute the sum of the values – average square. Divide by n-1 Take square root You now have s, the standard deviation!!! –SMILEY FACE!