《C++程序设计》(英文版) Chapter 12 Topic

Programming in c++ Arrays Dale/eems/Headington
1 Arrays

Programming in C++ Chapter 12 Topics One-Dimensional Arrays s Using const in Function Prototypes s Using an Array of struct or class Obiects Using an enum Index Type for an Array s Special Kinds of Array Processing s& Two-Dimensional Arrays s Passing Two-Dimensional Arrays as Arguments Another Way of Defining Two-Dimensional Arrays Multidimensional Arrays
2 Chapter 12 Topics ❖One-Dimensional Arrays ❖Using const in Function Prototypes ❖Using an Array of struct or class Objects ❖Using an enum Index Type for an Array ❖Special Kinds of Array Processing ❖Two-Dimensional Arrays ❖Passing Two-Dimensional Arrays as Arguments ❖Another Way of Defining Two-Dimensional Arrays ❖Multidimensional Arrays

Programming in C++ C++ Data Types simple structured integral enum floating array struct union class char short int long bool float double long double address pointer reference
3 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long double

Programming in C++ Structured Data Type A structured data type is a type that o stores a collection of individual components with one variable name o and allows individual components to be stored and retrieved
4 Structured Data Type A structured data type is a type that ❖stores a collection of individual components with one variable name ❖and allows individual components to be stored and retrieved

Programming in C++ Declare variables to store and total 3 blood pressures int bp1, bp2, bp3 int total 4000 4002 4004 bp1 bp2 bp3 cin >>bp1 > bp2 > bp3 total s bp1+ bp2+ bp3;
5 Declare variables to store and total 3 blood pressures int bp1, bp2, bp3; int total; 4000 4002 4004 bp1 bp2 bp3 cin >> bp1 >> bp2 >> bp3; total = bp1 + bp2 + bp3;

Programming in C++ What if you wanted to store and total 1000 blood pressures? int bp[ 10001 M/ declares an array of 1000 int values 5000 5002 5004 5006 bp[o] bp[1l bp[2 bp999]
6 What if you wanted to store and total 1000 blood pressures? int bp[ 1000 ] ; // declares an array of 1000 int values bp[0] bp[1] bp[2] . . . . bp[999] 5000 5002 5004 5006 . . .

Programming in C++ One-Dimensional Array Definition An array is a structured collection of components (called array elements), all of the same data type, given a single name, and stored in adjacent memory locations The individual components are accessed by using the array name together with an integral valued index in square brackets The index indicates the position of the component within the collection
7 One-Dimensional Array Definition An array is a structured collection of components (called array elements), all of the same data type, given a single name, and stored in adjacent memory locations. The individual components are accessed by using the array name together with an integral valued index in square brackets. The index indicates the position of the component within the collection

Difference Between Array and++ Programming in C Struct or class o As array is a structure, an array differs from struct or class in two fundamental was 1. An array is a homogeneous data structure whereas structs and classes are heterogeneous types 2. A component of an array is accessed by its position in the structure, whereas a component of a struct or class is accessed by an identifie
8 Difference Between Array and Struct or class ❖As array is a structure, an array differs from struct or class in two fundamental was: 1. An array is a homogeneous data structure,whereas structs and classes are heterogeneous types. 2. A component of an array is accessed by its position in the structure, whereas a component of a struct or class is accessed by an identifier

Programming in C++ Another Example o Declare an array called temps which will hold up to 5 individual float values number of elements in the array float temps 5]; //declaration allocates memory Base Address 7000 7004 7008 7012 7016 tem ps[o temps[1] temps[2 temps[3 temps[41 indexes or subscripts 9
9 Another Example ❖Declare an array called temps which will hold up to 5 individual float values. float temps[5]; // declaration allocates memory temps[0] temps[1] temps[2] temps[3] temps[4] 7000 7004 7008 7012 7016 number of elements in the array indexes or subscripts Base Address

Programming in C++ Declaration of an Array oo the index is also called the subscript o in C++, the first array element always has subscript 0. The second array element has subscript 1, etc the base address of an array is its beginning address in memory SYNTAX Data Type ArrayName [ConstIntExpression 10
10 Declaration of an Array ❖the index is also called the subscript ❖in C++, the first array element always has subscript 0. The second array element has subscript 1, etc. ❖the base address of an array is its beginning address in memory SYNTAX DataType ArrayName [ConstIntExpression];
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《C++程序设计》(英文版) Chapter 11 Topics.ppt
- 《C++程序设计》(英文版) Chapter 10 Topics.ppt
- 《C++程序设计》(英文版) Chapter 9 Topics.ppt
- 《C++程序设计》(英文版) Chapter 8 Topics.ppt
- 《C++程序设计》(英文版) Chapter 7 Topics.ppt
- 《C++程序设计》(英文版) Chapter 6 Topics.ppt
- 《C++程序设计》(英文版) Chapter 5 Topics.ppt
- 《C++程序设计》(英文版) Chapter 4 Topics.ppt
- 《C++程序设计》(英文版) Chapter 3 Topics.ppt
- 《C++程序设计》(英文版) Chapter 2 Topics.ppt
- 《C++程序设计》(英文版) Chapter 1 Topics.ppt
- 《网络互连技术教程》第9章 广播.ppt
- 《网络互连技术教程》第8章 用户数据报协议—UDP.ppt
- 《网络互连技术教程》第7章 CMP和网络状态.ppt
- 《网络互连技术教程》第6章 地址解析.ppt
- 《网络互连技术教程》第5章 子网与超网.ppt
- 《网络互连技术教程》第4章 网络互连协议——IP.ppt
- 《网络互连技术教程》第3章 网络接入技术.ppt
- 《网络互连技术教程》第2章 网络互连体系.ppt
- 《网络互连技术教程》第1章 网络的历史与发展.ppt
- 《C++程序设计》(英文版) Chapter 13 Topics.ppt
- 《C++程序设计》(英文版) Chapter 14 Topics.ppt
- 《C++程序设计》(英文版) Chapter 15 Topics.ppt
- 《Java编程技术基础》第一章 面向对象原理与实现.ppt
- 《Java编程技术基础》第二章 Java的实现基础.ppt
- 《Java编程技术基础》第二章习题.doc
- 《Java编程技术基础》第三章 类与对象(一).ppt
- 《Java编程技术基础》第三章习题.doc
- 《Java编程技术基础》第四章 类与对象(二).ppt
- 《Java编程技术基础》第四章习题.doc
- 《Java编程技术基础》第五章 异常与垃圾收集.ppt
- 《Java编程技术基础》第五章习题.doc
- 《Java编程技术基础》第十一章 Java集合框架.ppt
- 《Java编程技术基础》第十一章习题.doc
- 《Java编程技术基础》第二章 JDBC.ppt
- 武汉外语外事职业学院:《VisualBasic语言程序设计教程》第二版 第14章 图形处理.ppt
- 武汉外语外事职业学院:《VisualBasic语言程序设计教程》第二版 第3章 窗体.ppt
- 武汉外语外事职业学院:《VisualBasic语言程序设计教程》第二版 第5章 Visual Basic语法基础.ppt
- 武汉外语外事职业学院:《VisualBasic语言程序设计教程》第二版 第6章 顺序结构.ppt
- 武汉外语外事职业学院:《VisualBasic语言程序设计教程》第二版 第7章 选择结构.ppt