1、用C+解决问题第十版Chapter 7TRUE/FALSE1.The indexed variables (members) of an array must be integers.ANSWER: FALSE2.The locations of the various indexed variables in an array can be spread out all over the memory.ANSWER: FALSE3.The following array declaration is legaldouble scores=0.1,0.2,0.3;ANSWER: true4.A
2、rrays can be passed to functions.ANSWER: TRUE5.Arrays can be returned from a function.ANSWER: FALSE6.If a function is expecting a pass by reference parameter, you can pass an index variable from an array of the same base type to that function.ANSWER: TRUE7.When you have a function that expects an ar
3、ray, it should also expect the size of the array or the number of indexed variables with valid data.ANSWER: TRUE8.The following function declaration guarantees the values in the array argument are not changed.void function1(int array, int numElements);ANSWER: FALSE9.The following function will work
4、with any size integer array.void function1(int array, int numElements);ANSWER: TRUE10.If you use the const modifier in a function declaration, you do not include it in the function definition.ANSWER: FALSEShort Answer1.Write the code to declare a two dimension array of integers with 10 rows and 20 c
5、olumns.ANSWER: int array1020;2.Write the code to declare an array of 10 doubles named list;ANSWER: double list10;3.The modifier that guarantees that an array argument will not be changed is called _.ANSWER: const4.How many indexed variables does the following array have?int myArray=1,2,3,6,5,4,7,1,2
6、;ANSWER: 95.How many indexed variables does the following array have?int myArray12=1,2,3,6,5,4,7,1,2;ANSWER: 126.Write the declaration for a function named funct1 that expects an array of floats, the number of elements in the array and does not return any value.ANSWER: void funct1(float myArray, int
7、 numElements);7.If you put a value in the square brackets of a one-dimension array parameter, this value is _ by the compiler.ANSWER: ignored8.If your index used to access the indexed variables of the array has the value of a non-existent index, this is called _ANSWER: Index out of range, Index out
8、of bounds, or illegal.9.The computer remembers the address of which indexed variable(s) in an array? _ANSWER: the first10.A computers memory consists of numbered locations called _.ANSWER: bytes11.In the expression double score10;double is called the _ of the arrayANSWER: base type12.In the expressi
9、on cout scorei endl;i is called theANSWER: index or subscript13.An _ is used to process a collection of data all of which is the same type ANSWER: array14.The individual variables that comprise an array are called _ANSWER: indexed variables, subscripted variables, or elements.15.Indexes are numbered
10、 starting at _ANSWER: 0Multiple Choice1.What are the valid indexes for the array shown below?int myArray25;a.0-25b.0-24c.1-25d.1-24ANSWER: B2.What is wrong with the following code?float scores10, total;a.Cannot declare regular and array variables together.b.Arrays must be integersc.The 10 should be
11、replaced with a variable name, whose value is input from the userd.Nothing.ANSWER: D3.Given an array named scores with 25 elements, what is the correct way to access the 25th element?a.scores+25b.scores24c.scores25d.scoreslastANSWER: B4.Why should you use a named constant for the size of an array?a.
12、Readability of codeb.Makes changes to the program easierc.Helps reduce logic errorsd.All of the aboveANSWER: D5.Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located?a.It adds 3 to the base address of the arrayb.It adds space for 3 integers to the
13、 base address of the arrayc.It remembers where all the indexed variables of the array are located.d.None of the aboveANSWER: B6.What is wrong with the following code fragment?const int SIZE =5;float scoresSIZE;for(int i=0; i=SIZE;i+) cout scoresi;a.Array indexes start at 1 not 0b.Arrays must be inte
14、gersc.Array indexes must be less than the size of the arrayd.Should be cin scores0;ANSWER: C7.Which of the following declare an array of 5 characters, and initializes them to some known values?a.char array5=a,b,c,d,e;b.char array4=a,b,c,d,e;c.char array5=;d.char array=a,b,d,e;e.A and Cf.B and Dg.all
15、 of the aboveANSWER: E8.If you declare and initialize an integer array of size 10, but only list 5 values, what values are stored in the remaining 5 indexed variables?a.0b.garbagec.0.0d.0ANSWER: A9.Arrays are always passed to a function usinga.pass by valueb.pass by referencec.pass by arrayd.you can
16、not pass arrays to a functionANSWER: C10.Give the following declarations, which of the following is a legal call to this function?int myFunction(int myValue);int myArray1000;a.cout myFunction(myArray);b.cout myFunction(myArray0);c.myArray = myFunction(myArray);d.myArray1 = myFunction(myArray0);e.A a
17、nd Bf.A and Cg.B and DANSWER: G11.Which of the following function declarations correctly expect an array as the first argument?a.void f1(int array, int size);b.void f1(int& array, int size);c.void f1(int array100, int size);d.void f1(float array, int size);e.All of the abovef.C and Dg.A and BANSWER:
18、 F12.Which of the following function declarations correctly guarantee that the function will not change any values in the array argument?a.void f1(int array, int size) const;b.void f1(int array, int size);c.void f1(int &array, int size);d.void f1(const int array, int size);e.void f1(int array, const
19、 int size);ANSWER: D13.The following function definition has an error in it. What line is this error on?0. void f1(const double array, int size)1. 2. int i=0;3. while(i size)4. 5. arrayi += 2;6. cout arrayi;7. i+;8. 9. a.0b.2c.5d.6e.2ANSWER: C14.Which of the following function declarations could be
20、used to input data from the keyboard into the array? a.void input(int array, int &numElements, int MAX_SIZE);b.void input(int array, int numElements, int MAX_SIZE);c.void input(int &array, int numElements, int MAX_SIZE);d.int array input(int array, int &numElements, int MAX_SIZE);ANSWER: A15.If we w
21、ant a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate?a.void search(const int array, int target, int numElements);b.void search(const int array, int target);c.int searc
22、h(const int array, int numElements);d.int search(const int array, int target, int numElements);ANSWER: D16.Given the following function definition for a search function, and the following variable declarations, which of the following are appropriate function invocations?const int SIZE=1000;int searc
23、h(const int array, int target, int numElements);int arraySIZE, target, numberOfElements;a.search(array0, target, numberOfElements);b.result=search(array0, target, numberOfElements);c.result=search(array, target, numberOfElements);d.result=search(array, target, SIZE);ANSWER: C17.Given the following f
24、unction definition, will repeated calls to the search function for the same target find all occurrences of that target in the array?int search(const int array, int target, int numElements) int index=0; bool found=false; while(!found) & (index numElements) if(arrayindex = target) found=true; else ind
25、ex+; if(found=true) return index; else return -1;a.Yesb.No c.Impossible to tell without looking at the values of the arrayd.It depends on the value of target.ANSWER: B18.Given the following function definition, what modifications need to be made to the search function so that it finds all occurrence
26、s of target in the array?int search(const int array, int target, int numElements) int index=0; bool found=false; while(!found) & (index size;int arraysize;c.int array=0,0,0;d.const int size=9;int arraysize;e.All of the abovef.All but Cg.All but BANSWER: G21.Which of the following function declaratio
27、ns will accept the following two-dimension array?int pages1030;a.void f1(int pages, int size);b.void f1(int pages30, int size);c.void f1(int pages10, int size);d.void f1(int& pages, int size);ANSWER: B22.If you need a function that will handle multi-dimensional arrays, you must specify the following
28、 sizes inside the square brackets.a.All the sizesb.All sizes except the last dimensionc.All sizes except the first dimensiond.None of the sizesANSWER: C23.What is the output of the following code fragment? int array44, index1, index2; for(index1=0;index14;index1+) for(index2=0;index24;index2+) arrayindex1index2=index1 + index2; for(index1=0;index14;index1+) for(inde
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1