CSE 143 Quiz 3: July 16th, 1998
Time limit: 20 minutes
Closed book, closed notes

Name:

Section:
 
 

Question 1:
Please circle true or false.
 
1. True False   An operator is just like a regular function (or method), except that it has a funny name.
2. True False   Because we used an array (with a fixed upper bound) in our implementation of the list ADT, the list abstraction represents a fixed-sized collection.
3. True False   C++'s built-in array does not come with built-in bounds-checking or searching routines.  It is therefore not a collection.
4. True False   The IntList class could easliy be adapted to maintain a list of objects of any type.
5. True False   A C++ struct is a fixed-size, direct access collection.
6. True False   Although stacks are of theoretical interest in computer science, they rarely get used to write actual programs.
7. True False   A collection is called homogenous when it contains multiple copies of the exact same item.
Question 2:
Consider the following program:

#include <iostream.h>

void printIt( double dvalue ) {
    cout << dvalue << endl;
}
void printIt( int ivalue ) {
    cout << ivalue << endl;
}

int main( void ) {
    printIt( 15 );
    printIt( 16.01 );
    return 0;
}
 
 
 

  • What is the output of this program?

  •  15
    16.01

     

  • Name the C++ feature we've discussed that allows you to have multiple functions of the same name in a program.

  •  
     
    Overloading
     
     
     
    Question 3:
    Recall the three main operations on Stacks: push, which puts a new item on the top of the stack; pop, which returns the item at the top of the stack while removing it; and top, which returns the item at the top of the stack without modifying the stack in any way.
     Write a function swap, which assumes that a stack (of integers) contains at least two elements, and swaps the top two elements of the stack.  In other words, if a given IntStack stack contains [....... A B] then swap( stack ) will cause stack to contain [....... B A].
      #include "stack.h"

      void swap( IntStack& stack )
      {
          int a = stack.pop();
          int b = stack.pop();
         
          stack.push( a );
          stack.push( b );

       }
       
       

    Question 4:
    Suppose that we have an instance of an IntList called list.  At some point in time, list looks like this:

    Draw the list after the following code is executed:

        list.deleteItem();
        list.deleteItem();
        list.insertBefore( 15 );
        list.advance();
        list.insertAfter( 0 );
        list.start();

    Be sure to indicate the head and tail of the list, as well as the cursor.

    Bonus:
    What does STL stand for?

        The Standard Template Library