Unlock access to all the studying documents.
View Full Document
Copyright Cengage Learning. Powered by Cognero.
1. All components of an array are of the same data type.
2. The array index can be any integer less than the array size.
3. The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0.
4. Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content
of the twelfth component of the array list.
Copyright Cengage Learning. Powered by Cognero.
9. The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.
10. In a two-dimensional array, the elements are arranged in a table form.
11. Which of the following statements declares alpha to be an array of 25 components of the type int?
12. Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for
Copyright Cengage Learning. Powered by Cognero.
the index of the array nameList?
13. Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta?
14. Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid
for the index of the array salesData?
15. Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the
array sales?
for (int 1 = 1; j <= 49; j++)
sales[j] = 0;
for (int j = 1; j <= 50; j++)
sales[j] = 0;
for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
for (int j = 0; j <= 50; j++)
sales[j] = 0.0;
Copyright Cengage Learning. Powered by Cognero.
16. Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the
elements of list?
for (int j = 1; j < 10; j++)
cout << list[j] << ” “;
cout << endl;
for (int j = 0; j <= 9; j++)
cout << list[j] << ” “;
cout << endl;
for (int j = 1; j < 11; j++)
cout << list[j] << ” “;
cout << endl;
for (int j = 1; j <= 10; j++)
cout << list[j] << ” “;
cout << endl;
17. What is the output of the following C++ code?
int list[5] = {0, 5, 10, 15, 20};
int j;
for (j = 0; j < 5; j++)
cout << list[j] << ” “;
cout << endl;
Copyright Cengage Learning. Powered by Cognero.
int alpha[] = (3, 5, 7, 9, 11);
23. In C++, the null character is represented as ____.
24. Which of the following correctly declares name to be a character array and stores “William” in it?
char name[6] = “William”;
char name[7] = “William”;
char name[8] = “William”;
char name[8] = ‘William’;
25. Consider the following declaration: char str[15];. Which of the following statements stores “Blue Sky” into
str?
Copyright Cengage Learning. Powered by Cognero.
32. Given the following declaration:
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fifth row of sale?
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[5][j];
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[5][j];
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[4][j];
33. Given the following declaration:
Copyright Cengage Learning. Powered by Cognero.
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fourth column of sale?
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[j][3];
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[j][4];
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][4];
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];
34. In row order form, the ____.
first row is stored first
first column is stored first
first column is stored last
35. A collection of a fixed number of elements (called components) arranged in n dimensions (n >= 1) is called a(n) ____.
Copyright Cengage Learning. Powered by Cognero.