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

Exercises: Topic: Array

The document contains 21 multiple choice and coding questions about arrays in C++. It covers topics like declaring, initializing, accessing, and manipulating one and two dimensional arrays. Loops and calculations with array elements like finding averages are also addressed. The questions would need to be answered by writing C++ code to declare and manipulate arrays according to the given requirements and specifications.

Uploaded by

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

Exercises: Topic: Array

The document contains 21 multiple choice and coding questions about arrays in C++. It covers topics like declaring, initializing, accessing, and manipulating one and two dimensional arrays. Loops and calculations with array elements like finding averages are also addressed. The questions would need to be answered by writing C++ code to declare and manipulate arrays according to the given requirements and specifications.

Uploaded by

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

EXERCISES

TOPIC : ARRAY
1. Which of the following correctly declares an array?
a) int name[10];
b) int name;
c) name{10};
d) array name[10];

2. Identify the correct syntax to access the 25 element for the array named anarray with 25
elements.
e) anarray=+25
f) anarray[24]
g) anarray[25]
h) anarray[last]
3. Which is the correct statement for declaring and initializing an array?
int score[ ]={90, 88, 70, 89};
i. The size element of the array is 4.
ii. score[1]=90;
iii. The type of each element is integer
iv. The name of the array is score.

a) i and ii only
b) iii and iv only
c) i, iii and iv only
d) ii, iii and iv only
4. Analyze and find the value of num[0][1] and num[2][1] for two dimensional array below.
int num[3][2]={1,2,3,4,5,6};

a) 3,5
b) 2,3
c) 3,6
d) 2,6
5. The array cost holds the following data:

25.99 14.55 33.65 25.25 45.99 4.99 17.85

What is the value in the variable cost after the following statement is executed?
total = cost[4];

a) 4.99
b) 25.25
c) 33.65
d) 45.99
6. Which of the following shows the correct syntax to declare and initialize a four element char
array named block.
a) char block[4]={“a”,”b”,”c”};
b) char block[3]={‘a’,’b’,’c’,’d’};
c) char block[4]={‘a’ ’b’ ’c’ ’d’};
d) char block[4]={‘a’,’b’,’c’,’d’};

7. Determine which of the following statement is false of the declaration below.


char arr[30];
e) string array data type
f) [30] refer to the size of an array
g) The last index is 30
h) Contains 30 elements
8. Which code best refer to the statement below?
“Assign value 6 to Nombor array with index 10”
a) Nombor[6]=10;
b) Nombor[10]=6;
c) Nombor[ ]=6;
d) Nombor[6]={ };
9. Which of the following shows the correct declaration for beta in an array of 4 rows and 3 column
with data type int?
a) int beta[4][3]={{0,1,2},{1,2,3},{2,3,4},{3,4,5}};
b) int beta[4][3]={0,1,2; 1,2,3; 2,3,4; 3,4,5};
c) int beta[4][3]={0,1,2: 1,2,3: 2,3,4: 3,4,5};
d) int beta[4][3]={{0,1,2};{1,2,3};{2,3,4};{3,4,5}};
10. Display the value of the following array to the screen using loop.
int number[9]={5,9,1,2,8,3,7,6,4};

11. Write an array declaration of score as an integer array with 8 elements.

12. Write an array declaration of StudentPointer as an double array with 3 rows and 4 columns.

13. Based on the syntax below, change the value of last element to 10.
int state[2][3]={1,2,3,4,5,6};
14. Write the syntax to declare an array.

15. Write the c++ statement to..


i. Declare an array price of 10 elements of type int.
ii. Set the value of fifth element of array price to 25.
iii. Access the value of tenth element of array price.
iv. Declare an array price consist 5 rows and 4 column with data type of double.

16. Based on fragment code below, write the value for each statement.
int num[3][4]={{2,4,6,8},{3,6,9,12},{1,5,10,13}};
i. cout<<num[2][3];
ii. cout<<num[0][2];
17. Complete the table below.
int X [25];
float Y[15];
char Z[30];

Element Array Index


1 Y
26 X
Y Y[7]
Z Z[20]
18. Write a complete program to store 5 integers in an array. Display the integers in reverse order
using for loop.

19. Write a complete program to takes 6 price of products from the user, store it in an array and
calculate the average of the price.

20. Write a program that fulfill the requirement given below.


Declare an array named MARK1 that can store 5 integer value. By using loop
(for/while/do…while) ask user to key in all 5 value for the array MARK1. Calculate the average
value for ALL 5 value keyed-in by user. Store the average value calculated in a double variable
named AVG. Display the average value stored in AVG variable at the end of the program.
21. Write a program that fulfill the requirement given below.

Declare a double two dimensional array that will holds marks for 5
students for 3 quizzes. Ask the user to keyin marks for all 5 students for
their quiz 1, quiz 2 and quiz 3. Calculate the average marks for all 3
quizzes took by each of the student. Store the calculated average mark
in the array that you had declared above. Display ALL the marks and
average marks in a table form as below.

You might also like