Suppose that a program wants to use both a bag of doubles and a bag of Strings. Which version of the Bag could you use? A. You can use the array version of the non-template Bag B. You can use the linked list version of the non-template Bag C. You can use the array version of the template Bag D. Two of the above answers are right E. Answers A, B, and C are all right Why is it a bad idea to have a size_t parameter for a template function? A. Because size_t values cannot be negative B. Because it would require stdlib.h to be separately compiled C. Because the compiler can tell the size of something without having a size_t parameter D. Because most compilers would not permit the actual argument to be 42 (an int) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B. To hide the name of the function from the linker (preventing duplicate symbols) C. To implement container classes D. To permit the use of the debugger without the -gstabs flag Consider this prototype for a template function: template void foo(Item x); Which is the right way to call the foo function with an integer argument i: A. foo( i ); B. foo( i ); C. foo( i ); D. foo( i ); E. foo( i ); Here is a function declaration (assume that BLANK is a blank character): void exam(int n) { if (n > 1) exam(n-1); cout << n << BLANK; } What is the output produced by the function call exam(3)? A. 1 2 3 B. 2 3 C. 3 2 1 D. 3 2 Consider this function declaration: void quiz(int i) { if (i > 0) { quiz(i / 2); quiz(i / 2); } cout << "*"; } How many asterisks are printed by the function call quiz(5)? A. 3 B. 4 C. 7 D. 8 E. Some other number Suppose that a flood fill starts at the point marked with an o in this diagram: XXXXXXXXXX XX XXXX This is row number 1 XX XX XXXX This is row number 2 XX o XXX This is row number 3 XXXXXXXXXX Suppose that the first recursive call is always left; the second recursive call is always right; the third recursive call is always up; the fourth recursive call is always down. How will the rows be completely filled? A. Row 1 is filled first, then row 2, then row 3 B. Row 1 is filled first, then row 3, then row 2 C. Row 2 is filled first, then row 3, then row 1 D. Row 3 is filled first, then row 1, then row 2 E. Row 3 is filled first, then row 2, then row 1 In a real computer, what will happen if you make a recursive call without making the problem smaller? A. The operating system detects the infinite recursion because of the "repeated state" B. The program keeps running until you press Ctrl-C C. The results are nondeterministic D. The run-time stack overflows, halting the program When the compiler compiles your program, how is a recursive call treated differently than a non-recursive function call? A. Parameters are all treated as reference arguments B. Parameters are all treated as value arguments C. There is no duplication of local variables D. None of the above How many of the trees in the margin are complete binary trees? A. None B. Two C. Three D. All How many of the trees in the margin are full binary trees? A. None B. Two C. Three D. All What is the maximum number of leaves for a binary tree with 15 nodes? A. Less than 8 B. 8 C. 9 D. 10 E. More than 10 Consider a complete binary tree with 1000 nodes, with the data stored in the elements a[0]..a[999] of an array. Where are the parent and the left child of the node stored at a[100]? A. Parent at 49, left child at 200 B. Parent at 49, left child at 201 C. Parent at 50, left child at 200 D. Parent at 50, left child at 201 E. None of the above Here is the code from the debugger session in last week's lab: int main() { int a = 10; int b = 30; /********************************************************* * This program is part of assignment 9 for csci 2270. * * blah blah blah * DO NOT DISCUSS YOUR ANSWERS WITH OTHERS UNTIL THURS. * ********************************************************** / b += a; // Add a to b ********/ b += a; // Add a to b again **/ b++; // Increment b *******/ if (b > 30000); b++; // Increment b again */ return 0; } What is the final value of b? A. 41 B. 42 C. 51 D. 52 E. None of the above Write code to declare a bag of ints and a bag of doubles. Use the insert function to put the number 42 in one of the bags, and the number 3.14 in the other. Write a recursive function that has one parameter which is a size_t value called x. The function prints x asterisks, followed by x exclamation points. Do not use any loops or local variables. Write a declaration of a struct that could be used to store the data from a node in a tree, where each node can have up to 1000 children. Write the complete declaration in an exact form that will compile correctly. Do not omit any part of the declaration. Complete the body of this function. Check the precondition as much as possible. void swap_children(double data[], size_t n, size_t p) // Precondition: data is a partially-filled array containing the data from // the nodes of a complete binary tree with n nodes. The number p is the // index of a node that has both a left and a right child in the tree. // Postcondition: The value of the left child of node p has been swapped // with the value of the right child of node p.