Академический Документы
Профессиональный Документы
Культура Документы
C++
03/16/15
Outline
Introduction
Arrays
Declaring Arrays
Examples Using Arrays
Assign
DEFINITION ARRAY
03/16/15
Array
03/16/15
Format:
arrayname[position number]
03/16/15
03/16/15
Array
# of elements Size of
Array
Definition
Element
Size
-------------------------------------------------------------------------char letters[25]; 251 byte25 bytes
short rings[100];1002 bytes200 bytes
int miles[84]; 844 bytes336 bytes
float temp[12]; 12 4 bytes48 bytes
double distance
1000 8 bytes8000 bytes
[1000];
DECLARING ARRAYS
03/16/15
Name
Type of array
Number of elements
arrayType arrayName[numberOfElements];
Examples:
int c[10];
float myArray[3284];
Declaring multiple arrays of same type
int b[ 100 ], x[ 27 ];
Initializers
int n[5] = { 1, 2, 3, 4, 5 };
All elements 0
03/16/15
#include <iostream>
{
double distance[] = {44.14, 720.52, 96.08, 468.78, 6.28};
cout << "2nd member = " << distance[1] << endl;
cout << "5th member = " << distance[4] << endl;
system (pause);
return 0;
}
03/16/15
CREATING AN ARRAY
USING LOOPING
STATEMENT
# include <iostream>
int main ()
{
int arrayVar [9];
for (int Var = 0; Var<=8; Var+=2)
{
arrayVar [Var] = 90;
cout << Var<< " ---- " <<
arrayVar[Var]<<endl;
}
system ("pause");
return 0;
}
10
03/16/15
#include <iostream>
{
char Color[] = { 'B', 'l', 'a', 'c', 'k' };
char Country[] = "Philippines";
cout << "Color = " << Color << endl;
cout << "Country = " << Country;
system ("pause");
return 0;
}
11
TRY THIS!
03/16/15
rectangle[0]
= length
rectangle[1] = width
rectangle [2] = area
12
ASSIGN (FINALS)
03/16/15
13