Arrays
Lab 9.1 Declaring and Manipulating Data into Arrays
Question |
Answer |
1. How many components are contained in the following array declarations? double values [14]; |
a. 14 b. 15 |
2. Write a for loop that sums the numbers in an array with 5 components. |
int sum = 0 for( int i=0; i<5; i++) sum+=array[i]; |
3. An array _________________. |
a. is a simple data type b. is a structured data type |
4. Simple data types are building blocks for arrays. |
yes |
5. An array index starts at 1. |
no |
6. In C++, array is a reserved word. |
no |
7. The following code allows the size of an array to be determined at execution: int n; cout << “Enter the size of the array: “; cin >> n; int array[n]; |
yes |
Lab 9.2 Checking Index Bounds and Initializing Arrays
Question |
Answer |
1. How many components are contained in the following array declarations? double values [14]; |
a. 14 b. 15 |
int array [10]; array [10] = 5; |
No, Array[9]=5; |
int array[5] = { 1, 2, 3}; What are the values of each array component? |
{1,2,3,0,0} |
4. The following code initializes each component to 0: int array[3]; array[3] = {0}; |
No |
5. The following code initializes each component to 0: int array[3] = {0}; |
yes |
6. The following code correctly initializes each component to 0: int array[3]; for (int count = 0; count <= 3; count++) array[count] = 0; |
It does initializes each component too but because the array maximum index is 2 |
7. The following code initializes each component to 0: int array[3]; for (int count = 1; count <= 3; count++) array[count] = 0; |
No, _IndexOutOf BoundException |
Lab 9.3 Passing Arrays as Parameters to Functions
Question |
Answer |
1. Given the prototype: void function(int array[5]); The formal parameter is an array of 5 elements. |
T |
|
F |
3. Given the declaration: int array[5]; and the prototype: void function(int []); Which code calls a function with array as the argument? |
a. function (array); b. function (array[]); c. function (array[5]); |
4. Which prototype for a function reads in an integer array and returns the array to the calling function? |
a. int function(); b. int[] function(); c. void function(int array[]); d. void function(int &array[]); |
Our motto is deliver assignment on Time. Our Expert writers deliver quality assignments to the students.
Get reliable and unique assignments by using our 100% plagiarism-free.
Get connected 24*7 with our Live Chat support executives to receive instant solutions for your assignment.
Get Help with all the subjects like: Programming, Accounting, Finance, Engineering, Law and Marketing.
Get premium service at a pocket-friendly rate at AssignmentHippo
I was struggling so hard to complete my marketing assignment on brand development when I decided to finally reach to the experts of this portal. They certainly deliver perfect consistency and the desired format. The content prepared by the experts of this platform was simply amazing. I definitely owe my grades to them.
Get instant assignment help