Search . . .
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
CIS 102
COMPUTER
PROGRAMMING II
MULTI-DIMENSIONAL ARRAY
STEM
Winchester R. Gerez Workshop
Faculty, Department of Computer Science
VISIT OUR WEBSITE
[Link]
m
COLLEGE OF COMPUTING AND INFORMATION SCIENCES Department of Computer Science
COLLEGE OF COMPUTING AND INFORMATION Search . . .
SCIENCES
OBJECTIVES
Declaration,
Multi-dimensional C+ Initialization, Programming
+ Accessing Index Exercizes
and Array
Operations
COLLEGE OF COMPUTING AND INFORMATION SCIENCES Department of Computer Science
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
WHAT IS 3D DIMENSIONAL ARRAY?
• A 3D array is an extension of a 2D array, where elements are
organized in three dimensions.
• It can be visualized as a collection of 2D arrays, stacked together.
• Each element in a 3D array is accessed using three indices:
[depth][row][column].
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
STRUCTURE OF 3D ARRAY
• A 1D array is a list of elements:
1.→ arr[5] = {1, 2, 3, 4, 5}
• A 2D array is a table (grid) with rows
and columns:
1.→ arr[2][3] (2 rows, 3 columns)
• A 3D array is a collection of 2D tables
stacked together:
1.→ arr[3][3][3] (3 layers, 3 rows, 3
columns)
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
DECLARING A 3D ARRAY
• x represents the number of 2D arrays.
• y represents the number of rows.
• z represents the number of columns.
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
EXAMPLE
• arr is a 2x3x4 3D array (2 blocks, each containing a 3x4
matrix).
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
MEMORY LAYOUT OF 3D ARRAY
• arr is a 2x3x4 3D array (2 blocks, each containing a 3x4
matrix).
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
ACCESSING ELEMENTS IN A 3D
ARRAY
To access an element in a 3D array, use
the format:
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
TRAVESING 3D ARRAY
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
LECTURE ACTIVITY 1
Sum of Diagonals, Rows, and Columns in a 2D Array
Write a C++ program that calculates and displays:
✅ Sum of the main diagonal
✅ Sum of the secondary diagonal
✅ Sum of each row
✅ Sum of each column
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
LECTURE ACTIVITY 2
Write a C++ program that performs the following string operations:
• Declare and initialize an array of strings with at least five names.
• Display the length of each string using .length().
• Extract and display a substring from each string using .substr().
• Erase a portion of each string using .erase().
• Replace part of each string using .replace().
• Append a string to each name using .append().
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
COLLEGE OF COMPUTING AND INFORMATION
SCIENCES
LECTURE ACTIVITY 3
Activity 3: 3D Array Operations in C++
In this activity, you will work with 3D arrays and perform the following tasks:
• Declare and initialize a 3×3×3 3D array with predefined values.
• Find the sum of all elements in a 2×2×3 3D array.
• Modify the traversal program to print the elements in reverse order.
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
Get in
Touch
With
Send usUs
a message
or visit us
City of Batac, Ilocos Norte,
Philippines
(63) 77-600-0459
op@[Link]
Follow us for
updates
[Link]/MMSUofficial
[Link]