The first 6 questions are multiple-choice. Circle the response that best answers each question. (5 points each)
void quiz( )
{
bag::size_type i;// Line 1
bag b; // Line 2
b.insert(42); // Line 3
i = b.size( ); // Line 4
cout << i; // Line 5
}
When is the bag b's dynamic array allocated?
void funky(________ head_ptr);
// Precondition: head_ptr is a head pointer for a linked list.
// Postcondition: The function funky has done some manipulation of
// the linked list, and the list might now have a new head node.
What is the best data type for head_ptr in this function?
node
node&
node*
node*&
void remove(node*& head_ptr, const node::value_type& target); //PRE: head_ptr is the head pointer of a non-empty linked list. The // list contains at least one occurrence of target. //POST: the node containing target that is closest to the head of the // linked list has been removedFill in the following outline to produce a full implementation of the remove() function.
void remove(node*& head_ptr, const node::value_type& target){
// Declare two local pointers, p and previous
// Initialize p to point to the head of the list; initialize previous to NULL
// Move p down the list until it points to the first node containing target.
// Each time you move p down the list, move previous down the list as well
// so that it always points to the node previous to p
// If previous equals NULL, make head_ptr point to the node
// that comes after p.
// Otherwise, make the node previous to p point to the node that comes after p
// Delete the node pointed to by p
}
private: value_type *data; size_type used; size_type capacity;Suppose there is no copy constructor defined for this class. Draw a picture and provide a short explanation of what can go wrong if a bag object is passed as a value parameter to a function.
class foo
{
public:
foo();
void one() const;
foo two(int i);
friend foo f(foo x);
private:
int size;
};
A client program declares two foo objects named a and b. A statement is ``legal'' if it compiles without error. Answer each of the following questions YES or NO.
a = b;legal in the client program?
a.one();legal in the client program?
a = two(10);legal in the client program?
a.size = b.size;legal in the client program?
x.size = 0;legal in the function f?
size = 0;legal in the function one?