Module Week 9

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Computing Fundamentals (Programming Logic and Design) 1

Array

Module 8 Week 9 Array

Course Learning Outcomes:


1. To learn about storing data in array.
2. To learn about how to use constant with arrays.

Data Storing in Array


A sequence of values in computer memory is an Array.
Frequently, an array has somewhat similar in all values of it. It may
embody any record of customers profile or bank account number. Every
time you require a various storage location for an object, you may use
an actual equivalent of an array in programming. Keeping significant
documents in a folder and you labeled every folder alphabetically, then
it is the same with the idea of an array. Likewise, planning what to take
course for the next semester by means of scanning choices of courses
open, then it is also an array.

Array Occupying Computer Memory

Asserting an array is also declaring a structure that covers


multiple data items. One element of the array is a data item. Every data
type has a similar element on it. Succeeding to it, each element lodges a
range in the computer memory linking to another. Considering the
amount of the elements an array can hold, and the array’s size and
stating the constant and variables along with the array.

Course Module
Figure 1

A subscript or index is the number values that show the exact


location of the item inside an array. And every array element differs
from one another. A subscript represents the distance from the initial
element and every single element had a unique subscript. Nonetheless,
entirely of all array elements have the similar group name. Thus, every
subscripts of an array are constantly an integer’s sequence.

Using Constants with Arrays

You can use constants in numerous habits when working with


arrays:
• Holding array’s size
• Array’s values
• As subscript

1. Constant as Array’s size

Naming a constant in its right place then the program you


are creating is improving. Your program code will be easier
to understand and modify if we will have a constant name.
Mostly of the languages, use one of these two methods:

✓ Declaring a named number constant like


SIZE_ARRAY = 19. You can use this sample
constant every single time you enter an array,
continually making sure any subscript you use
remains lesser than the continuous value.

✓ Several languages, the array size signifies a


constant and had routinely provided for each array
Computing Fundamentals (Programming Logic and Design) 3

Array

you made. Example, in Java, after you state an


array named count, its size is kept in a field name.

2. Constants as Element Values of an Array

Occasionally, constants should be kept in values of an


array since they not change during the execution of the
program. Assuming that you make an array and it should hold
names for the months. Don’t make it complicated for the
array identifier with its content. The array of the name of the
month can be stated like the following:

string monthName[12] = "January", "February",


"March", "April", "May", "June", "July",
"August", "September", "October", "November",
"December"

3. Array Subscript as a Constant

Not often you need to create unnamed number constant


as an array’s subscript. Sample of it is to show the initial value
in array named amountArray, the following statement below
is an example of an unnamed literal constant:

output amountArray[0]

You will also encounter a case to use a named constant as


a subscript. For instance, if amountArray holds tax amount in
every 10 cities covered by your company, and Manila is city
3, the value for Manila is as follows:

output amountArray[3]

Course Module
References and Supplementary Materials
Books and Journals
1. Joyce Farrell (2012) Programming Logic and Design; Comprehensive version

Online Supplementary Reading Materials


1. Array in Programming https://www.toolsqa.com/data-structures/array-in-
programming/ April 2020

You might also like