0% found this document useful (0 votes)
8 views15 pages

Agapay TN08 M2-Forma Arrays

The document outlines a laboratory exercise for a Computer Programming 2 course focused on arrays in C++. It includes program outcomes, course learning outcomes, intended learning outcomes, background information on arrays, and various activities for students to implement and practice array concepts. Additionally, it addresses the importance of arrays in programming and provides references for further reading.

Uploaded by

maxmishalan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

Agapay TN08 M2-Forma Arrays

The document outlines a laboratory exercise for a Computer Programming 2 course focused on arrays in C++. It includes program outcomes, course learning outcomes, intended learning outcomes, background information on arrays, and various activities for students to implement and practice array concepts. Additionally, it addresses the importance of arrays in programming and provides references for further reading.

Uploaded by

maxmishalan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

COLLEGE OF COMPUTER STUDIES

CCS007L
(COMPUTER
PROGRAMMING 2)

EXERCISE

2
ARRAYS

Student Name / Marcus Agapay


Group Name:
Name Role

Members (if
Group):
TN08
Section:
Alejandro Legazpi
Professor:
I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY
EXERCISE

 Analyze a complex problem and identify and define the computing


requirements appropriate to its solution. [PO: B]
 Design, implement and evaluate computer-based systems or
applications to meet desired needs and requirements. [PO: C]

II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE


LABORATORY EXERCISE

 Select and apply appropriate program constructs in developing computer


programs. [CLO: 2]
 Develop, test and debug computer programs based on a given
specification using the fundamental programming components. [CLO:
3]

III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY


EXERCISE

At the end of this exercise, students must be able to:

 Emphasize the importance of arrays in creating C++ programs.

 Implement arrays in C++ programs in solving computing problems.

IV. BACKGROUND INFORMATION

An array is a container object that holds a fixed number of values of a


single type. The length of an array is established when the array is
created. After creation, its length is fixed.

CCS007L-Computer Page 2
An array consists of a name and the number of elements of the array.
You can refer to a specific array element by the array name and the
element number, which is known as the index number. Array index
element number always starts with 0(zero).

Each item in an array is called an element, and each element is accessed


by its numerical index. The 9th element, for example, would therefore be
accessed at index 8.

Advantages of using Arrays

CCS007L-Computer Page 3
1. You can refer to a large number of elements by just specifying the
index number and the array name.
2. Arrays make it easy to do calculations in a loop.

The various types of arrays in C++ are:


• One-dimensional arrays
• Multi-dimensional arrays

A. One-Dimensional Arrays

One-dimensional array is a list of variables of the same data type.

Declaring Arrays

A typical declaration for an array in C++ is:

data_type array_name[no. of elements];

Initializing Arrays

In both cases, local and global, when we declare an array, we have the
possibility to assign initial values to each one of its elements by enclosing
the values in braces { }.

data_type

array_name[n]={val[0],val[1],..,val[n

-1]}; Where n is the number of

elements
For example:
int num[5] = { 16, 2, 77, 40, 120 };
char word[3]={‘J’,’A’,’Y’};

Accessing the Values of an Array

The format is as simple as:

CCS007L-Computer Page 4
array_name[index] or
variable_object_identifier=array_n
Examples:
ame[index];
y=
Number[0];
x=
Pressure[8];
letter =
Word[1];

Assigning Values to an Array

CCS007L-Computer Page 5
The format is as simple as:
array_name[index]=elem
ent value;
Examples:
Number[0]=-5;
Traffic[1]=“Green”;
Word[1]=‘J’;

B. Multidimensional Arrays

In additions to one-dimensional arrays, you can create two-


dimensional arrays. To declare two- dimensional arrays, you need to
specify multiple square brackets after the array name. Multidimensional
arrays can be described as "arrays of arrays".

A two dimensional array has two subscripts/indexes. The first


subscript refers to the row, and the second, to the column. Its
declaration has the following form:

data_type array_name[row][column];

For examples:
int x[3][4];
float matrix[20][25];

The first line declares x as an integer array with 3 rows and 4


columns and the second line declares a matrix as a floating-point array
with 20 rows and 25 columns.

Accessing Elements in Two-Dimensional Array

Accessing an element in a multidimensional array has the following

CCS007L-Computer Page 6
form:

array_name[row_index][column_index];

For example, the way to reference the second element vertically and

fourth horizontally in an expression would be:

V. LABORATORY ACTIVITY

ACTIVITY 2.1: Even and Its Position

CCS007L-Computer Page 7
Write a program that identifies the position of all even numbers in

an array of 10 elements. Sample Output:


Enter 10 numbers: 4 6 7 9 11 13 15 16 20 23
Even numbers are located at indices: 0 1 7 8

Program: (save as [surname_2_1.cpp])

Output:(screenshot of the output)

ACTIVITY 2.2: Sorting Values in an Array

Write a program that will ask the user to enter the size of the array n <
100. Once the array size is validated, it is required that the user will enter

the elements of the array. Finally, display the sorted array elements using

CCS007L-Computer Page 8
any sorting algorithm from smallest to greatest.

Sample Output:
Enter the size of the
array: 4 Array element
1: 6
Array element 2: 4
Array element 3: 5
Array element 4: 2
The sorted array is: 2 4 5 6

Program: (save as [surname_2_2.cpp])

CCS007L-Computer Page 9
Output:(screenshot of the output)

ACTIVITY 2.3: Finding Vowels and Whitespaces

Write a program that counts the number of vowels and whitespaces in a

CCS007L-Computer Page 10
all capital letters only.

Sample Output:
Enter a string: WELCOME TO
A 2
E 2
I 0
O 2
U 0
Whitespaces – 2

Program: (save as [surname_2_3.cpp])

CCS007L-Computer Page 11
Output:(screenshot of the output)

CCS007L-Computer Page 12
VI. QUESTION AND ANSWER

Directions: Briefly answer the questions below.

CCS007L-Computer Page 13
 Why is it necessary, being a programmer, to use arrays? What are the
risks of not using arrays?
Arrays are critical for managing multiple related values efficiently,
allowing for organized code, quick indexed access, and streamlined
operations such as sorting and searching. Without arrays, code becomes
cluttered, harder to maintain, and less scalable, leading to inefficient
memory use and error-prone programming.

 When is two-dimensional or multidimensional array used in a


program? These arrays are particularly useful when the data has a
natural structure that can be represented in multiple dimensions,
making it easier to manage and manipulate the data in a program.

VII.REFERENCES
 Abraham (2015). Coding for dummies. John Wiley and Sons: Hoboken, NJ
 Zak, D (2015). An Introduction to Programming with C++. 8th Edition
 Cadenhead, R et. Al. (2016). C++ in 24 Hours, Sams Teach Yourself (6th
Edition).Sams Publishing
 McGrath, M. (2017). C++ programming in easy steps (5th ed.).
Warwickshire, United Kingdom: Easy Steps Limited

 Tale, T. (2016). C++: The Ultimate Beginners Guide to C++


Programing. CreateSpace Independent Publishing Platform
 http://cs.uno.edu/~jaime/Courses/2025/devCpp2025Instructions.html

CCS007L-Computer Page 14

You might also like