Information Technology

May 22, 2009

Assignment for FINALS

1. Which of the following statements of C++ arrays is true?

a. Array components cannot be of floating point types
b. The index type of an array can be any data type.
c. An array component can be treated the same as a simple variable of its component type.
d. a and b above
e. a, b, and c above


2. Given the declaration float alpha[75];the valid range of index values for alpha is:

a. 0 through 75
b. 0 through 74
c. 1 through 75
d. 1 through 74
e. 1 through 76


3. What is the output of the following program fragment?int gamma[3] = {5, 10, 15};int i;for (i = 0; i < 3; i++) cout <a. 5 10 15b. 5 10c. 0 1 2d. 0 1e. It cannot be answered from the information given.

4. What is the output of the following program fragment?int gamma[3] = {5, 10, 15};int i;for (i = 0; i <= 3; i++) cout <5. Which of the following could be used to declare an array alpha and initialize its components to 10, 20, and 30?
a. int alpha[3] = {10, 20, 30};b. int alpha[] = {10, 20, 30};c. int alpha[3] = {10 20 30};d. a and b abovee. a, b, and c above

6. Given the declarations
int status[10]; int i;which of the following loops corrects zeros out the status array?

a. for (i =0; i <= 10; i++) status[i] = 0;
b. for (i =0; i <10; i++) status[i] = 0;
c. for (i =1; i <= 10; i++) status[i] = 0;
d. for (i =1; i <10; i++) status[i] = 0;
e. for (i =1; i <= 11; i++) status[i] = 0;
7. After execution of the code fragmentint arr[5];int i;for (i = 0; i <5;>=3) arr[i-1] = arr[i] + 3;}what is contained in arr[i]?
a. 2b. 3c. 7d. 8e. none of the above
8. After execution of the code fragmentint arr[5];int i;for (i = 0; i <5;>=3) arr[i-1] = arr[i] + 3;}what is contained in arr[3]?
a. 5b. 3c. 8d. 9e. none of the above

9. What is the loop invariant for the following loop?for (i = 0; i < 20; i++) cout << arr[i] << endl;
a. //Invariant (prior to test): // arr[0..19] have been printed && 0 <= i <= 19
b. //Invariant (prior to test): // arr[0..i] have been printed && 0 <= i <= 19
c. //Invariant (prior to test): // arr[0..i] have been printed && 0 <= i <= 20d. //Invariant (prior to test): // arr[0..i - 1] have been printed && 0 <= i <= 19e. //Invariant (prior to test): // arr[0..i - 1] have been printed && 0 <= i <= 20

10. Given a 5000-element array beta, which of the code fragments below could be used to print out the values of beta [0], beta [2], beta [4], and so forth? (All variables are of type int.)
a. for (i = 0; i <5000; i = i + 2) cout <b. for (i = 0; i <2500; i++) cout <c. for (i = 0; i <2500; i = i++) cout <

11. What is the output of the following program fragment?int alpha[5] = {100, 200, 300, 400, 500};int i;for (i = 4; i > 0; i--)
cout<
a. 400 300 200 100
b. 500 400 300 200 100
c. 500 400 300 200d. 4 3 2 1e. It cannot be answered from the information given.

12. What is the output of the following program fragment?int alpha[5] = {100, 200, 300, 400, 500};int i;for (i = 4; i >= 0; i--)
cout<
a. 400 300 200 100 0
b. 500 400 300 200 100
c. 500 400 300 200d. 4 3 2 1 0e. It cannot be answered from the information given.


13. Which of the following cannot be used to input values into a 3-element int array named alpha?

a. cin>>alpha[0]>>alpha[1]>>alpha[2];
b. cin >> alpha;
c. for (i =0; i <>> alpha[i];
d. cin >> alpha[0]; cin >> alpha[1]; cin >> alpha[2];


14. You are writing a program to count the frequencies of characters that are read from a data file. (The computer uses the ASCII character set, which defines 128 different characters.) Which of the following array declarations is appropriate, given that input characters will be used to index into the freqCount array?

a. int freqCount[128];
b. int freqCount[char];
c. char freqCount[128];
d. char freqCount[int];
e. none of the above

15. Given the declarationconst int NUM_STUDENTS = 300;enum Colors {RED, BLACK, BROWN, BLOND, GRAY};which set of declarations below creates two parallel arrays, one that holds integer ID numbers and one that holds student hair colors?

a. int studentID[NUM_STUDENTS]; int hairColor[Colors];b. int studentID[NUM_STUDENTS]; int hairColor[NUM_STUDENTS];c. int studentID[NUM_STUDENTS]; Colors hairColor[NUM_STUDENTS];d. int studentID[Colors]; int hairColor[Colors];

No comments: