0% found this document useful (0 votes)
55 views

Laboratory Activity 7

The document describes exercises involving one-dimensional arrays in C++. It includes the narrative, pseudocode, and flowchart for a program that takes in 10 integers from the user and outputs statistics about the even and odd numbers. It also includes a second exercise where two arrays A and B of 10 elements each are defined, and a third array C is created by adding the elements of A and B together. Questions are provided about the variables, outputs, and observations from running the programs. Supplemental activities define additional arrays and variables to practice array operations.

Uploaded by

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

Laboratory Activity 7

The document describes exercises involving one-dimensional arrays in C++. It includes the narrative, pseudocode, and flowchart for a program that takes in 10 integers from the user and outputs statistics about the even and odd numbers. It also includes a second exercise where two arrays A and B of 10 elements each are defined, and a third array C is created by adding the elements of A and B together. Questions are provided about the variables, outputs, and observations from running the programs. Supplemental activities define additional arrays and variables to practice array operations.

Uploaded by

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

Jayson M.

Lapada
CPE 223
LABORATORY ACTIVITY NO.7

ARRAY
(One-Dimensional Array)
EXERCISE No.1

Martin wants to create a program that requires the user to input 10 integers then print the total
number of even integers, highest even integer, lowest even integer, total number of odd integers,
highest odd integer, and lowest odd integer. If, however, the user inputs zero (0), the program will
display “You have not yet entered 10 integers.”
Below is the sample output of the program Martin created.
Enter the integers:
Integer 1: 15
Integer 2: 9
Integer 3: 71
Integer 4: 35
Integer 5: 17
Integer 6: 13
Integer 7: 63
Integer 8: 33
Integer 9: 97
Integer 10: 13
Total number of even integers : 0
Highest even integer : none
Lowest even integer : none
Total number of odd integers : 10
Highest odd integer : 97
Lowest odd integer :
1. Write the corresponding algorithm
a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given problem.
3. Construct the program and record your screen display result

NARRATIVE
Step 1: Input 10 integers integer.

Step 2: Differentiate which is the Step 4: Find the total number of


odd and even from the inputted integers.
odd integers, highest odd integer and lowest odd
Step 3: Find the total number of integer.
Step 5: Display results
even integers, highest even integer and lowest
even
PSEUDOCODE
Start

- Input int1, int2, int3, int4, int5, int6,

int7 int8, int9 and int10.

- Differentiate which is the

odd and even from the

inputted integers.

- Find the total number of even

integer and lowest even even integers, highest even

integer.

- Find the total number of odd

integer and lowest odd integers, highest odd

integer.

- Display Results
END
FLOWCHART

DISPLAY RESULTS
QUESTIONS

1. What conditional operation is requires producing counting the even numbers? In my program
syntax, I used for loop in checking upon the entered even integers and the if statement for
checking true value of for loop.

2. What conditional operation is requires producing counting the odd numbers? In my program
syntax, I used for loop in checking upon the entered odd integers and the if statement for checking
true value of for loop.

3. What are the variables needed to produce the desired output? The variable need to produce the
desired output are the array of integers which will which will be used in order to identify odd and
even using for loop and if-else statements

4. What did you observe in arranging the numbers in ascending order? I have observed that
whenever we want to arrange the numbers in ascending order, we must iterate from arr[1] to arr[n] over
the array, then compare the current element to its predecessor. If the key element is smaller than its
predecessor, compare it to the elements before. Move the greater elements one position up to make space
for the swapped element.

5. What did you observe in arranging the numbers in descending order? I have observed that in
arranging numbers in descending order, we need to sort the Array opposite on what we are doing
in arranging numbers in ascending order.
EXERCISE No. 2

Sam wants to create a program that required 20 integers. Suppose the following numbers are
the value input as A[10] = {-10, 20, 30, 40 ,– 50, -60, -70, 30, 90, 10} and B[10] = {15, 12, 13,14, –
50, -60, -20, 25, 35, 30}.
1. Write the corresponding algorithm
a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given problem.
3. Construct the program and record your screen display result

int count, sum=0; for (count = 0; count <=9 ;

count ++)

{ c[count] = b[count] + a[count];

cout << c[count] ; }

Narrative
- Sam need size 20 of integers
- First Sam needs to create a basket where the integers will be stored
- By declaring basket a and b
-Second Sam need to show the stored item in the basket
-By using a loop we can now output each item stored in the basket

Pseudocode
-Start
int size to 10
Array a[size] = {input value};
Array b[size]= {input value};
for count = 0; count<size: count ++
print a[count];
endfor
for count = 0; count<size: count ++
print b[count];
endfor
-Stop
FLOWCHART
DISPLAY RESULT
QUESTIONS

1. Refer to exercise no. 2, what is the value count [5]? -100

2. Refer to exercise no. 2, what is the value count [7]? -90

3. What Refer to exercise no. 2, what is the output of the program if count is change to
minus 5? 25 1843102131 32796 1095501703 65316 5 32 43 54 -100 -120 -90 55
125 40

4. What Refer to exercise no. 2, what is the output of the program if count is change to
minus 2? -1513526217 65325 5 32 43 54 -100 -120 -90 55 125 40

SUPPLEMENTAL ACTIVITIES

1. The value of variables are A, B, n and m. Assuming n =5 and m =5. What will be the
output of x if A[10] = {-1, -2, -3, -4 ,– 5, -6, -7, -8, -9, -10} and B[10] = {1, 2, 3,4, 5, 6, 7,
8, 9, 10}?

int c, x, n, m, d ;
for (c = 0; c <= n ; c++ {
for (d = 0; d <= m ;
d++ { x = A[c] * B[d];
cout << x << "\t”;}
cout << "\n”; }

Write your answer. No output; Invalid Syntax format

2. Refer to No. 1, what is the value of x if c[2] , d[3], n= 5 and m= 5 ?

Write your answer. No output; Invalid Syntax format


3. Refer to No. 1, what is the value of x if c[8], d[8] n=9 and m= 5

Write your answer. No output; Invalid Syntax format

6. Conclusion:

I there for conclude that is the simplest form of an Array in which the
elements are stored linearly and can be accessed individually by specifying
the index value of each element stored in the array. And doing exercises
improves my skills in assessing and it improves my logical thinking

You might also like