Beruflich Dokumente
Kultur Dokumente
VENTURA
DATE:
EXPERIMENT 06
ARRAY
ONE DIMENSIONAL ARRAY OPERATION AND EXECUTION
❖ PROCEDURES
PROGRAM 01 : PROCEDURES
Page 1 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
PROGRAM 02 : PROCEDURES
Program 02
1 #include<iostream> 22 a = 0, i = 0;
2 #include<conio.h> 23 while(a<3)
3 using namespace std; 24 { for(b = 0, c = input[b]; b < valSize; b++)
4 25 { if(input[b]>c)
5 int main(void) 26 { c = input[b];
6 { int valSize, input[20], output[3] = { 0 }; 27 i = b;
7 int x, y, z, a, b, c, i; 28 }
8 29
9 cout<<"Input the number of elements: "; 30 output[a] = c;
10 cin>>valSize; 31 }
11 32
12 cout<<"\nInput the element values: \n"; 33 input[i] = 0;
13 for( x = 0; x<valSize; x++) 34
14 cin>>input[x]; 35 a++;
15 36 }
16 cout<<"\n\nYou have entered the following values: \n"; 37
17 for( y = 0; y<valSize; y++) 38 for(z = 0; z<=2; z++)
18 cout<<input[y]<<" "; 39 cout<<output[z]<<" ";
19 40 cout<<endl;
20 cout<<"\n\nResults: \n\t"; 41
21 42 getch();
43 return 0;
44 }
Page 2 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
❖ QUESTIONS
PROGRAM 01 : QUESTIONS
QP1.1. Fill up the required data on table TP1.1 by executing Program 01 and providing the series of inputs
below.
Table TP1.1
Output
No. Input
( Display on the Monitor Screen )
Programming
Ex. 65 65
3_
1 25
2 12
3 60
4 77
5 10
6 48
7 50
8 56
9 13
10 26
Page 3 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
QP1.3. Briefly discuss the importance of program line numbers 14 – 19 to the operation of the program.
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
QP1.4. How can you relate the value of variable x to the value extracted from the array numbers?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
QP1.5. What is the importance of the variable status in the operation of the program?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
QP1.6. What would be the effect in execution of the program if the loop condition in program line
number 14 is changed to x < 15 ? x < 10 ?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
Page 4 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
PROGRAM 02 : QUESTIONS
QP2.1. Fill up the required data on table TP2.1 by executing Program 02 and providing the series of inputs
below.
Table TP2.1
Inputs Output
No. Number of
Element Values ( Results )
Elements
19 18 17
Ex. 8 19 18 17 16 15 14 13 12
_
1 4 56 21 32 11
2 5 15 27 63 21 26
3 6 98 25 78 56 91 91
4 8 12 56 78 96 25 46 23 14
5 11 23 56 45 78 89 25 15 45 56 92 98
6 14 22 23 24 25 36 27 28 29 30 31 32 33 34 35
7 15 97 85 95 84 96 82 78 99 56 99 56 98 45 52 99
8 16 10 10 10 10 10 10 10 10 11 10 10 10 10 10 10 10
9 18 15 15 15 15 15 20 20 20 20 20 25 35 35 35 35 35 35 35
Note: If you want to test with different inputs other than the inputs given above, make sure to input only positive integral numbers.
QP2.3. Refer to program line 6, what is the meaning of the code: output[ 3 ] = { 0 }?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
Page 5 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
QP2.4. What is the importance of the variable c in the operation of the program?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
QP2.5. What is the importance of the code input[ i ] = 0; in program line 33 ? What is the effect on the
program when this code is deleted ?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
QP2.6. Briefly discuss the importance of program line numbers 12 – 14 to the operation of the program.
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
QP2.7. Briefly discuss the importance of program line numbers 38 – 40 to the operation of the program.
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
Page 6 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
❖ CHALLENGE PROGRAMS
Figure 01
3. Provide a copy of your source code on a separate paper. Follow proper format in documenting your
source code.
4. Modify the program. Change the element values of array numbers with the following values:
a. 55, 18, 29, 56, 95, 26, 16, 78, 56, 22, 48, 25, 58, 89, 67, 17, 27, 47, 62, and 64 respectively.
b. 90, 22, 48, 25, 58, 89, 67, 17, 27, 47, 62, 55, 18, 29, 56, 85, 26, 12, 78, and 28 respectively.
c. 15, 15, 15, 15, 15, 20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 12, 12, 12, 12, and 12 respectively.
d. 129, 256, 85, 26, 312, 22, 48, 25, 258, 56, 118, 89, 67, 117, 27, 447, 62, 55, 78, and 828
respectively.
Provide a screenshot for each given set of modified values on a separate sheet of paper.
Page 7 of 8
NATIONAL UNIVERSITY MANILA COMPUTER FUNDAMENTALS WITH PROGRAMMING ENGR. RAFAEL A. VENTURA
1. Create a program to find the lowest four elements in an array named Data. The input array must be at
least four elements in size, otherwise the program will return an “Invalid Input” error message.
Figure 02
3. Provide a copy of your source code on a separate paper. Follow proper format in documenting your
source code.
4. Test the reliability of your program by supplying the inputs( from no.1 up to no.6 only ) in Table TP2.1.
Provide a screenshot for each given set of inputs on a separate sheet of paper.
Page 8 of 8