Engineering Problem Solving with C Etter Chapter 6
Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays 9/17/2020 Engineering Problem Solving with C++, Second Edition, J. Ingber 1
One Dimensional Arrays 4 Sorting Algorithms 4 Searching Algorithms 4 Character Strings 4 The string Class. 9/17/2020 Engineering Problem Solving with C++, Second Edition, J. Ingber 2
Definition and Initialization Computation and Output Function Arguments ARRAYS 9/17/2020 Engineering Problem Solving with C++, Second Edition, J. Ingber 3
Definition 4 An array is a data structure for storing a contiguous block of data. 4 All data elements in an array must be of the same type. 4 Individual elements of the array are specified using the array name and an offset. 4 In C++ the offset of the first element is always 0. 9/17/2020 Engineering Problem Solving with C++, Second Edition, J. Ingber 4
Definition and Initialization 4 Syntax: data_type identifier[size] [= initialization list]; Note: size is an integer constant. 4 Example: double m[8]; m[0] m[1] m[2] m[3] m[4] m[5] m[6] m[7] ? ? ? ? 9/17/2020 Engineering Problem Solving with C++, Second Edition, J. Ingber 5
Initializing Arrays 4 Initializing array elements (initialization=>declaration) char vowels[5] = {'a', 'e', 'i', 'o', 'u'}; bool ans. Key[] ={true, false, true, false}; char word[] = "Hello"; vowels 'a' 'e' ans. Key true word 'H' 'e' 9/17/2020 'i' 'o' false true 'l' 'u' false 'o' Engineering Problem Solving with C++, Second Edition, J. Ingber '